gpt4 book ai didi

objective-c - QTCaptureOutput.delegate captureOutput :didOutputVideoFrame:. ..从未调用过

转载 作者:行者123 更新时间:2023-12-03 17:59:09 25 4
gpt4 key购买 nike

来源

所以,我这样设置了一个QTCaptureSession:

    //Setup Camera
cameraSession = [[QTCaptureSession alloc] init];
QTCaptureDevice *camera = [QTCaptureDevice deviceWithUniqueID: cameraID];

BOOL success = [camera open: &error];
if (!success || error)
{
NSLog(@"Could not open device %@.", cameraID);
NSLog(@"Error: %@", [error localizedDescription]);
return nil;
}

//Setup Input Session
QTCaptureDeviceInput *cameraInput = [[QTCaptureDeviceInput alloc] initWithDevice: camera];

success = [cameraSession addInput: cameraInput error: &error];
if (!success || error)
{
NSLog(@"Could not initialize input session.");
NSLog(@"Error: %@", [error localizedDescription]);
return nil;
}

//Setup Output
QTCaptureDecompressedVideoOutput *cameraOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
[cameraOutput setDelegate: self];

success = [cameraSession addOutput: cameraOutput error: &error];
if (!success || error)
{
NSLog(@"Could not initialize output session.");
NSLog(@"Error: %@", [error localizedDescription]);
return nil;
}

QTCaptureDecompressedVideoOutput 委托(delegate)的 captureOutput:didOutputVideoFrame:WithSampleBuffer:fromConnection: 因此:

- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
NSLog(@"starting convert\n");
}

然后我使用以下方法开始捕获处理:

    [cameraSession startRunning];

所有变量都初始化良好, session 启动良好,但 captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection: 永远不会被调用。

上下文

这是一个命令行应用程序,使用 GCC 编译。它与以下框架相关联:

  • 基金会
  • cocoa
  • QTKit
  • QuartzCore

相关杂项

帧不太可能丢失,因为 captureOutput:didDropVideoFrameWithSampleBuffer:fromConnection: 也没有被调用。

最佳答案

因此,在 Mike Ash 的帮助下,我设法发现我的程序立即终止,而不是等待委托(delegate)回调(根据 Apple 的 QTKit 文档,这可能发生在单独的线程)。

我的解决方案是向名为 captureIsFinished 的对象添加一个 BOOL 属性,然后将其添加到 main() 函数中:

    //Wait Until Capture is Finished
while (![snap captureIsFinished])
{
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
}

这有效地使应用程序的运行循环持续 1 秒钟,检查捕获是否完成,然后再运行一秒钟。

关于objective-c - QTCaptureOutput.delegate captureOutput :didOutputVideoFrame:. ..从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9101222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com