zoukankan      html  css  js  c++  java
  • 合成视频

    // 合成 我的视频大小都是一样的 所以没有对他们进行缩放裁剪等操作 

    - (void)mergeAndExportVideos {

        if (videoArray.count==0) {

            return;

        }

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];

      /// 从mixComposition取出音视频 轨道

            AVMutableCompositionTrack *audioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

            AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

            CMTime totalDuration = kCMTimeZero;

            NSError *error = nil;

            for (int i = 0; i < [videoArray count]; i++) {

                AVAsset *asset = [AVAsset assetWithURL:[[NSURL alloc] initFileURLWithPath:videoArray[i]]];

                

                [audioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.duration)

                                    ofTrack:[[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]

                                     atTime:totalDuration

                                      error:nil];

                

                [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.duration)

                                    ofTrack:[[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]

                                     atTime:totalDuration

                                      error:&error];

                totalDuration = CMTimeAdd(totalDuration, asset.duration);

            }

      /// 合成视频文件存储的路径

            NSString *path = [self getVideoMergeFilePathString];

            NSURL *mergeFileURL = [NSURL fileURLWithPath:path];

            AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPreset640x480];

            exporter.outputURL = mergeFileURL;

            exporter.outputFileType = AVFileTypeQuickTimeMovie;

            exporter.shouldOptimizeForNetworkUse = YES;

            [exporter exportAsynchronouslyWithCompletionHandler:^{

                for (NSString *path in videoArray) {

                    [self delFromLocal:path];

                }

                [videoArray removeAllObjects];

    //            [self savePhotoCmare:path];//写入相册

          

            }];

        });

    }

  • 相关阅读:
    CSS 与 HTML5 响应式图片
    Sublime Text3中最常用的快捷键
    JSON.parse这个是啥?
    页面的拼装配置Appache SSI
    如何保障mysql和redis之间的数据一致性?(转发)
    ORACLE异常ORA-01843 || ORA-14411 || Invalid column index
    Cause: java.sql.SQLException: 无效的列索引
    java.lang.IllegalArgumentException: host parameter is null
    java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException 异常
    java.sql.SQLIntegrityConstraintViolationException: ORA-00001: 违反唯一约束条件
  • 原文地址:https://www.cnblogs.com/xia0huihui/p/5430800.html
Copyright © 2011-2022 走看看