如何将静态图像添加到AVComposition? [英] How do I add a still image to an AVComposition?
问题描述
我有一个 AVMutableComposition
带有一个视频轨道,我想在视频轨道中添加一个静止图像,以便显示一段时间。静止图像只是一个PNG。我可以将图像作为资产加载,但这就是它,因为生成的资产没有任何轨道,因此无法使用 insertTimeRange ...
方法简单地插入。
I have an AVMutableComposition
with a video track and I would like to add a still image into the video track, to be displayed for some given time. The still image is simply a PNG. I can load the image as an asset, but that’s about it, because the resulting asset does not have any tracks and therefore cannot be simply inserted using the insertTimeRange…
methods.
有没有办法将静止图像添加到合成中?看起来答案在Core Animation的某个地方,但整个事情似乎有点高于我的头脑,我会很感激代码示例或一些信息指针。
Is there a way to add still images to a composition? It looks like the answer is somewhere in Core Animation, but the whole thing seems to be a bit above my head and I would appreciate a code sample or some information pointers.
推荐答案
好的。 WWDC 上有一个名为使用AV Foundation编辑媒体的精彩视频,解释了很多。您无法将图像直接插入 AVComposition
时间轴,至少我没有找到任何方法。但是在导出或播放资产时,您可以参考 AVVideoComposition
。这可能不是这个类的完美名称,因为它允许你在资产中的各种视频轨道之间混合,非常像 AVAudioMix
为音频做。而 AVVideoComposition
有一个 animationTool
属性,可以让你投掷核心动画图层( CALayer
)混合。 CALayer
有一个内容
属性,可以分配 CGImageRef
。在我的情况下没有帮助,可能会帮助其他人。
OK. There’s a great video called Editing Media with AV Foundation from WWDC that explains a lot. You can’t insert images right to the AVComposition
timeline, at least I did not find any way to do that. But when exporting or playing an asset you can refer to an AVVideoComposition
. That’s maybe not a perfect name for the class, since it allows you to mix between various video tracks in the asset, very much like AVAudioMix
does for audio. And the AVVideoComposition
has an animationTool
property that lets you throw Core Animation layers (CALayer
) into the mix. CALayer
has a contents
property that can be assigned a CGImageRef
. Does not help in my case, might help somebody else.
这篇关于如何将静态图像添加到AVComposition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!