资源
因此,我这样设置了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
代表的captureOutput:didOutputVideoFrame:WithSampleBuffer:fromConnection:
:- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
NSLog(@"starting convert\n");
}
然后,我使用以下命令开始捕获处理:
[cameraSession startRunning];
所有变量初始化都很好,会话也可以正常启动,但是
captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:
从未被调用。语境
这是一个由GCC编译的命令行应用程序。它与以下框架链接:
基础
可可
QTKit
石英核心
相关杂项
该帧不太可能丢失,因为
captureOutput:didDropVideoFrameWithSampleBuffer:fromConnection:
也没有被调用。 最佳答案
因此,在Mike Ash的帮助下,我设法弄清楚我的程序正在立即终止,而不是在等待委托回调(根据Apple的QTKit
文档,该回调可能发生在单独的线程上)。
我的解决方案是将BOOL
属性添加到名为captureIsFinished
的对象,然后将其添加到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/