在AVMutableVideoComposition中交叉淡入淡出 [英] Cross-fade within AVMutableVideoComposition

查看:703
本文介绍了在AVMutableVideoComposition中交叉淡入淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地组合了一个具有多个视频剪辑的AVMutableComposition,并且可以查看它并导出它,我想要使用交叉淡入淡出在他们之间转换,所以我想使用AVMutableVideoComposition。我找不到任何例子,如何甚至安排和播放一对夫妇AVAsset视频连续。有没有人有一个例子,如何添加轨道到AVMutableVideoComposition等效的AVMutableComposition的insertTimeRange,或如何设置交叉淡化?

I have successfully composed an AVMutableComposition with multiple video clips and can view it and export it, and I would like to be able to transition between them using a cross-fade, so I want to use AVMutableVideoComposition. I can't find any examples on how to even arrange and play a couple AVAsset videos in succession. Does anyone have an example of how to add tracks to an AVMutableVideoComposition with the equivalent of AVMutableComposition's insertTimeRange, or how to set up a cross-fade?

[self.composition insertTimeRange:CMTimeRangeMake(kCMTimeZero,asset.avAsset.duration)
                                         ofAsset:asset.avAsset
                                          atTime:self.composition.frameDuration
                                           error:nil]


推荐答案

我从Apple的WWDC 2010示例代码中找到了一个名为AVEditDemo的示例。

I found an example called AVEditDemo from Apple's WWDC 2010 Sample Code.

https:// developer .apple.com / library / ios / samplecode / AVCustomEdit / Introduction / Intro.html

样本中有很多细节,总结:您需要同时使用AVMutableComposition和AVMutableVideoComposition。将轨道单独添加到AVMutableComposition,而不是使用更简单的insertTimeRange,因为它允许您在轨道上设置重叠时间。还需要将轨道添加到AVMutableVideoComposition作为具有不透明度斜坡的AVMutableVideoCompositionLayerInstructions。最后,要在AVPlayer中播放,您需要使用AVMutableComposition和AVMutableVideoComposition创建一个AVPlayerItem。

There is a lot of detail in the sample, but I'll summarize: You need to use both AVMutableComposition and AVMutableVideoComposition. Add tracks individually to AVMutableComposition instead of with the simpler insertTimeRange, as it allows you to set overlapping times on the tracks. The tracks also need to be added to the AVMutableVideoComposition as AVMutableVideoCompositionLayerInstructions with an opacity ramp. Finally, to play back in an AVPlayer, you need to create an AVPlayerItem using both the AVMutableComposition and AVMutableVideoComposition.

看起来像在api中的每个级别更深情况从MPMoviePlayer与资产到AVPlayer与AVComposition,最后到AVVideoComposition - 增加必要的编码指数。

It seems like going each level deeper in the api – in this case from MPMoviePlayer with an asset to AVPlayer with an AVComposition and finally to an AVVideoComposition – increases necessary coding exponentially.

这篇关于在AVMutableVideoComposition中交叉淡入淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆