2012-10-12 10 views
7

Birden videolar ve birden fazla şarkı birleştirme ediyorum ve ben bot aynı kod Bazı yaptım şu yanıtı AVAssetExportSessionStatus = 4,error = Error Domain=AVFoundationErrorDomain Code=-11841 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11841.)" alıyorum kesinlikle iyi dün ama bugün koşuyordu çünkü kodunda sorunun ne alıyorum araştırma ve geçersiz video kompozisyonu nedeniyle ihracat başarısız oluyor bulundu.Lütfen video kompozisyonunda neyin yanlış olduğunu öğrenin.AVErrorInvalidVideoComposition = -11.841

- (void)mergeAllselectedVideos 
{ 
    NSArray *pathArray = [DocumentDirectory getUrlFromDocumentDirectoryOfList:self.selectedClipsArray]; 
    AVMutableComposition *mixComposition = [[AVMutableComposition alloc]init]; 
    NSMutableArray *layerinstructions = [[NSMutableArray alloc]init]; 
    CMTime time = kCMTimeZero; 
    CMTime previousSongDuration = kCMTimeZero; 
    for (int i = 0 ; i < pathArray.count; i++) 
    { 
     //VIDEO TRACK// 
     time = CMTimeAdd(time, previousSongDuration); 
     NSURL *url = [NSURL URLWithString:[pathArray objectAtIndex:i]]; 
     AVAsset *avAsset = [AVAsset assetWithURL:url]; 
     AVMutableCompositionTrack *track = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 
     [track insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration) ofTrack:[[avAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:time error:nil]; 
    previousSongDuration = avAsset.duration; 
    } 
    CMTime audioTime = kCMTimeZero; 
    for (int i = 0; i < self.selectedSongsArray.count; i++) 
    { 
     MPMediaItem * songItem = [self.selectedSongsArray objectAtIndex:i]; 
     NSURL *songURL = [songItem valueForProperty: MPMediaItemPropertyAssetURL]; 
     AVAsset *audioAsset = [AVAsset assetWithURL:songURL]; 
     AVMutableCompositionTrack *AudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
     CMTimeRange timeRange = CMTimeRangeMake(audioTime, audioAsset.duration); 
     if(CMTimeGetSeconds(CMTimeAdd(audioTime, audioAsset.duration)) > CMTimeGetSeconds(time)) 
     { 
      timeRange = CMTimeRangeMake(audioTime, CMTimeSubtract(time,audioTime)); 
     } 
     [AudioTrack insertTimeRange:timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil]; 
     audioTime = CMTimeAdd(audioTime, audioAsset.duration); 
    } 

    AVMutableVideoCompositionInstruction * MainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 
    MainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, time); 
    MainInstruction.layerInstructions = layerinstructions; 

    AVMutableVideoComposition *MainCompositionInst = [AVMutableVideoComposition videoComposition]; 
    MainCompositionInst.instructions = [NSArray arrayWithObject:MainInstruction]; 
    MainCompositionInst.frameDuration = CMTimeMake(1, 30); 
    MainCompositionInst.renderSize = CGSizeMake(320.0, 480.0); 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    movieName = [CoreDataFunctions getNameForMovieForDate:[CalendarFunctions getCurrentDateString]]; 
    self.moviePlayButton.titleLabel.text = movieName; 
    NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:movieName]; 

    NSURL *url = [NSURL fileURLWithPath:myPathDocs]; 

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; 
    exporter.outputURL=url; 
    exporter.outputFileType = AVFileTypeQuickTimeMovie; 
    exporter.videoComposition = MainCompositionInst; 
    exporter.shouldOptimizeForNetworkUse = YES; 
    [exporter exportAsynchronouslyWithCompletionHandler:^{dispatch_async(dispatch_get_main_queue(), ^{[self exportDidFinish:exporter];});}]; 
} 
- (void)exportDidFinish:(AVAssetExportSession*)session 
{ 
    //Printing error 
    NSLog(@"AVAssetExportSessionStatus = %i,error = %@",session.status,session.error); 
} 

cevap

6

Sorunu aynı sorunla karşılaşırken buldum. Bu konudaki teorim, video kompozisyonu için tüm özelliklerin dışa aktarma zamanında ayarlanmadığıdır. Benim durumumda

AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition]; 
videoComposition.frameDuration = CMTimeMake(1,30); 
videoComposition.renderScale = 1.0; 
videoComposition.renderSize = CGSizeMake(352.0, 288.0); 
instruction.layerInstructions = [NSArray arrayWithObject: layerInstruction]; 
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, videoAsset.duration); 
videoComposition.instructions = [NSArray arrayWithObject: instruction]; 

, ben talimat üzerine timerange özelliği eksikti: İşte şimdi hatasız ihracat sonuçlandığını ben şimdi kullanıyorum dörtlük var. Doğru değerleri aldıklarından emin olmak için kendi mülklerinizi kontrol edin. İyi şanslar! Bu şey zor.

+0

Aaron, bir video oluşturmak için mümkün değil varlık ile aynı sorunu var. Yukarıda belirttiğiniz her şeyi belirledim. Bunun hakkında düşünebildiğim tek şey, video girişimin başka bir oturumdan çıktı olmasıdır. Bunun nasıl önemli olabileceği hakkında bir fikrin var mı? –

+0

Bu sorun benim için ya da: ( –

-1

Sen, ilk LayerInstruction için opacity ayarlamak ör .: ihtiyaç

[FirstlayerInstruction setOpacity:0.0 atTime:firstAsset.duration];