<!--
{
  "documentType" : "article",
  "framework" : "VideoToolbox",
  "identifier" : "/documentation/VideoToolbox/VTCompressionSession-api-collection",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "VTCompressionSession"
}
-->

# VTCompressionSession

An object that compresses video data.

## Discussion

A compression session supports the compression of a sequence of video frames. Here’s the workflow:

1. Create a compression session using [`VTCompressionSessionCreate(allocator:width:height:codecType:encoderSpecification:imageBufferAttributes:compressedDataAllocator:outputCallback:refcon:compressionSessionOut:)`](/documentation/VideoToolbox/VTCompressionSessionCreate(allocator:width:height:codecType:encoderSpecification:imageBufferAttributes:compressedDataAllocator:outputCallback:refcon:compressionSessionOut:)).
2. Optionally, configure the session with your desired [Compression Properties](/documentation/VideoToolbox/compression-properties) by calling [`VTSessionSetProperty(_:key:value:)`](/documentation/VideoToolbox/VTSessionSetProperty(_:key:value:)) or [`VTSessionSetProperties(_:propertyDictionary:)`](/documentation/VideoToolbox/VTSessionSetProperties(_:propertyDictionary:)).
3. Encode video frames using [`VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:sourceFrameRefcon:infoFlagsOut:)`](/documentation/VideoToolbox/VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:sourceFrameRefcon:infoFlagsOut:)) and receive the compressed video frames in the session’s [`VTCompressionOutputCallback`](/documentation/VideoToolbox/VTCompressionOutputCallback).
4. To force the completion of some or all pending frames, call [`VTCompressionSessionCompleteFrames(_:untilPresentationTimeStamp:)`](/documentation/VideoToolbox/VTCompressionSessionCompleteFrames(_:untilPresentationTimeStamp:)).
5. When you finish with the compression session, call [`VTCompressionSessionInvalidate(_:)`](/documentation/VideoToolbox/VTCompressionSessionInvalidate(_:)) to invalidate it and <doc://com.apple.documentation/documentation/CoreFoundation/CFRelease> to free its memory.

## Topics

### Creating a Session

[`func VTCompressionSessionCreate(allocator: CFAllocator?, width: Int32, height: Int32, codecType: CMVideoCodecType, encoderSpecification: CFDictionary?, imageBufferAttributes: CFDictionary?, compressedDataAllocator: CFAllocator?, outputCallback: VTCompressionOutputCallback?, refcon: UnsafeMutableRawPointer?, compressionSessionOut: UnsafeMutablePointer<VTCompressionSession?>) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionCreate(allocator:width:height:codecType:encoderSpecification:imageBufferAttributes:compressedDataAllocator:outputCallback:refcon:compressionSessionOut:))

Creates an object that compresses video frames.

### Configuring a Session

[Compression Properties](/documentation/VideoToolbox/compression-properties)

Properties that you use to configure a compression session.

### Encoding Frames

[`func VTCompressionSessionGetPixelBufferPool(VTCompressionSession) -> CVPixelBufferPool?`](/documentation/VideoToolbox/VTCompressionSessionGetPixelBufferPool(_:))

Returns a pool that provides ideal source pixel buffers for a compression session.

[`func VTCompressionSessionPrepareToEncodeFrames(VTCompressionSession) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionPrepareToEncodeFrames(_:))

Enables the encoder to perform any necessary resource allocation before the encoder begins encoding frames (optional).

[`func VTCompressionSessionEncodeFrame(VTCompressionSession, imageBuffer: CVImageBuffer, presentationTimeStamp: CMTime, duration: CMTime, frameProperties: CFDictionary?, sourceFrameRefcon: UnsafeMutableRawPointer?, infoFlagsOut: UnsafeMutablePointer<VTEncodeInfoFlags>?) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:sourceFrameRefcon:infoFlagsOut:))

Presents frames to the compression session.

[`func VTCompressionSessionEncodeFrame(VTCompressionSession, imageBuffer: CVImageBuffer, presentationTimeStamp: CMTime, duration: CMTime, frameProperties: CFDictionary?, infoFlagsOut: UnsafeMutablePointer<VTEncodeInfoFlags>?, outputHandler: VTCompressionOutputHandler) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionEncodeFrame(_:imageBuffer:presentationTimeStamp:duration:frameProperties:infoFlagsOut:outputHandler:))

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

[`func VTCompressionSessionCompleteFrames(VTCompressionSession, untilPresentationTimeStamp: CMTime) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionCompleteFrames(_:untilPresentationTimeStamp:))

Forces the compression session to complete the encoding of frames.

### Encoding Multi-Image Frames

[`func VTIsStereoMVHEVCEncodeSupported() -> Bool`](/documentation/VideoToolbox/VTIsStereoMVHEVCEncodeSupported())

Returns a Boolean value that indicates whether the system supports MV-HEVC encoding.

[`func VTCompressionSessionEncodeMultiImageFrame(VTCompressionSession, taggedBuffers: [CMTaggedBuffer], presentationTimeStamp: CMTime, duration: CMTime, frameProperties: CFDictionary?, infoFlagsOut: UnsafeMutablePointer<VTEncodeInfoFlags>?, outputHandler: VTCompressionOutputHandler) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionEncodeMultiImageFrame(_:taggedBuffers:presentationTimeStamp:duration:frameProperties:infoFlagsOut:outputHandler:))

Passes a multi-image frame to a compression session for encoding and provides a callback to handle the output.

[`extern OSStatus VTCompressionSessionEncodeMultiImageFrame(VTCompressionSessionRef session, CMTaggedBufferGroupRef taggedBufferGroup, CMTime presentationTimeStamp, CMTime duration, CFDictionaryRef frameProperties, void *sourceFrameRefcon, VTEncodeInfoFlags *infoFlagsOut);`](/documentation/VideoToolbox/VTCompressionSessionEncodeMultiImageFrame)

Passes a multi-image frame to a compression session for encoding.

[`extern OSStatus VTCompressionSessionEncodeMultiImageFrameWithOutputHandler(VTCompressionSessionRef session, CMTaggedBufferGroupRef taggedBufferGroup, CMTime presentationTimeStamp, CMTime duration, CFDictionaryRef frameProperties, VTEncodeInfoFlags *infoFlagsOut, VTCompressionOutputHandler outputHandler);`](/documentation/VideoToolbox/VTCompressionSessionEncodeMultiImageFrameWithOutputHandler)

Passes a multi-image frame to a compression session for encoding and provides a callback to handle the output.

### Performing Multiple Passes

[`func VTCompressionSessionBeginPass(VTCompressionSession, flags: VTCompressionSessionOptionFlags, UnsafeMutablePointer<UInt32>?) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionBeginPass(_:flags:_:))

Marks the start of a specific compression pass.

[`func VTCompressionSessionEndPass(VTCompressionSession, furtherPassesRequestedOut: UnsafeMutablePointer<DarwinBoolean>?, UnsafeMutablePointer<UInt32>?) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionEndPass(_:furtherPassesRequestedOut:_:))

Marks the end of a compression pass.

[`func VTCompressionSessionGetTimeRangesForNextPass(VTCompressionSession, timeRangeCountOut: UnsafeMutablePointer<CMItemCount>, timeRangeArrayOut: UnsafeMutablePointer<UnsafePointer<CMTimeRange>?>) -> OSStatus`](/documentation/VideoToolbox/VTCompressionSessionGetTimeRangesForNextPass(_:timeRangeCountOut:timeRangeArrayOut:))

Retrieves the time ranges for the next pass.

### Invalidating a Session

[`func VTCompressionSessionInvalidate(VTCompressionSession)`](/documentation/VideoToolbox/VTCompressionSessionInvalidate(_:))

Tears down a compression session.

### Accessing the Type Identifier

[`func VTCompressionSessionGetTypeID() -> CFTypeID`](/documentation/VideoToolbox/VTCompressionSessionGetTypeID())

Retrieves the Core Foundation type identifier for the compression session.

### Data Types

[`class VTCompressionSession`](/documentation/VideoToolbox/VTCompressionSession)

A reference to a VideoToolbox compression session.

[`struct VTEncodeInfoFlags`](/documentation/VideoToolbox/VTEncodeInfoFlags)

Flags that indicate encoder state.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)