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];//写入相册

          

            }];

        });

    }

  • 相关阅读:
    A Survey of Machine Learning Techniques Applied to Software Defined Networking (SDN): Research Issues and Challenges
    A Deep Learning Based DDoS Detection System in Software-Defined Networking (SDN)
    解决win10 USB转串口无法使用
    Feeder-Link Outage Prediction Algorithms for SDN-based High-Throughput Satellite
    Flow monitoring in Software-Defined Networks
    Refining Network Intents for Self-Driving Networks
    2020生活变化
    【转载】 图解最小堆形成-以数组方式表示
    福大软工 · 最终作业
    福大软工 · 第十二次作业
  • 原文地址:https://www.cnblogs.com/xia0huihui/p/5430800.html
Copyright © 2011-2022 走看看