如何将静态图像添加到 AVComposition 中?

发布于 2024-10-04 08:48:29 字数 250 浏览 5 评论 0原文

我有一个带有视频轨道的 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风疏影 2024-10-11 08:48:29

好的。 WWDC 有一个很棒的视频,名为使用 AV Foundation 编辑媒体,其中解释了很多内容。您无法将图像直接插入 AVComposition 时间线,至少我没有找到任何方法来做到这一点。但是,在导出或播放资产时,您可以引用 AVVideoComposition。对于该类来说,这可能不是一个完美的名称,因为它允许您在资源中的各种视频轨道之间进行混合,非常类似于 AVAudioMix 对音频的作用。 AVVideoComposition 有一个 animationTool 属性,可让您将核心动画层 (CALayer) 放入混合中。 CALayer 有一个 contents 属性,可以分配一个 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.

北方。的韩爷 2024-10-11 08:48:29

我的作品中还需要静止图像。我的思路有点不同。在应该出现图像的地方插入黑色的动态电影(可能一个这样的视频就足够了)。为每个此类插入添加字典参考,将构图时间范围链接到真正所需的图像。当正确的时间范围到达我的全职自定义合成器时,拉出所需的图像并将其绘制到输出像素缓冲区中,忽略合成中传入的黑色帧。我认为这是另一种方式。

I also need still images in my composition. My line of thinking is a little different. Insert on-the-fly movies of black in place of when images should be appearing (possibly one such video would suffice). Add a dictionary reference to each such insert, linking composition time-ranges to bona-fide desired images. When the correct time range arrives in my full-time custom compositor, pull out the desired image and paint that into the output pixel buffer, ignoring the incoming black frames from the composition. I think that'd be another way of doing it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文