【问题标题】:Consecutive calls to startRecordingToOutputFileURL:连续调用 startRecordingToOutputFileURL:
【发布时间】: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 切换根本不起作用......) .他们说虽然可以通过使用AVCaptureVideoDataOutputAVAssetWriter 类来实现,但解决方案非常核心,因为您必须协调音频/视频。
  • 在您链接到该问题的文档中,总是明确提到在 Mac OS X 之间不会丢弃任何媒体样本。
  • DTS 在经过很长时间的延迟后于昨天回复,承认这是一个错误。我已附上详细信息作为答案。

标签: iphone ios avfoundation avcam


【解决方案1】:

感谢大家对此的评论和好的想法。这是来自 Apple DTS 的话...

我与我们的 AV Foundation 工程师交谈过,这绝对是一个错误 因为这种方法没有按照文档所说的那样做 ("在调用该方法之前不需要调用stopRecording 而另一个录制正在进行中。”)。请提交错误报告 使用 Apple Bug Reporter (http://developer.apple.com/bugreporter/) 所以团队可以进行调查。确保并包括您的最低要求 报告中的项目。

我已将此作为错误 11632087 向 Apple 提交

【讨论】:

  • 天哪。我很高兴有人真正确认了这个错误。我可能已经尝试了超过 5 种不同的方法(黑客)来完成这项工作(即使使用双会话/文件输出来回处理视频输入 - 根本没有办法在不丢失 1-3 秒的情况下拥有多个文件他们之间的视频)。我终于可以休息了:P
  • 好像看不到别人提交的bug。 2012 年 11 月 1 日的 xcode 更新解决了这个问题吗?
  • 刚刚检查了错误报告。仍然开放。
  • 好的,谢谢,您是在等待回复还是找到了解决办法?
  • 我有一个不好的解决方法:等到录制完成,然后分割文件。它很慢。它可以异步完成,因此应用程序可以保持响应,但对于我的应用程序,在文件准备好之前用户无需执行太多操作。
【解决方案2】:

在文档中是这样说的:

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

您确定检查nextUrl 是一个不存在的文件名吗?

【讨论】:

  • 感谢您的想法:我在开始之前删除(并确认)了 tmp 目录中的文件。
【解决方案3】:

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

你可以阅读它here

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    相关资源
    最近更新 更多