时光在线 小视频 中文字幕怎么添字幕?

IOS使用AVFoundation在视频上添加字幕以及控制字幕时间
IOS在视频上添加字幕效果的基本思路是:
使用自定义的CATextLayer文字图层或者CAShapeLayer文字图层,添加到视频的Layer上创建用户自定义的字幕效果。这两者的区别是:CATextLayer支持设置简单的文字效果,包括文字的内容、字体、字号大小、对其方式、文字颜色、背景颜色等基本的属性;CAShapeLayer功能更强大,提供了CATextLayer没有的边框大小、边框颜色等设置,如果需要更高级的文字内容展示,需要使用CATextLayer配合UIBezierPath来定制自定义的文字内容。
通过设置Layer图层的动画来控制字幕的时间点和时间长度,这里有一个坑如果单独设置CATextLayer或者CAShapeLayer的动画不能控制开始的时间,需要额外添加一个CALayer图层,把文字图层CATextLayer或者CAShapeLayer添加到父CALayer图层中,在文字图层CATextLayer或者CAShapeLayer上设置开始的动画
NSTimeInterval animatedInStartTime = startTime + initAnimationDuration
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]
fadeInAnimation.fromValue = @0.0f
fadeInAnimation.toValue = @1.0f
fadeInAnimation.additive = NO
fadeInAnimation.removedOnCompletion = NO
fadeInAnimation.beginTime = animatedInStartTime
fadeInAnimation.duration = animationDuration
fadeInAnimation.autoreverses = NO
fadeInAnimation.fillMode = kCAFillModeBoth
[textLayer addAnimation:fadeInAnimation forKey:@"opacity"]
在父CALayer图层上设置结束的动画,这样设置才能实现用户自定义的时间点和时间长度
NSTimeInterval animatedOutStartTime = startTime + duration - animationDuration
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]
fadeOutAnimation.fromValue = @1.0f
fadeOutAnimation.toValue = @0.0f
fadeOutAnimation.additive = NO
fadeOutAnimation.removedOnCompletion = NO
fadeOutAnimation.beginTime = animatedOutStartTime
fadeOutAnimation.duration = animationDuration
fadeOutAnimation.autoreverses = NO
fadeOutAnimation.fillMode = kCAFillModeBoth
[animatedTitleLayer addAnimation:fadeOutAnimation forKey:@"opacity"]
完整的代码
- (CALayer *)buildLayerbuildTxt:(NSString*)text
textSize:(CGFloat)textSize
textColor:(UIColor*)textColor
strokeColor:(UIColor*)strokeColor
opacity:(CGFloat)opacity
textRect:(CGRect)textRect
fontPath:(NSString*)fontPath
viewBounds:(CGSize)viewBounds
startTime:(NSTimeInterval)startTime
duration:(NSTimeInterval)duration
if (!text || [text isEqualToString:@""])
return nil
// Create a layer for the overall title animation.
CALayer *animatedTitleLayer = [CALayer layer]
// 1. Create a layer for the text of the title.
CATextLayer *titleLayer = [CATextLayer layer]
titleLayer.string = text
titleLayer.font = (__bridge CFTypeRef)(@"Helvetica")
titleLayer.fontSize = textSize
titleLayer.alignmentMode = kCAAlignmentCenter
titleLayer.bounds = CGRectMake(0, 0, textRect.size.width, textRect.size.height)
titleLayer.foregroundColor = textColor.CGColor
titleLayer.backgroundColor = [UIColor clearColor].CGColor
// [animatedTitleLayer addSublayer:titleLayer]
// 添加文字以及边框效果
UIFont *font = nil
if ((fontPath != nil) && (fontPath.length & 0)) {
font = [[FLVideoEditFontManager sharedFLVideoEditFontManager] fontWithPath:fontPath size:textSize]
titleLayer.font = CGFontCreateWithFontName((__bridge CFStringRef)font.fontName)
if (font == nil) {
titleLayer.font = (__bridge CFTypeRef)(@"Helvetica")
UIBezierPath *path = nil
if (font) {
path = [FLLayerBuilderTool createPathForText:text fontHeight:textSize fontName:(__bridge CFStringRef)(font.fontName)]
path = [FLLayerBuilderTool createPathForText:text fontHeight:textSize fontName:CFSTR("Helvetica")]
CGRect rectPath = CGPathGetBoundingBox(path.CGPath)
CAShapeLayer *textLayer = [CAShapeLayer layer]
textLayer.path = path.CGPath
textLayer.lineWidth = 1
if (strokeColor != nil) {
textLayer.strokeColor = strokeColor.CGColor
if (textColor != nil) {
textLayer.fillColor = textColor.CGColor
textLayer.lineJoin = kCALineJoinRound
textLayer.lineCap = kCALineCapRound
textLayer.geometryFlipped = NO
textLayer.opacity = opacity
textLayer.bounds = CGRectMake(0, 0, rectPath.size.width, textSize+10)
[animatedTitleLayer addSublayer:textLayer]
// 动画图层位置
animatedTitleLayer.position = CGPointMake(textRect.origin.x+textRect.size.width/2, viewBounds.height - textRect.size.height/2 - textRect.origin.y)
NSTimeInterval initAnimationDuration = 0.1f
NSTimeInterval animationDuration = 0.1f
// 3.显示动画
NSTimeInterval animatedInStartTime = startTime + initAnimationDuration
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]
fadeInAnimation.fromValue = @0.0f
fadeInAnimation.toValue = @1.0f
fadeInAnimation.additive = NO
fadeInAnimation.removedOnCompletion = NO
fadeInAnimation.beginTime = animatedInStartTime
fadeInAnimation.duration = animationDuration
fadeInAnimation.autoreverses = NO
fadeInAnimation.fillMode = kCAFillModeBoth
[textLayer addAnimation:fadeInAnimation forKey:@"opacity"]
NSTimeInterval animatedOutStartTime = startTime + duration - animationDuration
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]
fadeOutAnimation.fromValue = @1.0f
fadeOutAnimation.toValue = @0.0f
fadeOutAnimation.additive = NO
fadeOutAnimation.removedOnCompletion = NO
fadeOutAnimation.beginTime = animatedOutStartTime
fadeOutAnimation.duration = animationDuration
fadeOutAnimation.autoreverses = NO
fadeOutAnimation.fillMode = kCAFillModeBoth
[animatedTitleLayer addAnimation:fadeOutAnimation forKey:@"opacity"]
return animatedTitleLayer
依赖的工具类FLLayerBuilderTool.m文件:
#import "FLLayerBuilderTool.h"
#import &CoreText/CoreText.h&
@implementation FLLayerBuilderTool
+ (UIBezierPath*) createPathForText:(NSString*)string fontHeight:(CGFloat)height fontName:(CFStringRef)fontName
if ([string length] & 1)
return nil;
UIBezierPath *combinedGlyphsPath = nil;
CGMutablePathRef letters = CGPathCreateMutable();
CTFontRef font = CTFontCreateWithName(fontName, height, NULL);
if (font == nil) {
font = (__bridge CFTypeRef)(@"Helvetica");
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)font, kCTFontAttributeName,
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
for (CFIndex runIndex = 0; runIndex & CFArrayGetCount(runArray); runIndex++)
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
for (CFIndex runGlyphIndex = 0; runGlyphIndex & CTRunGetGlyphCount(run); runGlyphIndex++)
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
CFRelease(line);
combinedGlyphsPath = [UIBezierPath bezierPath];
[combinedGlyphsPath moveToPoint:CGPointZero];
[combinedGlyphsPath appendPath:[UIBezierPath bezierPathWithCGPath:letters]];
CGPathRelease(letters);
CFRelease(font);
if (attrString)
attrString = nil;
return combinedGlyphsP
参考资料:
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!如何给视频快速加上字幕?_百度知道
如何给视频快速加上字幕?
尝试过会声会影X4,但只会加特效字幕,那种如同电影一样的字幕如何添加?时间轴的处理有什么要点吗?比如做一个《元首的愤怒》,如何确保音画同步?
我有更好的答案
我用会声会影都是边听边插字幕,没有用时间轴,因为时间排布又还需要用别的软件,比如popsub之类的,我觉得很麻烦。 你可以试试直接放视频,然后到需要加字幕的地方直接暂停,然后点标题,然后直接在画面上需要放字幕的位置双击,就可以输入文字了。
我的X4里标题都只有特效字幕添加……
你点屏幕以后是不是有一个文字输入框? 整个编辑小屏幕的右侧,是不是有编辑区??你扩大素材库看看,应该有编辑/动画两种模式,你选编辑,取消动画再试试
采纳率:49%
百度搜一下么,用会声会影加字幕,有专门制作字幕的教程,说也说不清楚。还不如看教程来的快~
参考了但是想问一下,如果POPSUB做出的字幕时间不对,可以再会声会影中该吗?
貌似不行,会声会影不认的popsub的编辑文件,应该改不了
给视频加字幕,建议用
爱剪辑,简单易上手最易用、强大的免费视频制作和视频剪辑软件点击 字幕特效 ,双击视频预览画面,即可添加字幕。软件自带了 水墨、风沙、雷击爆破、火焰特效、缤纷秋叶等大片级好莱坞字幕特效,和逐字呈现、翻滚、放大等酷炫字幕特效,一键即可渲染支持一键插入歌词文件,并渲染MTV字幕特效,和卡拉OK字幕特效并自带了各种动感风格滤镜特效、几百种视频转场特效一键设置,打造大片级视频效果支持对视频一键美颜、美化,磨皮等,还可以一键调色。支持烈火燎原、缤纷时尚、水墨晕染等影院级动景特效软件性能非常稳定,不像传统软件易卡顿和崩溃
1条折叠回答
为您推荐:
其他类似问题
您可能关注的内容
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。IOS使用AVFoundation在视频上添加字幕以及控制字幕时间_iOS开发_动态网站制作指南
IOS使用AVFoundation在视频上添加字幕以及控制字幕时间
来源:人气:1697
IOS在视频上添加字幕效果的基本思路是:
使用自定义的CATextLayer文字图层或者CAShapeLayer文字图层,添加到视频的Layer上创建用户自定义的字幕效果。这两者的区别是:CATextLayer支持设置简单的文字效果,包括文字的内容、、字号大小、对其方式、文字颜色、背景颜色等基本的属性;CAShapeLayer功能更强大,提供了CATextLayer没有的边框大小、边框颜色等设置,如果需要更高级的文字内容展示,需要使用CATextLayer配合UIBezierPath来定制自定义的文字内容。
通过设置Layer图层的动画来控制字幕的时间点和时间长度,这里有一个坑如果单独设置CATextLayer或者CAShapeLayer的动画不能控制开始的时间,需要额外添加一个CALayer图层,把文字图层CATextLayer或者CAShapeLayer添加到父CALayer图层中,在文字图层CATextLayer或者CAShapeLayer上设置开始的动画
NSTimeInterval animatedInStartTime = startTime + initAnimationD
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.fromValue = @0.0f;
fadeInAnimation.toValue = @1.0f;
fadeInAnimation.additive = NO;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.beginTime = animatedInStartT
fadeInAnimation.duration = animationD
fadeInAnimation.autoreverses = NO;
fadeInAnimation.fillMode = kCAFillModeB
[textLayer addAnimation:fadeInAnimation forKey:@"opacity"];
在父CALayer图层上设置结束的动画,这样设置才能实现用户自定义的时间点和时间长度
NSTimeInterval animatedOutStartTime = startTime + duration - animationD
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeOutAnimation.fromValue = @1.0f;
fadeOutAnimation.toValue = @0.0f;
fadeOutAnimation.additive = NO;
fadeOutAnimation.removedOnCompletion = NO;
fadeOutAnimation.beginTime = animatedOutStartT
fadeOutAnimation.duration = animationD
fadeOutAnimation.autoreverses = NO;
fadeOutAnimation.fillMode = kCAFillModeB
[animatedTitleLayer addAnimation:fadeOutAnimation forKey:@"opacity"];
完整的代码
- (CALayer *)buildLayerbuildTxt:(NSString*)text
textSize:(CGFloat)textSize
textColor:(UIColor*)textColor
strokeColor:(UIColor*)strokeColor
opacity:(CGFloat)opacity
textRect:(CGRect)textRect
fontPath:(NSString*)fontPath
viewBounds:(CGSize)viewBounds
startTime:(NSTimeInterval)startTime
duration:(NSTimeInterval)duration
if (!text || [text isEqualToString:@""])
// Create a layer for the overall title animation.
CALayer *animatedTitleLayer = [CALayer layer];
// 1. Create a layer for the text of the title.
CATextLayer *titleLayer = [CATextLayer layer];
titleLayer.string =
titleLayer.font = (__bridge CFTypeRef)(@"Helvetica");
titleLayer.fontSize = textS
titleLayer.alignmentMode = kCAAlignmentC
titleLayer.bounds = CGRectMake(0, 0, textRect.size.width, textRect.size.height);
titleLayer.foregroundColor = textColor.CGC
titleLayer.backgroundColor = [UIColor clearColor].CGC
// [animatedTitleLayer addSublayer:titleLayer];
// 添加文字以及边框效果
UIFont *font =
if ((fontPath != nil) && (fontPath.length & 0)) {
font = [[FLVideoEditFontManager sharedFLVideoEditFontManager] fontWithPath:fontPath size:textSize];
titleLayer.font = CGFontCreateWithFontName((__bridge CFStringRef)font.fontName);
if (font == nil) {
titleLayer.font = (__bridge CFTypeRef)(@"Helvetica");
UIBezierPath *path =
if (font) {
path = [FLLayerBuilderTool createPathForText:text fontHeight:textSize fontName:(__bridge CFStringRef)(font.fontName)];
path = [FLLayerBuilderTool createPathForText:text fontHeight:textSize fontName:CFSTR("Helvetica")];
CGRect rectPath = CGPathGetBoundingBox(path.CGPath);
CAShapeLayer *textLayer = [CAShapeLayer layer];
textLayer.path = path.CGP
textLayer.lineWidth = 1;
if (strokeColor != nil) {
textLayer.strokeColor = strokeColor.CGC
if (textColor != nil) {
textLayer.fillColor = textColor.CGC
textLayer.lineJoin = kCALineJoinR
textLayer.lineCap = kCALineC
textLayer.geometryFlped = NO;
textLayer.opacity =
textLayer.bounds = CGRectMake(0, 0, rectPath.size.width, textSize+10);
[animatedTitleLayer addSublayer:textLayer];
// 动画图层位置
animatedTitleLayer.position = CGPointMake(textRect.origin.x+textRect.size.width/2, viewBounds.height - textRect.size.height/2 - textRect.origin.y);
NSTimeInterval initAnimationDuration = 0.1f;
NSTimeInterval animationDuration = 0.1f;
// 3.显示动画
NSTimeInterval animatedInStartTime = startTime + initAnimationD
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.fromValue = @0.0f;
fadeInAnimation.toValue = @1.0f;
fadeInAnimation.additive = NO;
fadeInAnimation.removedOnCompletion = NO;
fadeInAnimation.beginTime = animatedInStartT
fadeInAnimation.duration = animationD
fadeInAnimation.autoreverses = NO;
fadeInAnimation.fillMode = kCAFillModeB
[textLayer addAnimation:fadeInAnimation forKey:@"opacity"];
NSTimeInterval animatedOutStartTime = startTime + duration - animationD
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeOutAnimation.fromValue = @1.0f;
fadeOutAnimation.toValue = @0.0f;
fadeOutAnimation.additive = NO;
fadeOutAnimation.removedOnCompletion = NO;
fadeOutAnimation.beginTime = animatedOutStartT
fadeOutAnimation.duration = animationD
fadeOutAnimation.autoreverses = NO;
fadeOutAnimation.fillMode = kCAFillModeB
[animatedTitleLayer addAnimation:fadeOutAnimation forKey:@"opacity"];
return animatedTitleL
依赖的工具类FLLayerBuilderTool.m文件:
#import "FLLayerBuilderTool.h"
#import &CoreText/CoreText.h&
@implementation FLLayerBuilderTool
+ (UIBezierPath*) createPathForText:(NSString*)string fontHeight:(CGFloat)height fontName:(CFStringRef)fontName
if ([string length] & 1)
UIBezierPath *combinedGlyphsPath =
CGMutablePathRef letters = CGPathCreateMutable();
CTFontRef font = CTFontCreateWithName(fontName, height, NULL);
if (font == nil) {
font = (__bridge CFTypeRef)(@"Helvetica");
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)font, kCTFontAttributeName,
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
// for each RUN
for (CFIndex runIndex = 0; runIndex & CFArrayGetCount(runArray); runIndex++)
// Get FONT for this run
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
// for each GLYPH in run
for (CFIndex runGlyphIndex = 0; runGlyphIndex & CTRunGetGlyphCount(run); runGlyphIndex++)
// get Glyph & Glyph-data
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);
// Get PATH of outline
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
CFRelease(line);
combinedGlyphsPath = [UIBezierPath bezierPath];
[combinedGlyphsPath moveToPoint:CGPointZero];
[combinedGlyphsPath appendPath:[UIBezierPath bezierPathWithCGPath:letters]];
CGPathRelease(letters);
CFRelease(font);
if (attrString)
attrString =
return combinedGlyphsP
参考资料:
视频特效制作:如何给视频添加边框、水印、动画以及3D效果
视频特效制作2
AVFoundation Tutorial: Adding Overlays and Animations to Videos
优质网站模板EDIUS中的视频的字幕该怎么进行添加?_百度知道
EDIUS中的视频的字幕该怎么进行添加?
我有更好的答案
你在需要添加字幕的T轨道上,单击右键,选新建——新建素材——选择quicktitler。
广播电视领域专家
& & 首先,将时间线指针拖到要插入字幕的位置,点击时间线面板工具栏上的 T 字图标,根据需要选择“在视频轨道上创建字幕”或“在1T轨道上创建字幕”。两种不同的创建字幕的方式,所产生的结果也不相同,根据编辑视频的需要,可以 选择合适的插入字幕方式(如切换片段中间的字幕,需要使用“在视频轨道上创建字幕”)。  在弹出的Quick Title窗口中输入EDIUS添加字幕所需文字,最下方可选择字幕风格,右侧可更改字幕文本属性,最简单的情况就是调整字幕位置,更改字体、大小等,然后点击左上的“保存”图标;  此时,EDIUS字幕就添加到时间线标尺所在位置的轨道上了,而且你也会发现素材面板中也有了创建的字幕素材。
本回答被提问者采纳
点T,然后加字幕 保存
给视频加字幕,建议用
爱剪辑,简单易上手最易用、强大的免费视频制作和视频剪辑软件点击 字幕特效 ,双击视频预览画面,即可添加字幕。软件自带了 水墨、风沙、雷击爆破、火焰特效、缤纷秋叶等大片级好莱坞字幕特效,和逐字呈现、翻滚、放大等酷炫字幕特效,一键即可渲染支持一键插入歌词文件,并渲染MTV字幕特效,和卡拉OK字幕特效并自带了各种动感风格滤镜特效、几百种视频转场特效一键设置,打造大片级视频效果支持对视频一键美颜、美化,磨皮等,还可以一键调色。支持烈火燎原、缤纷时尚、水墨晕染等影院级动景特效软件性能非常稳定,不像传统软件易卡顿和崩溃
1条折叠回答
为您推荐:
其他类似问题
您可能关注的内容
edius的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 幸福时光字幕 的文章

 

随机推荐