title: Extracting an image from H.264 sample data (Objective-C / Mac OS X)
body: <p>Given a sample buffer of H.264, is there a way to extract the frame it represents as an image?</p>
  
  <p>I'm using QTKit to capture video from a camera and using a <code>QTCaptureMovieFileOutput</code> as the output object.</p>
  
  <p>I want something similar to the <code>CVImageBufferRef</code> that is passed as a parameter to the <code>QTCaptureVideoPreviewOutput</code> delegate method. For some reason, the file output doesn't contain the <code>CVImageBufferRef</code>.</p>
  
  <p>What I do get is a QTSampleBuffer which, since I've set it in the compression options, contains an H.264 sample.</p>
  
  <p>I have seen that on the iPhone, CoreMedia and AVFoundation can be used to create a <code>CVImageBufferRef</code> from the given <code>CMSampleBufferRef</code> (Which, I imagine is as close to the <code>QTSampleBuffer</code> as I'll be able to get) - but this is the Mac, not the iPhone.</p>
  
  <p>Neither CoreMedia or AVFoundation are on the Mac, and I can't see any way to accomplish the same task.</p>
  
  <p>What I need is an image (whether it be a CVImageBufferRef, CIImage or NSImage doesn't matter) from the current frame of the H.264 sample that is given to me by the Output object's call back.</p>
  
  <hr>
  
  <p><em>Extended info (from the comments below)</em></p>
  
  <p>I have posted a related question that focusses on the original issue - attempting to simply play a stream of video samples using QTKit: <a href="https://stackoverflow.com/questions/3854505/playing-a-stream-of-video-data-using-qtkit-on-mac-os-x">Playing a stream of video data using QTKit on Mac OS X</a></p>
  
  <p>It appears not to be possible which is why I've moved onto trying to obtain frames as images and creating an appearance of video, by scaling, compressing and converting the image data from <code>CVImageBufferRef</code> to <code>NSImage</code> and sending it to a peer over the network.</p>
  
  <p>I can use the <code>QTCapturePreviewVideoOutput</code> (or decompressed) to get uncompressed frame images in the form of <code>CVImageBufferRef</code>. </p>
  
  <p>However, these images references need compressing, scaling and converting into <code>NSImage</code>s before they're any use to me, hence the attempt to get an already scaled and compressed frame from the framework using the <code>QTCaptureMovieFileOutput</code> (which allows a compression and image size to be set before starting the capture), saving me from having to do the expensive compression, scale and conversion operations, which kill CPU.</p>