如何使用 AVAssetExportSession 在 AVMutableComposition 之上正确导出 CALayer

发布于 2024-11-25 10:49:54 字数 910 浏览 2 评论 0原文

我知道这个问题之前被问过(例如这里此处)但我只是不明白我做错了什么。

我有一个 AVMutableComposition,用来将一些视频剪辑与一些在其上进行动画处理的 CALayer 组合起来。

当我将 AVMutableCompositionAVSynchronizedLayer 结合起来在 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 CALayers 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 技术交流群。

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

发布评论

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

评论(2

贱人配狗天长地久 2024-12-02 10:49:54

对于那些和我有同样问题的人,我终于找到了答案。每个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.

你的呼吸 2024-12-02 10:49:54
Methods that fixing frames and points
- (CGRect) fixRect:(CGRect)rect inRect:(CGRect)container
{
    CGRect frame = rect;
    frame.origin.y = container.size.height - frame.origin.y - frame.size.height;
    return frame;
}
- (CGPoint) fixPoint:(CGPoint)point fromPoint:(CGSize)containerSize
{
    CGPoint frame = point;
    frame.y = containerSize.height - frame.y;
    return frame;
}
Methods that fixing frames and points
- (CGRect) fixRect:(CGRect)rect inRect:(CGRect)container
{
    CGRect frame = rect;
    frame.origin.y = container.size.height - frame.origin.y - frame.size.height;
    return frame;
}
- (CGPoint) fixPoint:(CGPoint)point fromPoint:(CGSize)containerSize
{
    CGPoint frame = point;
    frame.y = containerSize.height - frame.y;
    return frame;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文