我可以在同一会话中拥有AVCaptureVideoDataOutput和AVCaptureMovieFileOutput吗?

时间:2012-12-19 13:45:25

标签: objective-c ios avfoundation

我正在iOS中开发一款应用。我需要从摄像头捕获视频,我需要将该视频记录到文件中并获得未压缩的帧,这就是我需要同时使用AVCaptureOutput ...

的原因。

我在苹果的文档中读到了这一点“你可以配置多个输入和输出,由一个会话协调:”所以我认为它必须是可行的,但我遇到了问题......

我正在设置两个会话:

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];
        }

    }
}

我没有收到任何错误,但是“AVCaptureVideoDataOutput”在添加“AVCaptureMovieFileOutput”之前正在工作,现在它不是......

那么......这两种可能吗?!有什么想法吗?!

谢谢!

1 个答案:

答案 0 :(得分:4)

这个问题的答案:Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput表示您不能同时为会话提供AVCaptureVideoDataOutput和AVCaptureMovieFileOutput。遗憾的是,我无法在Apple文档中验证这一点。我的经验是,在我将AVCaptureMovieFileOutput添加到会话的输出后,我不再接收到AVCaptureVideoDataOutput的sampleBufferDelegate的消息,这似乎支持了该断言。