我有持續時間爲4:00的視頻。現在我想根據視頻幀在視頻文件中添加文本。例如,從00:30到1:50,我想添加文字「歡迎」。現在從3點到4點視頻持續時間我想添加文字「真棒」。如何實現這一功能。我在下面提到了教程。它在整個視頻中添加文本,而不是一段視頻的時間。 https://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos如何在iOS SDK中添加一段視頻的文本
任何幫助將appriciated。
我對整個視頻添加的代碼行的附加文本:
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:36];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, 100)];
[subtitle1Text setString:_subTitle1.text];
[subtitle1Text setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text setForegroundColor:[[UIColor whiteColor] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
[overlayLayer addSublayer:subtitle1Text];
overlayLayer.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer 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];
composition.animationTool = [AVVideoCompositionCoreAnimationTool
videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
}
你可以這樣做,這是可能的,顯示你的代碼 –
我已經嘗試按照上面的示例代碼。 –
你能告訴我怎麼做嗎? –