代码之家  ›  专栏  ›  技术社区  ›  Andrea Girardi

从摄像头捕获可可帧

  •  7
  • Andrea Girardi  · 技术社区  · 15 年前

    我正在实施一个软件来从网络摄像机捕获视频。我在AppleDev中看到过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委托方法? 有什么想法吗?

    谢谢, 安德莉亚

    2 回复  |  直到 12 年前
        1
  •  3
  •   Brad Larson    15 年前

    您似乎正在尝试使用qtkit捕获API从网络摄像机捕获视频。MyRecorder示例应用程序几乎是使用此API可以制作的功能最简单的视频捕获程序。从您的描述中不清楚,但您需要确保遵循它们的示例,并以与在中相同的方式初始化视频会话。 -awakeFromNib MyRecorderController中的方法。如果你不这样做,就不会有任何视频被捕获。

    至于你想用的方法, -captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection: 是的委托方法 QTCaptureDecompressedVideoOutput .MyRecorder示例中不存在此类的实例,因为该示例只将压缩的视频记录到磁盘。要使用它,您需要创建 qtcapture解压缩视频输出 ,将其附加到 QTCaptureSession 使用 -addOutput:error: ,并为 qtcapture解压缩视频输出 实例将成为您的类。

    有关qtkit如何处理此类事情的更多信息,请参阅 QTKit Capture 的节 QTKit Application Programming Guide .

        2
  •  3
  •   Peter Hosey    15 年前

    我试过用

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

    但从来没打过电话。

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