我正在开发 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];
}
}
}
而且我没有收到任何错误,但是在添加“AVCaptureMovieFileOutput”之前“AVCaptureVideoDataOutput”正在工作,现在它不是......
那么……这两者都有可能吗?!任何的想法?!
谢谢!