【发布时间】:2012-06-02 00:11:46
【问题描述】:
The Apple docs 似乎表明在将视频录制到文件时,该应用可以随时更改 URL 没有问题。但我看到了一个问题。当我尝试这个时,录制委托被调用并出现错误......
操作无法完成。 (OSStatus 错误 -12780。)信息 字典是:{ AVErrorRecordingSuccessfullyFinishedKey = 0; }
(“couldn't”中的时髦单引号来自日志记录 [错误本地化描述])
这是代码,基本上是对 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] 生成文件 url,如 file-0.mov、file-5.mov、file-10.mov 等。
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 更改起作用。
【问题讨论】:
-
@danh 您是否需要帧精确的解决方案,或者如果您在视频之间丢失一些帧对您来说没问题?
-
@Alladinian - 没有损失,但如果有一个稍微有损的想法让我在这里脱身,我将非常感激。我已经尝试调用 stopRecording 并在委托方法中启动下一段。这行得通,但是帧丢失太大了……以秒为单位。
-
@danh 好吧,(由 Apple 工程师)证实,
AVCaptureFileOutput不可能进行帧精确切换(尽管他们避免解释为什么记录在案的 url 切换根本不起作用......) .他们说虽然可以通过使用AVCaptureVideoDataOutput和AVAssetWriter类来实现,但解决方案非常核心,因为您必须协调音频/视频。 -
在您链接到该问题的文档中,总是明确提到在 Mac OS X 之间不会丢弃任何媒体样本。
-
DTS 在经过很长时间的延迟后于昨天回复,承认这是一个错误。我已附上详细信息作为答案。
标签: iphone ios avfoundation avcam