2012-03-30 34 views
7

AVAssetExportSessionを使用して3つのビデオをマージ(追加)しようとしていますが、このエラーが発生しています。それは働いた1つまたは2つのビデオのために奇妙に。iOS 5:3つのビデオとAVAssetExportSessionのマージエラー

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にバグがありますか?

答えて

5

私はこの問題を発見しました。実際にはAVPlayerLayerを使用して各ビデオを同時にプレビューモードで表示するため、問題が発生しました。この質問AVPlayerItem fails with AVStatusFailed and error code "Cannot Decode"を参照すると、最大4つの同時AVPlayerが動作することについての文書化されていない制限があります。そして、この瞬間に4つのAVPlayerインスタンスがある場合、この制限によってAVAssetExportSessionが動作しなくなることがあります。

解決策は、エクスポートする前にAVPlayerを解放するか、またはAVPlayerを完全に使用しないことです。

+0

また、変更可能なコンポジションのコピーを使用してエクスポータを初期化することもできます – Edwin

+0

目的cのXcode 8.2.1でAVPlayerを解放する方法は? – sohil