如何使用AVAssetExportSession在AVMutableComposition上正确导出CALayer [英] How to properly export CALayer on top of AVMutableComposition with AVAssetExportSession
问题描述
我知道此问题之前已被问过(例如此处和此处)但我可以'弄清楚我做错了什么。
I know this question was asked before (for example here and here) but I just can't figure out what I'm doing wrong.
我有一个 AVMutableComposition
我用它来组合一些视频片段一些 CALayer
s在它们之上设置动画。
I have an AVMutableComposition
that I use to combine some video clips with some CALayer
s that animate on top of them.
当我拿走<$ c $时,一切正常c> AVMutableComposition 并将其与 AVSynchronizedLayer
组合,以便在 AVPlayerLayer
内播放。视频输出正确,一切都放在应有的位置。
Everything works ok when I take my AVMutableComposition
and combine it with an AVSynchronizedLayer
for playback inside an AVPlayerLayer
. The video comes out correctly and everything is positioned where it should.
我的问题是,当我尝试导出这个东西时,我尝试使用 AVVideoCompositionCoreAnimationTool
而不是 AVSynchronizedLayer
(这是我们应该用于导出的文档)和AVAssetExportSession,但出了点问题,因为在导出的电影中每个 CALayer
让它的坐标系反转。
My problem is that when I tried to export this thing I tried using AVVideoCompositionCoreAnimationTool
instead of AVSynchronizedLayer
(that's what the documentation says we should use for export) and an AVAssetExportSession, but something goes wrong because in my exported movie every CALayer
has it's coordinate system reversed.
因此,如果在回放期间0,0点位于顶部当我导出电影0,0点在左下角角落时屏幕的左侧一角,因此我的动画变得疯狂。
So if during playback the the 0,0 point is in the top-left corner of the screen when I export the movie the 0,0 point is in the bottom-left corner hence my animation go nuts.
我阅读了有关此内容的任何可能的文章,我还从Apple下载了AVVideoEdit样本,但我无法看到发生了什么......
I read any possible article about this and I also downloaded AVVideoEdit sample from Apple but I just can't see what is going on...
推荐答案
对于任何遇到同样问题的人,我终于找到了答案。每个 CALayer
都有一个名为 geometryFlipped
的属性,你需要设置为 YES
就在出口之前,一切都会好的。更多信息这里。
For anyone who has the same problem as I had I've finally found an answer. There is a property of every CALayer
called geometryFlipped
wich you need to set to YES
just before exporting and everything will be ok. More information here.
这篇关于如何使用AVAssetExportSession在AVMutableComposition上正确导出CALayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!