如何使用 AVAssetExportSession 在 AVMutableComposition 之上正确导出 CALayer
我知道这个问题之前被问过(例如这里 和此处)但我只是不明白我做错了什么。
我有一个 AVMutableComposition
,用来将一些视频剪辑与一些在其上进行动画处理的 CALayer
组合起来。
当我将 AVMutableComposition
与 AVSynchronizedLayer
结合起来在 AVPlayerLayer
内播放时,一切正常。视频正确显示,所有内容都位于应有的位置。
我的问题是,当我尝试导出这个东西时,我尝试使用 AVVideoCompositionCoreAnimationTool
而不是 AVSynchronizedLayer
(这就是文档所说的我们应该用于导出的内容)和 AVAssetExportSession,但是有些东西出错是因为在我导出的电影中,每个 CALayer 的坐标系都颠倒了。
因此,如果在播放期间 0,0 点位于屏幕的左上角,那么当我导出影片时,0,0 点位于左下角落,因此我的动画变得疯狂。
我阅读了任何有关此问题的文章,并且还从 Apple 下载了 AVVideoEdit 示例,但我只是看不到发生了什么......
I know this question was asked before (for example here and here) but I just can't figure out what I'm doing wrong.
I have an AVMutableComposition
that I use to combine some video clips with some CALayer
s that animate on top of them.
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.
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.
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.
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些和我有同样问题的人,我终于找到了答案。每个
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
calledgeometryFlipped
wich you need to set toYES
just before exporting and everything will be ok. More information here.