AVAssetWriterInputPixelBufferAdaptor Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AVFoundation.framework
Availability
Available in iOS 4.1 and later.
Declared in
AVAssetWriterInput.h

Overview

You use an AVAssetWriterInputPixelBufferAdaptor to append video samples packaged as CVPixelBuffer objects to a single AVAssetWriterInput object.

Instances of AVAssetWriterInputPixelBufferAdaptor provide a CVPixelBufferPool that you can use to allocate pixel buffers for writing to the output file. Using the provided pixel buffer pool for buffer allocation is typically more efficient than appending pixel buffers allocated using a separate pool.

Tasks

Creating an Adaptor

Adding a Pixel Buffer

Inspecting a Pixel Buffer Adaptor

Properties

assetWriterInput

The asset writer input to which the adaptor should append pixel buffers. (read-only)

@property(nonatomic, readonly) AVAssetWriterInput *assetWriterInput
Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h

pixelBufferPool

A pixel buffer pool that will vend and efficiently recycle CVPixelBuffer objects that can be appended to the receiver. (read-only)

@property(nonatomic, readonly) CVPixelBufferPoolRef pixelBufferPool
Discussion

For maximum efficiency, you should create CVPixelBuffer objects for appendPixelBuffer:withPresentationTime: by using this pool with the CVPixelBufferPoolCreatePixelBuffer function.

This property is NULL before the first call to startSessionAtTime:on the associated AVAssetWriter object.

This property is key value observable.

Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h

sourcePixelBufferAttributes

The pixel buffer attributes of pixel buffers that will be vended by the adaptor’s CVPixelBufferPool. (read-only)

@property(nonatomic, readonly) NSDictionary *sourcePixelBufferAttributes
Discussion

The value of this property is a dictionary containing pixel buffer attributes keys defined in <CoreVideo/CVPixelBuffer.h>.

Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h

Class Methods

assetWriterInputPixelBufferAdaptorWithAssetWriterInput:sourcePixelBufferAttributes:

Returns a new pixel buffer adaptor to receive pixel buffers for writing to the output file.

+ (AVAssetWriterInputPixelBufferAdaptor *)assetWriterInputPixelBufferAdaptorWithAssetWriterInput:(AVAssetWriterInput *)input sourcePixelBufferAttributes:(NSDictionary *)sourcePixelBufferAttributes
Parameters
input

The asset writer input to which the receiver should append pixel buffers.

Currently, only asset writer inputs that accept media data of type AVMediaTypeVideo can be used to initialize a pixel buffer adaptor.

It is an error to pass a sample buffer input that is already attached to another instance of AVAssetWriterInputPixelBufferAdaptor.

sourcePixelBufferAttributes

The attributes of pixel buffers that will be vended by the input's CVPixelBufferPool.

Pixel buffer attributes keys for the pixel buffer pool are defined in <CoreVideo/CVPixelBuffer.h>. To take advantage of the improved efficiency of appending buffers created from the adaptor’s pixel buffer pool, you should specify pixel buffer attributes that most closely accommodate the source format of the video frames being appended.

Pass nil if you do not need a pixel buffer pool for allocating buffers.

Return Value

A new pixel buffer adaptor to receive pixel buffers for writing to the output file.

Discussion

To specify the pixel format type, the pixelBufferAttributes dictionary should contain a value for kCVPixelBufferPixelFormatTypeKey. For example, use [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] for 8-bit-per-channel BGRA, or use [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] for 2-plane YCbCr.

Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h

Instance Methods

appendPixelBuffer:withPresentationTime:

Appends a pixel buffer to the receiver.

- (BOOL)appendPixelBuffer:(CVPixelBufferRef)pixelBuffer withPresentationTime:(CMTime)presentationTime
Parameters
pixelBuffer

The CVPixelBuffer to be appended.

presentationTime

The presentation time for the pixel buffer to be appended. This time will be considered relative to the time passed to -[AVAssetWriter startSessionAtSourceTime:] to determine the timing of the frame in the output file.

Return Value

YES if the pixel buffer was successfully appended, otherwise NO.

Discussion

If the operation is unsuccessful, writing the asset has failed. You must not call finishWriting.

Special Considerations

Do not modify a CVPixelBuffer or its contents after you have passed it to this method.

Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h

initWithAssetWriterInput:sourcePixelBufferAttributes:

Initializes a new pixel buffer adaptor to receive pixel buffers for writing to the output file.

- (id)initWithAssetWriterInput:(AVAssetWriterInput *)input sourcePixelBufferAttributes:(NSDictionary *)sourcePixelBufferAttributes
Parameters
input

The asset writer input to which the receiver should append pixel buffers.

Currently, only asset writer inputs that accept media data of type AVMediaTypeVideo can be used to initialize a pixel buffer adaptor.

It is an error to pass a sample buffer input that is already attached to another instance of AVAssetWriterInputPixelBufferAdaptor.

sourcePixelBufferAttributes

The attributes of pixel buffers that will be vended by the input's CVPixelBufferPool.

Pixel buffer attributes keys for the pixel buffer pool are defined in <CoreVideo/CVPixelBuffer.h>. To take advantage of the improved efficiency of appending buffers created from the adaptor’s pixel buffer pool, you should specify pixel buffer attributes that most closely accommodate the source format of the video frames being appended.

Pass nil if you do not need a pixel buffer pool for allocating buffers.

Return Value

A pixel buffer adaptor initialized to receive pixel buffers for writing to the output file.

Discussion

To specify the pixel format type, the pixelBufferAttributes dictionary should contain a value for kCVPixelBufferPixelFormatTypeKey. For example, use [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] for 8-bit-per-channel BGRA, or use [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] for 2-plane YCbCr.

Availability
  • Available in iOS 4.1 and later.
Declared In
AVAssetWriterInput.h