I'm implementing a software to caputre video from webcam. I've seen MyRecorder sample in Apple Dev and it works fine.
I've tried to add a button to take a snapshot from video with this code:
- (IBAction)addFrame:(id)sender
{
CVImageBuf开发者_开发技巧ferRef imageBuffer;
@synchronized (self) {
imageBuffer = CVBufferRetain(mCurrentImageBuffer);
}
if (imageBuffer) {
[ bla bla bla ]
}
}
but mCurrentImageBuffer is always empty. How can I take current frame from my webcam and put on mCurrentImageBuffer?
I've tried to use
(void)captureOutput:(QTCaptureOutput *)captureOutput
didOutputVideoFrame:(CVImageBufferRef)videoFrame
withSampleBuffer:(QTSampleBuffer *)sampleBuffer
fromConnection:(QTCaptureConnection *)connection
{
CVImageBufferRef imageBufferToRelease;
CVBufferRetain(videoFrame);
@synchronized (self) {
imageBufferToRelease = mCurrentImageBuffer;
mCurrentImageBuffer = videoFrame;
}
CVBufferRelease(imageBufferToRelease);
}
but it's never called. How can I decide when call captureOutput delegate method? Any idea?
thanks, Andrea
It looks like you're trying to use the QTKit Capture API for capturing video from your webcam. The MyRecorder sample application is pretty much the simplest functioning video capture program you can make using this API. It wasn't clear from your description, but you need to make sure that you follow their example, and initialize your video session in the same manner as they do in the -awakeFromNib
method within MyRecorderController. If you don't, you won't get any video being captured.
As far as the method you're trying to use, -captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:
is a delegate method for QTCaptureDecompressedVideoOutput
. An instance of this class is not present in the MyRecorder sample, because that sample only records compressed video to disk. To use this, you'll need to create an instance of QTCaptureDecompressedVideoOutput
, attach it to your QTCaptureSession
using -addOutput:error:
, and set the delegate for the QTCaptureDecompressedVideoOutput
instance to be your class.
For more information on how QTKit handles this sort of thing, you can consult the QTKit Capture section of the QTKit Application Programming Guide.
I've tried to use
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
but it's never called.
Is the object implementing this method the capture output object's delegate?
精彩评论