1

我正在使用这段代码来创建 AVCaptureSession,但是当-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection被调用时,sampleBuffer 大小为 0

- (BOOL)createCaptureSession:(NSError **)outError{
/* Create a capture session. */
self.captureSession = [[AVCaptureSession alloc] init];
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPresetHigh])
{
    /* Specifies capture settings suitable for high quality video and audio output. */
    [self.captureSession setSessionPreset:AVCaptureSessionPresetHigh];
}

/* Add the main display as a capture input. */
display = CGMainDisplayID();
self.captureScreenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:display];
if ([self.captureSession canAddInput:self.captureScreenInput])
{
    [self.captureSession addInput:self.captureScreenInput];
}
else
{   NSLog(@"nevyslo");
    return NO;
}

/* Register for notifications of errors during the capture session so we can display an alert. */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionRuntimeErrorDidOccur:) name:AVCaptureSessionRuntimeErrorNotification object:self.captureSession];


AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[self.captureSession addOutput:output];

dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];

[self.captureSession startRunning];
    return YES;
}

我的方法有什么问题吗?有没有可能这个错误可能在其他地方?我正在使用 ARC。

编辑 缓冲区不是空的,但它立即被释放。通过保留缓冲液解决。谢谢

4

0 回答 0