18

Appleのドキュメントによると、ビデオをファイルに録画している間、アプリは問題なくその場でURLを変更できるとのことです。しかし、私は問題を見ています。これを試してみると、レコーディングデリゲートがエラーで呼び出されます...

操作を完了できませんでした。(OSStatusエラー-12780。)情報ディクショナリは次のとおりです。{AVErrorRecordingSuccessfullyFinishedKey = 0; }

(「できませんでした」のファンキーな一重引用符は、ロギング[errorlocalizedDescription]から来ています)

これが基本的にWWDC10AVCamサンプルの微調整であるコードです。

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が書き込まれ、次にエラーが発生し、次にOKというように続きます。

その場でURLを変更しても機能しないようですが、書き込みが停止し、次のURL変更が機能するようになります。

4

3 に答える 3

8

これについてのレビューと良い考えをありがとう。これがAppleDTSからの言葉です...

AV Foundationのエンジニアと話をしましたが、このメソッドがドキュメントに記載されているとおりに機能しないというのは間違いなくバグです(「別のレコーディングの進行中に、このメソッドを呼び出す前にstopRecordingを呼び出す必要はありません」)。チームが調査できるように、Apple Bug Reporter(http://developer.apple.com/bugreporter/ )を使用してバグレポートを提出してください。最小限のプロジェクトを必ずレポートに含めてください。

私はこれをバグ11632087としてAppleに提出しました

于 2012-06-09T15:26:34.103 に答える
1

ドキュメントでは、次のように述べられています。

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

nextUrlそれが存在しないファイル名であることを確認してください。

于 2012-06-04T09:49:13.613 に答える
0

ドキュメントによると、2つの連続したstartRecordingToOutputFileURLの呼び出しはサポートされていません。

あなたはここでそれについて読むことができます

iOSでは、このフレーム精度のファイル切り替えはサポートされていません。エラーを回避するために、このメソッドを再度呼び出す前にstopRecordingを呼び出す必要があります。

于 2013-01-24T14:30:12.930 に答える