Objective c QTCaptureOutput.delegate captureOutput:didOutputVideoFrame:。。。从未打过电话 来源
因此,我设置了一个Objective c QTCaptureOutput.delegate captureOutput:didOutputVideoFrame:。。。从未打过电话 来源,objective-c,cocoa,delegates,callback,qtkit,Objective C,Cocoa,Delegates,Callback,Qtkit,因此,我设置了一个QTCaptureSession: //Setup Camera cameraSession = [[QTCaptureSession alloc] init]; QTCaptureDevice *camera = [QTCaptureDevice deviceWithUniqueID: cameraID]; BOOL success = [camera open: &error]; if (!success || er
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;
}
和QTCaptureDecompressedDVideOutput
代理的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的帮助下,我设法发现我的程序立即终止,没有等待代理回调(根据苹果的QTKit
docs,这可能发生在一个单独的线程上)
我的解决方案是将BOOL
属性添加到名为captureissfinished
的对象中,然后将其添加到main()
函数中:
//Wait Until Capture is Finished
while (![snap captureIsFinished])
{
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
}
它有效地使应用程序的运行循环持续1秒,检查捕获是否完成,然后再运行一秒钟