源
所以,我这样设置了一个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 convertn");
}
然后我使用开始捕获处理
[cameraSession startRunning];
所有变量初始化良好,会话启动良好,但从未调用captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:
。
上下文
这是一个命令行应用程序,使用GCC编译。它与以下框架相关联:
- 基础
- 可可
- QTKit
- QuartzCore
相关杂录
帧不太可能下降,因为captureOutput:didDropVideoFrameWithSampleBuffer:fromConnection:
也没有被调用。
因此,在Mike Ash的帮助下,我设法弄清楚我的程序正在立即终止,而不是等待委托回调(根据苹果公司的QTKit
文档,这可能发生在一个单独的线程上)。
我的解决方案是将BOOL
属性添加到名为captureIsFinished
的对象中,然后将其添加到main()
函数中:
//Wait Until Capture is Finished
while (![snap captureIsFinished])
{
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
}
这有效地使应用程序的运行循环持续1秒,检查捕获是否完成,然后再运行一秒钟。