【问题标题】:iOS 5: Error merging 3 videos with AVAssetExportSessioniOS 5:将 3 个视频与 AVAssetExportSession 合并时出错
【发布时间】:2012-03-30 11:58:25
【问题描述】:

我正在尝试使用 AVAssetExportSession 合并(附加)3 个视频,但我不断收到此错误。奇怪的是 1 或 2 个视频有效。

Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x458120 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}

我什至尝试在出现错误的情况下重做该功能,但我得到的只是无限的错误消息。这是我的代码的 sn-p。

AVMutableComposition *mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
NSError * error = nil;
NSMutableArray * timeRanges = [NSMutableArray arrayWithCapacity:arrayMovieUrl.count];
NSMutableArray * tracks = [NSMutableArray arrayWithCapacity:arrayMovieUrl.count];

for (int i=0; i<[arrayMovieUrl count]; i++) {
    AVURLAsset *assetClip = [arrayMovieUrl objectAtIndex:i];
    AVAssetTrack *clipVideoTrackB = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

    [timeRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
    [tracks addObject:clipVideoTrackB];
}
[compositionTrack insertTimeRanges:timeRanges ofTracks:tracks atTime:kCMTimeZero error:&error];

AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPreset1280x720];
NSParameterAssert(exporter != nil);
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.outputURL = outputUrl;
[exporter exportAsynchronouslyWithCompletionHandler:^{
    switch ([exporter status]) {
        case AVAssetExportSessionStatusFailed:
            NSLog(@"Export failed: %@", [exporter error]);
            break;
        case AVAssetExportSessionStatusCancelled:
            NSLog(@"Export canceled");
            break;
        case AVAssetExportSessionStatusCompleted:
            NSLog(@"Export successfully");
            break;
        default:
            break;
    }
    if (exporter.status != AVAssetExportSessionStatusCompleted){
        NSLog(@"Retry export");
        [self renderMovie];
    }
}];

我的代码有问题还是 iOS 5 有一些错误?

【问题讨论】:

    标签: ios ios5 avfoundation avassetexportsession


    【解决方案1】:

    我发现了问题。所以问题实际上是因为我使用 AVPlayerLayer 以预览模式同时显示每个视频。参考这个问题 AVPlayerItem fails with AVStatusFailed and error code "Cannot Decode" ,最多 4 个同时工作的 AVPlayer 存在未记录的限制。当此时有 4 个 AVPlayer 实例时,这个限制在某种程度上阻碍了 AVAssetExportSession 的工作。

    解决方案是在导出前释放 AVPlayer,或者完全不使用 AVPlayer。

    【讨论】:

    • 你也可以使用可变组合的副本来初始化导出器
    • 如何在objective c Xcode 8.2.1中发布AVPlayer?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 2016-06-13
    相关资源
    最近更新 更多