如何使用AVFoundation为视频的不同片段应用不同的文本

时间:2014-01-28 15:12:17

标签: ios objective-c video avfoundation

我正在尝试将视频的已用时间加水印到视频帧上。但我只能使用AVVideoCompositionCoreAnimationToolCALayer在整个视频时段内呈现静态文本。

如何应用更改每秒覆盖在视频上的文字?

Stack Overflow中的类似问题也没有得到解答

1 个答案:

答案 0 :(得分:0)

您可以参考

http://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos

你只需要CABasicAnimation并添加你的标题图层。只需检查一下,改变所需的参数即可正常工作。我已经完成了我的项目之一

CATextLayer *title = [CATextLayer layer];
// code for title layer setting
// code for the opacity animation which will remove the text
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animation setDuration:0];
[animation setFromValue:[NSNumber numberWithFloat:1.0]];
[animation setToValue:[NSNumber numberWithFloat:0.0]];
[animation setBeginTime:1];
[animation setRemovedOnCompletion:NO];
[animation setFillMode:kCAFillModeForwards];
[title addAnimation:animation forKey:@"animateOpacity"];

CATextLayer *title = [CATextLayer layer]; // code for title layer setting // code for the opacity animation which will remove the text CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"]; [animation setDuration:0]; [animation setFromValue:[NSNumber numberWithFloat:1.0]]; [animation setToValue:[NSNumber numberWithFloat:0.0]]; [animation setBeginTime:1]; [animation setRemovedOnCompletion:NO]; [animation setFillMode:kCAFillModeForwards]; [title addAnimation:animation forKey:@"animateOpacity"];