连续调用startRecordingToOutputFileURL:

苹果文件似乎表明,在录制video到一个文件,应用程序可以更改没有问题的url。 但是我看到一个问题。 当我尝试这个时,logging委托被调用一个错误…

手术无法完成。 (OSStatus错误-12780。)信息字典是:{AVErrorRecordingSuccessfullyFinishedKey = 0; }

(在“不能”的时髦单引号来自日志logging[错误localizedDescription])

这里的代码,基本上是WWDC10 AVCam示例的调整:

1)开始录制。 启动计时器每隔几秒更改输出URL

- (void) startRecording { // start the chunk timer self.chunkTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(chunkTimerFired:) userInfo:nil repeats:YES]; AVCaptureConnection *videoConnection = [AVCamCaptureManager connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]]; if ([videoConnection isVideoOrientationSupported]) { [videoConnection setVideoOrientation:[self orientation]]; } if ([[UIDevice currentDevice] isMultitaskingSupported]) { [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]]; } NSURL *fileUrl = [[ChunkManager sharedInstance] nextURL]; NSLog(@"now recording to %@", [fileUrl absoluteString]); [[self movieFileOutput] startRecordingToOutputFileURL:fileUrl recordingDelegate:self]; } 

2)定时器启动时,更改输出文件名称而不停止录制

 - (void)chunkTimerFired:(NSTimer *)aTimer { if ([[UIDevice currentDevice] isMultitaskingSupported]) { [self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]]; } NSURL *nextUrl = [self nextURL]; NSLog(@"changing capture output to %@", [[nextUrl absoluteString] lastPathComponent]); [[self movieFileOutput] startRecordingToOutputFileURL:nextUrl recordingDelegate:self]; } 

注意:[self nextURL]生成file-0.mov,file-5.mov,file-10.mov等文件url。

3)每次文件更改时都会调用它,而每次调用都是错误的。

 - (void) captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error { id delegate = [self delegate]; if (error && [delegate respondsToSelector:@selector(someOtherError:)]) { NSLog(@"got an error, tell delegate"); [delegate someOtherError:error]; } if ([self backgroundRecordingID]) { if ([[UIDevice currentDevice] isMultitaskingSupported]) { [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]]; } [self setBackgroundRecordingID:0]; } if ([delegate respondsToSelector:@selector(recordingFinished)]) { [delegate recordingFinished]; } } 

运行时,file-0被写入,然后我们在将url更改为file-5之后看到错误-12780,file-10被写入,然后出现错误,然后等等。

看起来,即时更改url不起作用,但会停止允许下一个URL更改工作的书写。

任何帮助将非常感激。

感谢所有,对此的审查和好的想法。 这里是来自苹果DTS的单词…

我和AV基金会的工程师进行了交stream,这个方法并没有做文档所说的那样(“在另一个录制过程中调用这个方法之前不需要调用stopRecording”)。 请使用Apple Bug Reporter( http://developer.apple.com/bugreporter/ )提交错误报告,以便团队进行调查。 确保在报告中包含您最小的项目。

我已经向苹果提交这个错误11632087

在这个文档中,它是这样写的:

If a file at the given URL already exists when capturing starts, recording to the new file will fail.

你确定你检查nextUrl是不存在的文件名吗?

根据文档,不支持连续调用2个startRecordingToOutputFileURL。

你可以在这里阅读

在iOS中,不支持此帧准确的文件切换。 您必须在再次调用此方法之前调用stopRecording以避免任何错误。