QTKit Capture - Setting DecompressedVideoOutput CVPixelBuffer Attributes

Q: How can I resize the CVImageBuffer's I'm getting passed when using the QTCaptureDecompressedVideoOutput delegate method captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:?

A: You can ask QTCaptureDecompressedVideoOutput to provide you with a CVImageBuffer of a specific size and pixel format using the setPixelBufferAttributes: method passing in an NSDictionary with the appropriate kCVPixelBuffer attributes defined.

Note: CVPixelBuffer attribute keys are defined in CVPixelBuffer.h

If your application required 320x240 ARGB pixel buffers out of QTCaptureDecompressedVideoOutput you could set the attributes as shown in the following example.

Listing 1: Setting QTCaptureDecompressedVideoOutput pixel buffer attributes.

static void SetOutputPixelBufferAttributes(QTCaptureDecompressedVideoOutput *inDecompressedVideoOutput)
{
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithDouble:320.0], (id)kCVPixelBufferWidthKey,
                                [NSNumber numberWithDouble:240.0], (id)kCVPixelBufferHeightKey,
                                // k32ARGBPixelFormat may be used on Mac OS X 10.4.x
                                [NSNumber numberWitUnsignedInt:kCVPixelFormatType_32ARGB],
                                                               (id)kCVPixelBufferPixelFormatTypeKey,
                                nil];

    [inDecompressedVideoOutput setPixelBufferAttributes:attributes];
}

Specifying pixel buffer attributes may cause the connected capture device to automatically be reconfigured to best match the requested output format. Conversions may also be necessary. For example, a pixel format conversion would be required if the capture device does not have an RGB mode yet RGB data has been requested. QTCapture will do all conversions for you and will choose the most optimal video pipeline for the requested output format.

IMPORTANT: Applications making use of the QTCaptureDecompressedVideoOutput object should ensure that any image processing performed on the thread from which captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection: was invoked is as efficient as possible. Since QTCaptureDecompressedVideoOutput maintains maximum frame quality and avoids dropping frames, using this output object and attempting CPU-intensive image processing on this thread may result in reduced performance while capturing.

For optimal performance move any time intensive tasks to another thread if necessary reserving the delegate method thread for queuing up frames for processing and dropping them as required.

Note: While not currently documented, the QTCaptureVideoPreviewOutput class also supports the setPixelBufferAttributes: method.

References:

Back to Top 

Document Revision History

DateNotes
2008-03-06Editorial
2008-01-22Describes how to configure a DecompressedVideoOutput objects CVPixelBuffer attributes.

Posted: 2008-03-06


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.