<small id='TXMzK'></small><noframes id='TXMzK'>

    1. <legend id='TXMzK'><style id='TXMzK'><dir id='TXMzK'><q id='TXMzK'></q></dir></style></legend>

      <tfoot id='TXMzK'></tfoot>

          <bdo id='TXMzK'></bdo><ul id='TXMzK'></ul>
      1. <i id='TXMzK'><tr id='TXMzK'><dt id='TXMzK'><q id='TXMzK'><span id='TXMzK'><b id='TXMzK'><form id='TXMzK'><ins id='TXMzK'></ins><ul id='TXMzK'></ul><sub id='TXMzK'></sub></form><legend id='TXMzK'></legend><bdo id='TXMzK'><pre id='TXMzK'><center id='TXMzK'></center></pre></bdo></b><th id='TXMzK'></th></span></q></dt></tr></i><div id='TXMzK'><tfoot id='TXMzK'></tfoot><dl id='TXMzK'><fieldset id='TXMzK'></fieldset></dl></div>

        如何使用 AVMutableCompositionTrack 合并音频和视频

        时间:2023-10-03
        <i id='JhYDi'><tr id='JhYDi'><dt id='JhYDi'><q id='JhYDi'><span id='JhYDi'><b id='JhYDi'><form id='JhYDi'><ins id='JhYDi'></ins><ul id='JhYDi'></ul><sub id='JhYDi'></sub></form><legend id='JhYDi'></legend><bdo id='JhYDi'><pre id='JhYDi'><center id='JhYDi'></center></pre></bdo></b><th id='JhYDi'></th></span></q></dt></tr></i><div id='JhYDi'><tfoot id='JhYDi'></tfoot><dl id='JhYDi'><fieldset id='JhYDi'></fieldset></dl></div>

          <bdo id='JhYDi'></bdo><ul id='JhYDi'></ul>

            <small id='JhYDi'></small><noframes id='JhYDi'>

                <tbody id='JhYDi'></tbody>
              <legend id='JhYDi'><style id='JhYDi'><dir id='JhYDi'><q id='JhYDi'></q></dir></style></legend>
                • <tfoot id='JhYDi'></tfoot>
                • 本文介绍了如何使用 AVMutableCompositionTrack 合并音频和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我需要合并音频和视频,然后我需要在 Mediaplayer 中播放音频文件.如何在IOS中合并音频和视频.是否有任何源代码.请给我一些建议

                  In my application I need to merge audio and video and then I need to play the audio file in the Mediaplayer. How can I merge the audio and video in IOS. Is there is any source code for this. Please suggest me some ideas

                  提前致谢

                  推荐答案

                  使用这个

                  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:AVAssetExportPresetHighestQuality];   
                  
                  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";
                  _assetExport.outputURL = exportUrl;
                  _assetExport.shouldOptimizeForNetworkUse = YES;
                  
                  [_assetExport exportAsynchronouslyWithCompletionHandler:
                   ^(void ) {      
                              // your completion code here
                       }       
                   }
                   ];
                  

                  这篇关于如何使用 AVMutableCompositionTrack 合并音频和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:不在编辑模式下重新排序 UITableView 上的控件? 下一篇:如何在 iOS 4 上禁用快速应用程序切换(多任务)?

                  相关文章

                • <i id='d3Yl3'><tr id='d3Yl3'><dt id='d3Yl3'><q id='d3Yl3'><span id='d3Yl3'><b id='d3Yl3'><form id='d3Yl3'><ins id='d3Yl3'></ins><ul id='d3Yl3'></ul><sub id='d3Yl3'></sub></form><legend id='d3Yl3'></legend><bdo id='d3Yl3'><pre id='d3Yl3'><center id='d3Yl3'></center></pre></bdo></b><th id='d3Yl3'></th></span></q></dt></tr></i><div id='d3Yl3'><tfoot id='d3Yl3'></tfoot><dl id='d3Yl3'><fieldset id='d3Yl3'></fieldset></dl></div>

                    <small id='d3Yl3'></small><noframes id='d3Yl3'>

                    • <bdo id='d3Yl3'></bdo><ul id='d3Yl3'></ul>

                    <legend id='d3Yl3'><style id='d3Yl3'><dir id='d3Yl3'><q id='d3Yl3'></q></dir></style></legend>
                  1. <tfoot id='d3Yl3'></tfoot>