iphone ios 音频添加,合成,替换到视频(里的音轨)
2012-05-22 15:43
549 查看
如果对av foundation 不熟悉得话,建议先看看wwdc 2010 关于av foundation得讲座。http://blog.csdn.net/linzhiji/article/details/6752722
I have a video file and an audio file. Is it possible to merge it to one video with with sound file. I think AVMutableComposition should help me,
but I still dont understand how. any advices?
I have a video file and an audio file. Is it possible to merge it to one video with with sound file. I think AVMutableComposition should help me,
but I still dont understand how. any advices?
AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioUrl options:nil]; AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoUrl options:nil]; AVMutableComposition* mixComposition = [AVMutableComposition composition]; AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil]; AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil]; AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough]; NSString* videoName = @"export.mov"; NSString *exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName]; NSURL *exportUrl = [NSURL fileURLWithPath:exportPath]; if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) { [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil]; } _assetExport.outputFileType = @"com.apple.quicktime-movie"; DLog(@"file type %@",_assetExport.outputFileType); _assetExport.outputURL = exportUrl; _assetExport.shouldOptimizeForNetworkUse = YES; [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void ) { // your completion code here } } ];
相关文章推荐
- iphone ios 音频添加,合成,替换到视频(里的音轨)
- iphone ios 音频添加,合成,替换到视频(里的音轨)
- iOS开发之音轨合成(音频与音频,音频与视频)
- [IOS]对视频、音频播放器添加缓冲进度条
- ios视频和音频的合成
- ios 视频编辑,添加文字、图片(CA动画)水印,合成视频
- iOS 如何对音频、视频合成,配音、卡拉OK技术
- 【iOS-Cocos2d游戏开发之十四】音频/音效/视频播放(利用Cocos2D-iPhone-Extensions嵌入Cocos2d进行视频播放!)
- ios音频处理 音轨合成 swift
- iOS 视频剪切、旋转,视频添加音频、添加水印,视频导出
- [算法]iOS 视频添加水印,合成视频两种方案(整体渲染和分割渲染)
- iOS视频编辑之添加音轨的方法
- iOS中全局悬浮按钮,类似IPhone中的AssistiveTouch (可以替换为视频悬浮窗口)
- iphone ios 视频特效,视频合成
- 【iOS-Cocos2d游戏开发之十四】音频/音效/视频播放(利用Cocos2D-iPhone-Extensions嵌入Cocos2d进行视频播放!)
- 【iOS-Cocos2d游戏开发之十四】音频/音效/视频播放(利用Cocos2D-iPhone-Extensions嵌入Cocos2d进行视频播放!)
- [IOS]对视频、音频播放器添加缓冲进度条
- iOS 视频剪切、旋转,视频添加音频、添加水印,视频导出
- [IOS]对视频、音频播放器添加缓冲进度条
- 【iOS-Cocos2d游戏开发之十四】音频/音效/视频播放(利用Cocos2D-iPhone-Extensions嵌入Cocos2d进行视频播放!)