Instance Method


Instructs the receiver to invoke a block repeatedly, at its convenience, to gather media data for writing to the output.


- (void)requestMediaDataWhenReadyOnQueue:(dispatch_queue_t)queue usingBlock:(void (^)(void))block;



The queue on which block should be invoked.


The block the input should invoke to obtain media data.


The block should append media data to the input either until the input’s readyForMoreMediaData property becomes NO or until there is no more media data to supply (at which point it may choose to mark the input as finished using markAsFinished). The block should then exit. After the block exits, if the input has not been marked as finished, once the input has processed the media data it has received and becomes ready for more media data again, it will invoke the block again in order to obtain more.

A typical use of this method, with a block that supplies media data to an input while respecting the input’s readyForMoreMediaData property, might look like this:

[myAVAssetWriterInput requestMediaDataWhenReadyOnQueue:myInputSerialQueue usingBlock:^{
        while ([myAVAssetWriterInput isReadyForMoreMediaData])
            CMSampleBufferRef nextSampleBuffer = [self copyNextSampleBufferToWrite];
            if (nextSampleBuffer)
                [myAVAssetWriterInput appendSampleBuffer:nextSampleBuffer];
                [myAVAssetWriterInput markAsFinished];

You should not use this method with a push-style buffer source, such as AVCaptureAudioDataOutput or AVCaptureVideoDataOutput, because such a combination will typically require intermediate queueing of buffers. Instead, this method is better suited to a pull-style buffer source such as an AVAssetReaderOutput object.

When using a push-style buffer source, it is generally better to immediately append each buffer to the asset writer input, directly as it is received using appendSampleBuffer:. Using this strategy, it is often possible to avoid having to queue up buffers in between the buffer source and the asset writer input. Note that many of these push-style buffer sources also produce buffers in real-time, in which case you should set expectsMediaDataInRealTime to YES.

See Also

Adding Media Samples

- appendSampleBuffer:

Appends samples to the receiver.


A Boolean value that indicates the readiness of the input to accept more media data.

- markAsFinished

Tells the writer it can't append more buffers to this input.