如何在iOS上使用AVMutableComposition和CALayers将多个CALayer添加到视频文件 [英] How to add multiple CALayer to a video file using AVMutableComposition and CALayers on iOS

查看:162
本文介绍了如何在iOS上使用AVMutableComposition和CALayers将多个CALayer添加到视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按时间顺序一个接一个地添加多个CALayer.我可以使用此链接在视频文件中添加一层此处.现在我的问题是,如何向视频文件添加多个CALayer.

I want to add multiple CALayer one after another by time sequence.I can add one layer to video file using this link Here. Now my question is that how can i add multiple CALayer to video file.

先谢谢了.

推荐答案

最直接的方法是将多个图层捆绑为单个图层.您将必须添加说明以在某个时候添加它,并在不需要时将其删除.像这样:

Most straightforward way is to bundle several layers into single layers. You will have to add instructions to add it at some point and remove when not needed. Something like this:

CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.fromValue = [NSNumber numberWithFloat:(float)!fadeIsIn];
fadeAnimation.toValue = [NSNumber numberWithFloat:(float)fadeIsIn];
fadeAnimation.additive = NO;
fadeAnimation.removedOnCompletion = NO;
fadeAnimation.beginTime = atTime;
fadeAnimation.duration = duration;
fadeAnimation.fillMode = kCAFillModeBoth;
[layer addAnimation:fadeAnimation forKey:nil];

在此示例中,您可以进行淡入/淡出(1.0开始和0.0基本上是淡出). atTime是您要开始显示/移除该图层的时间,而duration是淡入淡出的持续时间(因此,如果某个小数值0.0001(从未尝试过0.0(为什么?)),它将不会淡入淡出,而只会进行平淡裁剪).图层是您希望在某个时候显示/删除的CALayer.您显然需要两次调用此方法,一次用于淡入,第二次用于淡出.让我知道您是否有更好的解决方案! :) ps只是注意到这是一个非常老的问题!

In this example you can do fade In/Outs (1.0 start and 0.0 is basically fadeout). atTime is time where you want this layer to be start displaying/removing and duration is fade duration (so if some small number 0.0001 (never tried 0.0 (why?)), it will do no fade but just plain cut). layer is CALayer that you want to be displayed/removed at some point. You need to call this method twice obviously, once for fade in, second for out. Let me know if you have better solution! :) ps just notices this is a really old question!

这篇关于如何在iOS上使用AVMutableComposition和CALayers将多个CALayer添加到视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆