2012-03-30 8 views
7

Próbuję scalić (dołączyć) 3 filmy przy użyciu AVAssetExportSession, ale nadal otrzymuję ten błąd. Dziwnie dla 1 lub 2 filmów wideo działało.iOS 5: Błąd łączenia 3 filmów z AVAssetExportSession

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

Próbowałem nawet powtórzyć funkcję w przypadku błędu, ale otrzymałem tylko nieskończony komunikat o błędzie. To jest fragment kodu.

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]; 
    } 
}]; 

Czy coś jest nie tak z moim kodem lub iOS 5 ma jakiś błąd?

Odpowiedz

5

Znalazłem problem. Problem polegał na tym, że używam AVPlayerLayer do jednoczesnego wyświetlania każdego wideo w trybie podglądu. Odwołując się do tego pytania AVPlayerItem fails with AVStatusFailed and error code "Cannot Decode", istnieje nieudokumentowany limit maksymalnie 4 jednoczesnych AVPlayer do pracy. Ograniczenie to w jakiś sposób utrudnia działanie AVAssetExportSession, gdy w tym momencie znajduje się 4 instancja AVPlayer.

Rozwiązaniem jest zwolnienie AVPlayer przed eksportem lub całkowite wyłączenie AVPlayer.

+0

można również zainicjować eksportera za pomocą kopii zmieniającej się kompozycji zamiast: – Edwin

+0

Jak zwolnić AVPlayer w celu c Xcode 8.2.1? – sohil