合并video和audio:导出透明/空白video

我正在尝试合并video和audio。 如果我粘贴video在我的主要包,然后video合并罚款。 但是,如果我使用任何录制的video(来自每个播放),那么导出的video没有video就是audio。

我看了我的相关问题,但没有一个和我的问题一样。 任何想法,为什么我得到与video主要捆绑工作正常时,有声音的空白video? 是因为录制的video有一些不同的属性?

任何帮助,将不胜感激。 谢谢。

合并audio(来自AVRecorder的m4aaudio)和video(来自everplay统一的mp4video)代码:

-(void)mergeAndSave//:(NSURL*) video_url { //Create AVMutableComposition Object which will hold our multiple AVMutableCompositionTrack or we can say it will hold our video and audio files. AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init]; //Now first load your audio file using AVURLAsset. Make sure you give the correct path of your videos. //NSURL *audio_url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Asteroid_Sound" ofType:@"mp3"]]; _audioAsset = [AVURLAsset URLAssetWithURL:recorder.url options:nil]; CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, _audioAsset.duration); //Now we are creating the first AVMutableCompositionTrack containing our audio and add it to our AVMutableComposition object. AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[_audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil]; //Now we will load video file. //NSURL *video_url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Asteroid_Video" ofType:@"mp4"]]; _videoAsset = [AVURLAsset URLAssetWithURL:recorderURL options:nil]; NSLog(@"blublu : %@, %f",recorderURL,CMTimeGetSeconds(_videoAsset.duration) ); CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,_audioAsset.duration); //Now we are creating the second AVMutableCompositionTrack containing our video and add it to our AVMutableComposition object. AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; [a_compositionVideoTrack insertTimeRange:video_timeRange ofTrack:[[_videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; //decide the path where you want to store the final video created with audio and video merge. NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsDir = [dirPaths objectAtIndex:0]; NSString *outputFilePath = [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"FinalVideo%@.mov",[NSDate date]]]; NSURL *outputFileUrl = [NSURL fileURLWithPath:outputFilePath]; if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; //Now create an AVAssetExportSession object that will save your final video at specified path. _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; _assetExport.outputFileType = AVFileTypeQuickTimeMovie; _assetExport.outputURL = outputFileUrl; [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"conversion done at path : %@", [NSData dataWithContentsOfFile:outputFilePath]); [[[CustomAlbum alloc]init] saveVideoWithPath:outputFileUrl]; }); } ]; } 

Interesting Posts