HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS 5:使用AVAssetExportSession合并3个视频时出错大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用AVAssetExportSession合并(追加)3个视频,但我一直收到此错误.奇怪的是它有1或2个视频.
Error Domain=AVFoundationErrorDomain Code=-11820 "CAnnot Complete Export" UserInfo=0x458120 {NSLocalizedRecoverySuggestion=Try exporTing again.,NSLocalizedDescription=CAnnot Complete Export}

我甚至尝试重做函数以防出错,但我得到的只是无限错误信息.这是我的代码的片段.

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有一些错误

解决方法

发现了问题.所以问题实际上是因为我使用AVPlayerLayer同时以预览模式显示每个视频.参这个问题 AVPlayerItem fails with AVStatusFailed and error code “Cannot Decode”,有最大4个同步AVPlayer的无证限制.当这个时刻有4个AVPlayer实例时,这个限制会以某种方式阻碍AVAssetExportSession的工作.

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

大佬总结

以上是大佬教程为你收集整理的iOS 5:使用AVAssetExportSession合并3个视频时出错全部内容,希望文章能够帮你解决iOS 5:使用AVAssetExportSession合并3个视频时出错所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。