AVCaptureVideoDataOutput

AVCaptureVideoDataOutput

我正在用iOS开发一个应用程序。我需要从摄像机捕获视频,并且需要将该视频记录到文件中并获取未压缩的帧,这就是为什么我需要同时使用AVCaptureOutput ...

我在苹果的文档中读到了“您可以配置多个输入和输出,并由一个 session 协调:”因此,我认为它必须可行,但是我遇到了问题。

我将两者都设置为 session :

self.fileOutput.maxRecordedDuration =  CMTimeMake(5000,1 );;
self.fileOutput.minFreeDiskSpaceLimit = 3000;


if([self.captureSession canAddOutput:self.fileOutput]){
    [self.captureSession addOutput:self.fileOutput];
    NSLog(@"Added File Video Output");
}else{
    NSLog(@"Couldn't add video output");
}

if ([self.captureSession canAddOutput:videoOutput]){
    [self.captureSession addOutput:videoOutput];
    NSLog(@"Added Data Video Output");
}else{
    NSLog(@"Couldn't add video output");
}

我都收到“肯定”确认消息。之后,我打电话给:
NSString *assetPath         = [self createAssetFilePath:@"mov"];
NSURL *outputURL            = [[NSURL alloc] initFileURLWithPath:assetPath];
[self.fileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
[self.captureSession startRunning];

然后我有我的委托函数:
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error {

NSLog(@"Output File URL: %@ ", outputFileURL);

BOOL recordedSuccessfully = YES;

    if ([error code] != noErr) {

        NSLog(@"Error: %@", error);
        id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
        NSLog(@"Error: %@", value);
        if (value) {
            recordedSuccessfully = [value boolValue];
        }

    }
}

而且我没有收到任何错误,但是在添加“AVCaptureMovieFileOutput”之前,“AVCaptureVideoDataOutput”可以正常工作了,现在还没有...

所以...可以同时做这两个吗?任何想法?!

谢谢!

最佳答案

该问题的答案:Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput指示您不能同时将AVCaptureVideoDataOutput和AVCaptureMovieFileOutput发送到 session 。不幸的是,我无法在Apple文档中对此进行验证。我的经验是,在将AVCaptureMovieFileOutput添加到 session 的输出之后,我不再接收到发送到AVCaptureVideoDataOutput的sampleBufferDelegate的消息,这似乎备份了该断言。

10-06 02:25