简体   繁体   English

合并iOS中的视频

[英]Merge videos in iOS

I'm using this wonderful tutorial to load 2 videos and merge them in iOS. 我正在使用这个精彩的教程来加载2个视频并将其合并到iOS中。

http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios

I'd like to adapt this to be able to handle unlimited videos selected by the user, but am struggling. 我想对此进行调整,使其能够处理用户选择的无限视频,但是很费劲。 How do I create an array of AVAsset objects that can then be combined into a single video? 如何创建AVAsset对象数组,然后将其组合成一个视频?

I save each video's MediaURL in an array which I then use to read each video from when I want to merge them. 我将每个视频的MediaURL保存在一个数组中,然后在合并它们时用于读取每个视频。 You can see more of it in my question here 你可以看到更多的在我的问题在这里

Note how I handle the insert time after each merge. 注意每次合并后我如何处理插入时间。

Its pretty easy to extend it to any number of videos. 将其扩展到任意数量的视频非常容易。 All you need is their URL. 您需要的只是他们的URL。 In the tutorial you mentioned they merge two videos so you know the basics. 在您提到的教程中,他们将两个视频合并在一起,因此您了解基础知识。 Just look at this tutorial . 只要看一下本教程 It matches exactly your requirement and easy to understand. 它完全符合您的要求并且易于理解。

You just have to implement getRandomVideoFileURL method. 您只需要实现getRandomVideoFileURL方法。 Create an array of all video's URL. 创建一个包含所有视频URL的数组。 Pass the index of loop (i) and get the URL. 传递循环(i)的索引并获取URL。

UPDATE : To add instructions, put this part in your loop: 更新 :要添加说明,请将此部分放入循环中:

AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
videoCompositionInstruction.timeRange = CMTimeRangeMake(time, assetTrack.timeRange.duration);
videoCompositionInstruction.layerInstructions = @[[AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoCompositionTrack]];
[instructions addObject:videoCompositionInstruction];

Then, after the loop form AVMutableVideoComposition like this: 然后,在循环形式AVMutableVideoComposition如下所示: AVMutableVideoComposition

AVMutableVideoComposition *mutableVideoComposition = [AVMutableVideoComposition videoComposition];
mutableVideoComposition.instructions = instructions;
mutableVideoComposition.frameDuration = CMTimeMake(1, 30);
mutableVideoComposition.renderSize = size; 

Change the variable names as you need, as I don't know which tutorial you are following. 根据需要更改变量名,因为我不知道您在关注哪个教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM