iOS 5:将3个video与AVAssetExportSession合并时出错
我试图合并(附加)使用AVAssetExportSession 3video,但我不断收到此错误。 奇怪的是1或2个video的工作。
Error Domain=AVFoundationErrorDomain Code=-11820 "Cannot Complete Export" UserInfo=0x458120 {NSLocalizedRecoverySuggestion=Try exporting again., NSLocalizedDescription=Cannot Complete Export}
我什至试图重做function的情况下,但我得到的只是无限的错误信息。 这是我的代码片段。
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同时以预览模式显示每个video。 引用此问题AVPlayerItem失败,AVStatusFailed和错误代码“无法解码” ,有最大4 AVPlayer同时工作的无证限制。 当这个时候有4个AVPlayer实例时,这个限制阻碍了AVAssetExportSession的工作。
解决方法是在导出之前释放AVPlayer,或者完全不使用AVPlayer。
- AVVideoCompositionCoreAnimationTool和CALayer在肖像模式?
- 在后台工作的AVAssetExportSession
- AVMutableComposition – video资产之间的空白/黑框
- AVAssetExportSession输出文件
- AVAssetExportSession给我一个输出video的右侧和底部的绿色边框
- AVFoundation导出方向错误
- AVAssetExportSession每次都失败(错误-12780)
- AVAssetExportSession导出失败,带有错误:“操作已停止,NSLocalizedFailureReason =video无法合成。
- 在后台启动AVAssetExportSession