gpt4 book ai didi

iOS 5 : Error merging 3 videos with AVAssetExportSession

转载 作者:可可西里 更新时间:2023-11-01 03:31:56 25 4
gpt4 key购买 nike

我正在尝试使用 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 : Error merging 3 videos with AVAssetExportSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9942488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com