我正在尝试在每秒更改的视频上添加时间戳。我已经在SO上搜索了很多但是没有任何完美的解决方案或方法
我首先尝试使用此代码添加文本,但是这样字符串保持静态并且不会更改
CALayer *overlayLayer1 = [CALayer layer];
CATextLayer *subtitle1Text1 = [[CATextLayer alloc] init];
[subtitle1Text1 setFont:@"Helvetica-Bold"];
[subtitle1Text1 setFontSize:36];
[subtitle1Text1 setFrame:CGRectMake(0, 100, size.width, 100)];
dt = [[NSDateFormatter alloc]init];
[dt setDateFormat:@"HH:mm:ss"];
NSDate *date1 = [NSDate dateWithTimeIntervalSinceNow:10];
[subtitle1Text1 setString:[dt stringFromDate:date1]];
[subtitle1Text1 setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text1 setForegroundColor:[[UIColor whiteColor] CGColor]];
[overlayLayer1 addSublayer:subtitle1Text1];
overlayLayer1.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer1 setMasksToBounds:YES];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer];
[parentLayer addSublayer:overlayLayer1];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
比我试图通过使用以下代码添加动画图层,但有些如何使用
CATextLayer *overlayLayer1 = [CATextLayer layer];
CABasicAnimation *textanim = [CABasicAnimation animationWithKeyPath:@"content"];
textanim.duration = 1.0;
textanim.fromValue = @"Hey";
textanim.toValue = @"Hello";
textanim.beginTime = AVCoreAnimationBeginTimeAtZero;
textanim.removedOnCompletion = NO;
textanim.fillMode = kCAFillModeForwards;
[overlayLayer1 addAnimation:textanim forKey:@"contentAnimate"];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, 0, size.width, size.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:overlayLayer1];
[parentLayer addSublayer:overlayLayer2];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
任何人都可以帮忙,让我知道我做错了什么?或者有什么方法可以实现我想要的(在视频上添加时间戳)。
修改
我可以导出视频,我的问题是,在导出的视频上,我想添加随时间变化的文字,我没有上面的代码。