7

我正在实施一个软件来捕捉来自网络摄像头的视频。我在 Apple Dev 中看到了 MyRecorder 示例,它运行良好。

我尝试使用以下代码添加一个按钮以从视频中拍摄快照:

- (IBAction)addFrame:(id)sender
{
    CVImageBufferRef imageBuffer;
    @synchronized (self) {
        imageBuffer = CVBufferRetain(mCurrentImageBuffer);
    }
    if (imageBuffer) { 
    [ bla bla bla ]     
    }
}

但 mCurrentImageBuffer 始终为空。如何从我的网络摄像头获取当前帧并放入 mCurrentImageBuffer?

我试过用

(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);  
} 

但它从未被调用。如何决定何时调用 captureOutput 委托方法?任何的想法?

谢谢,安德里亚

4

2 回答 2

3

我试过用

- (void)captureOutput:(QTCaptureOutput *)captureOutput 
                                didOutputVideoFrame:(CVImageBufferRef)videoFrame 
                                withSampleBuffer:(QTSampleBuffer *)sampleBuffer 
                                fromConnection:(QTCaptureConnection *)connection

但它从未被调用。

实现此方法的对象是捕获输出对象的委托吗?

于 2009-10-03T20:41:12.267 回答
3

看起来您正在尝试使用 QTKit Capture API 从您的网络摄像头捕获视频。MyRecorder 示例应用程序几乎是您可以使用此 API 制作的功能最简单的视频捕获程序。从您的描述中不清楚,但您需要确保遵循他们的示例,并以与-awakeFromNibMyRecorderController 中的方法相同的方式初始化视频会话。如果不这样做,您将不会捕获任何视频。

就您尝试使用-captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:的方法而言,是QTCaptureDecompressedVideoOutput. MyRecorder 示例中不存在此类的实例,因为该示例仅将压缩视频记录到磁盘。要使用它,您需要创建一个实例QTCaptureDecompressedVideoOutput,将其附加到您的QTCaptureSessionusing-addOutput:error:中,并将该实例的委托设置为QTCaptureDecompressedVideoOutput您的类。

有关 QTKit 如何处理此类事情的更多信息,您可以查阅QTKit Application Programming Guide的QTKit Capture部分。

于 2009-10-04T05:20:49.767 回答