Extracting an image from H.264 sample data (Objective-C / Mac OS X)
Given a sample buffer of H.264, is there a way to extract the frame it represents as an image?
I'm using QTKit to capture video from a camera and using a QTCaptureMovieFileOutput
as the output object.
I want something similar to the CVImageBufferRef
that is passed as a parameter to the QTCaptureVideoPreviewOutput
delegate method. For some reason, the file output doesn't contain the CVImageBufferRef
.
What I do get is a QTSampleBuffer which, since I've set it in the compression options, contains an H.264 sample.
I have seen that on the iPhone, CoreMedia and AVFoundation can be used to create a CVImageBufferRef
from the given CMSampleBufferRef
(Which, I imagine is as close to the QTSampleBuffer
as I'll be able to get) - but this is the Mac, not the iPhone.
Neither CoreMedia or AVFoundation are on the Mac, and I can't see any way to accomplish the same task.
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.
Extended info (from the comments below)
I have posted a related question that focusses on the original issue - attempting to simply play a stream of video samples using QTKit: Playing a stream of video data using QTKit on Mac OS X
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 CVImageBufferRe开发者_如何学Pythonf
to NSImage
and sending it to a peer over the network.
I can use the QTCapturePreviewVideoOutput
(or decompressed) to get uncompressed frame images in the form of CVImageBufferRef
.
However, these images references need compressing, scaling and converting into NSImage
s before they're any use to me, hence the attempt to get an already scaled and compressed frame from the framework using the QTCaptureMovieFileOutput
(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.
Does the Creating a Single-Frame Grabbing Application section of the QTKit Application Programming Guide not work for you in this instance?
精彩评论