---
title: "VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:infoFlagsOut:outputHandler:)"
framework: videotoolbox
role: symbol
role_heading: Function
path: "videotoolbox/vtcompressionsessionencodeframe(_:imagebuffer:presentationtimestamp:duration:frameproperties:infoflagsout:outputhandler:)"
---

# VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:infoFlagsOut:outputHandler:)

Presents frames to the compression session and invokes the output callback when compression is complete.

## Declaration

```swift
func VTCompressionSessionEncodeFrame(_ session: VTCompressionSession, imageBuffer: CVImageBuffer, presentationTimeStamp: CMTime, duration: CMTime, frameProperties: CFDictionary?, infoFlagsOut: UnsafeMutablePointer<VTEncodeInfoFlags>?, outputHandler: @escaping VTCompressionOutputHandler) -> OSStatus
```

## Parameters

- `session`: The compression session.
- `imageBuffer`: A Core Video image buffer (doc://com.apple.documentation/documentation/CoreVideo/CVImageBuffer) containing a video frame to be compressed. The buffer must have a nonzero reference count.
- `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer. Each presentation timestamp passed to a session must be greater than the previous one.
- `duration`: The presentation duration for this frame, to be attached to the sample buffer. If you do not have duration information, pass doc://com.apple.documentation/documentation/CoreMedia/CMTime/invalid.
- `frameProperties`: Key/value pairs specifying additional properties for encoding this frame. Note that some session properties may also be changed between frames. Such changes affect subsequently encoded frames.
- `infoFlagsOut`: A pointer to a VTEncodeInfoFlags to receive information about the encode operation. The doc://com.apple.videotoolbox/documentation/VideoToolbox/VTEncodeInfoFlags/asynchronous bit may be set if the encode is (or was) running asynchronously. The doc://com.apple.videotoolbox/documentation/VideoToolbox/VTEncodeInfoFlags/frameDropped bit may be set if the frame was dropped (synchronously). Pass NULL if you do not want to receive this information.
- `outputHandler`: The block to be called when encoding the frame is completed. This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrameWithOutputHandler.

## Discussion

Discussion Encoded frames may or may not be output before the function returns. The client should not modify the pixel data after making this call. The session and/or encoder retains the image buffer as long as necessary. important: This function cannot be called with a session created with a VTCompressionOutputCallback.

## See Also

### Encoding Frames

- [VTCompressionSessionGetPixelBufferPool(_:)](videotoolbox/vtcompressionsessiongetpixelbufferpool(_:).md)
- [VTCompressionSessionPrepareToEncodeFrames(_:)](videotoolbox/vtcompressionsessionpreparetoencodeframes(_:).md)
- [VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:sourceFrameRefcon:infoFlagsOut:)](videotoolbox/vtcompressionsessionencodeframe(_:imagebuffer:presentationtimestamp:duration:frameproperties:sourceframerefcon:infoflagsout:).md)
- [VTCompressionSessionCompleteFrames(_:untilPresentationTimeStamp:)](videotoolbox/vtcompressionsessioncompleteframes(_:untilpresentationtimestamp:).md)
