前提条件
- 开通IMS服务。
- 开通OSS服务或VOD服务,用于存储素材和成片。
接口说明
输入Timeline和成片地址,提交剪辑合成作业,返回剪辑作业JobId。
根据JobId获取剪辑合成作业信息,检查任务状态。
参数详细说明
Timeline中的详细参数说明,可以灵活设置音视频图片以及字幕多种轨道。
Timeline中Effect详细配置参数,可以设置转场、滤镜、特效等多种高级效果。
实现方式
1、字幕自动换行、自动缩放
参数设置
名称 |
类型 |
是否必填 |
描述 |
AdaptMode |
String |
否 |
AutoWrap:自动换行 AutoScale:自动缩放 |
TextWidth |
String |
否 |
像素值,文本框宽度,如果超出文字宽度的话会自动进行自动换行或者自动缩放处理。 |
timeline示例
{ "VideoTracks": [ { "VideoTrackClips": [ { "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/6.mov" } ] } ], "SubtitleTracks": [ { "SubtitleTrackClips": [ { "Type": "Text", "X": 0, "Y": 400, "FontURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "当不设置字幕自动换行或自动缩放时会超出视频画布", "Alignment": "TopCenter", "FontSize": 100, "FontColor": "#F5FFFA", "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "X": 0, "Y": 900, "FontURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "当字幕超出视频尺寸时触发自动换行", "AdaptMode": "AutoWrap", "Alignment": "TopCenter", "FontSize": 100, "FontColor": "#F5FFFA", "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "X": 0, "Y": 1400, "FontURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "当字幕超出视频尺寸时触发自动缩放", "AdaptMode": "AutoScale", "Alignment": "TopCenter", "FontSize": 100, "FontColor": "#F5FFFA", "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" } ] } ] }
2、设置局部字幕效果
content中增加局部参数覆写代码,覆写代码使用方式如下:
- 所有覆写代码均以两个反斜杠\\开头;
- 所有局部参数覆写代码必须在{}中,且一个{}可以包含多个覆写代码;
- 覆写代码会作用于其后的字幕上,如果想要结束该覆写代码,可以加一个与之对应的结束覆写代码来取消该效果;
覆写参数 |
参数描述 |
Content参数示例 |
\\1c&[BBGGRR]& \\2c&[BBGGRR]& \\3c&[BBGGRR]& |
1c为字体颜色,2c为边框颜色,3c为阴影颜色。 [BBGGRR]是十六进制的颜色BGR值,与一般的RGB颜色顺序相反。 |
"这里设置{\\1c&00FF7F&}绿{\\1c}色" |
\\bord[宽度] |
边框宽度,单位为像素。xbord,ybord为单独沿X轴或Y轴的边框宽度。 |
"这里设置{\\bord3\\3c&EBCE87&}描边宽度3{\\bord\\3c}颜色和大小" |
\\b0 \\b1 |
b1为加粗,b0为取消加粗。 |
"这里设置{\\b1}加粗{\\b0}效果", |
\\i0 \\i1 |
i1加斜体,i0为取消斜体。 |
"这里设置{\\i1}斜体{\\i0}效果" |
\\u0 \\u1 |
\u1为加下划线,\u0为取消下划线。 |
"这里设置{\\u1}下划线{\\u0}效果" |
\\s0 \\s1 |
\s1为加删除线,\s0为取消文本删除线。 |
"这里设置{\\s1}删除线{\\s0}效果" |
\\fs[字体尺寸] |
字幕大小,单位为像素。 |
"这里设置{\\fs100}100号{\\fs}文字" |
\\fn[字体名称] |
字幕名称,暂不支持设置自定义字体。 |
"这里设置{\\fnKaiTi}黑体{\\fn}字体" |
timeline示例
{ "VideoTracks": [ { "VideoTrackClips": [ { "MediaURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/6.mov" } ] } ], "SubtitleTracks": [ { "SubtitleTrackClips": [ { "Type": "Text", "X": 0, "Y": 800, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\1c&0801ea&\\3c&f7fcff&}深红色{\\1c\\3c}", "Alignment": "TopCenter", "FontSize": 65, "FontColor": "#F5FFFA", "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "X": 0, "Y": 400, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\fs100}100号{\\fs}字体", "Alignment": "TopCenter", "FontColor": "#F5FFFA", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 600, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\bord3\\3c&CD0000&}描边{\\bord\\3c}颜色和大小", "Alignment": "TopCenter", "FontSize": 65, "FontColor": "#F5FFFA", "TimelineIn": 0, "TimelineOut": 10, "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 200, "Content": "这里设置{\\bord3\\3c&701919&}不透明背景{\\bord\\3c}颜色和大小", "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "Alignment": "TopCenter", "FontColor": "#F5FFFA", "BorderStyle": 3, "Outline": 0, "OutlineColour": "#0000CD" }, { "Type": "Text", "Y": 1000, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\fnKaiTi}黑体{\\fn}字体", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "FontColor": "#F5FFFA", "Alignment": "TopCenter", "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 1400, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\b1}加粗{\\b0}效果", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "FontColor": "#F5FFFA", "Alignment": "TopCenter", "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 1300, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\i1}斜体{\\i0}效果", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "FontColor": "#F5FFFA", "Alignment": "TopCenter", "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 1200, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\u1}下划线{\\u0}效果", "FontColor": "#F5FFFA", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "Alignment": "TopCenter", "Outline": 2, "OutlineColour": "#0e0100" }, { "Type": "Text", "Y": 1600, "FontURL": "https://yuchen-test-shanghai.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "这里设置{\\1c&00FF00&\\b1\\fs100\\i1}组合{\\1c\\b0\\fs\\i0}效果", "FontColor": "#F5FFFA", "FontSize": 65, "TimelineIn": 0, "TimelineOut": 10, "Alignment": "TopCenter", "Outline": 2, "OutlineColour": "#0e0100" } ] } ] }
3、字幕特效、花字、自定义字体
Timeline示例
{ "VideoTracks": [ { "VideoTrackClips": [ { "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/6.mov" } ] } ], "SubtitleTracks": [ { "SubtitleTrackClips": [ { "Type": "Text", "X": 0, "Y": 500, "FontUrl": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "使用自定义字体配置花字", "AdaptMode": "AutoWrap", "Alignment": "TopCenter", "FontSize": 70, "EffectColorStyle": "skyline", "Outline": 5, "OutlineColour": "#87CEFA", "OutlineOpacity": 1, "TimelineIn": 0, "TimelineOut": 10 },{ "Type": "Text", "X": 0, "Y": 900, "FontUrl": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "使用自定义字体配置出场入场特效", "AdaptMode": "AutoScale", "Alignment": "TopCenter", "FontSize": 100, "FontColor": "#FFFF00", "TimelineIn": 0, "TimelineOut": 10, "AaiMotionIn": 3, "AaiMotionOut": 3, "AaiMotionInEffect": "wave_in", "AaiMotionOutEffect": "blur_out" },{ "Type": "Text", "X": 0, "Y": 1300, "FontUrl": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/material/AliHYAiHei.ttf", "Content": "使用自定义字体配置字幕循环特效", "AdaptMode": "AutoScale", "Alignment": "TopCenter", "FontSize": 100, "FontColor": "#FFFF00", "TimelineIn": 0, "TimelineOut": 10, "AaiMotionLoopEffect": "strongwave_display", "Ratio": 0.3 } ] } ] }
4、智能字幕
Timeline示例
{ "VideoTracks": [{ "VideoTrackClips": [{ "MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video7.mp4", "Effects": [{ "Type": "AI_ASR", "Font": "AlibabaPuHuiTi", "Alignment": "TopCenter", "Y": 910, "Outline": 10, "OutlineColour": "#ffffff", "FontSize": 60, "FontColor": "#000079", "FontFace": { "Bold": true, "Italic": false, "Underline": false } }] }] }] }
5、将字幕文件burnin进视频中
时间线示例
{ "VideoTracks": [ { "VideoTrackClips": [ { "MediaId": "MediaId1" }, { "MediaId": "MediaId3" } ] } ], "SubtitleTracks": [ { "SubtitleTrackClips": [ { "Type": "Subtitle", "SubType": "srt", "FileUrl": "http://your-bucket.oss-cn-shanghai.aliyuncs.com/your-subtitle.srt" },{ "Type": "Subtitle", "SubType": "ass", "FileUrl": "http://your-bucket.oss-cn-shanghai.aliyuncs.com/your-subtitle.ass" } ] } ] }