字幕及字幕模板

本文为您介绍如何修改SubmitMediaProducingJobTimeline参数完成字幕及字幕模板处理。

使用说明

  • 智能生产制作支持直播流、点播和OSS素材文件的剪辑合成、特效渲染、模板生产等功能,更多详情请参见智能生产制作概述

  • 将一个或多个视频、音频、图片、字幕素材合成为成品,可以通过不同的Timeline参数配置提交剪辑,然后调用SubmitMediaProducingJob - 提交剪辑合成作业来完成合成。

  • 时间线是将素材按照视频创意进行编排和特效设计的产物,时间线主要包含轨道、素材、效果3种对象,详情请参见Timeline配置说明

  • 如果您想通过调用SDK进行音视频剪辑,请参见安装IMS服务端SDK的准备工作

视频添加字幕

说明
  1. 字幕可以放在单独的字幕轨道SubtitleTracks中,也可以在视频Effects下设置字幕。

  2. 字幕的出场和入场时间可以通过TimelineIn和TimelineOut进行设置。如果不设置这两个参数,字幕轨道中的字幕将默认按照整个成片视频的时长生成。而在Effects下的字幕,则会默认按照当前Effects归属的视频素材的时间来生成。

  3. 字幕中可以使用\N或\n来实现字幕换行效果。

成片效果

Timeline示例

{
	"VideoTracks": [{
		"VideoTrackClips": [{
			"MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h3.mp4",
			"Effects": [{
				"Type": "Background",
				"SubType": "Blur",
				"Radius": 0.1
			}]
		}]
	}],
	"SubtitleTracks": [{
		"SubtitleTrackClips": [{
			"Type": "Text",
			"X": 0,
			"Y": 200,
			"Content": "这里是标题",
			"Alignment": "TopCenter",
			"FontSize": 80,
			"FontColorOpacity": 1,
			"EffectColorStyle": "CS0003-000011",
			"FontFace": {
				"Bold": true
			}
		}, {
			"Type": "Text",
			"X": 0,
			"Y": 320,
			"Font": "KaiTi",
			"Content": "这里是副标题",
			"Alignment": "TopCenter",
			"FontSize": 45,
			"FontColor": "#ffffff",
			"FontFace": {
				"Italic": true,
				"Underline": true
			}
		}, {
			"Type": "Text",
			"X": 50,
			"Y": 740,
			"Font": "AlibabaPuHuiTi",
			"Content": "角度旋转",
			"FontColor": "#FFD700",
			"Outline": 4,
			"Angle": 350,
			"OutlineColour": "#000000",
			"FontSize": 60,
			"FontFace": {
				"Bold": true
			}
		}, {
			"Type": "Text",
			"X": 0,
			"Y": 900,
			"Font": "AlibabaPuHuiTi",
			"Content": "这里是横幅字幕\n可以加换行符进行多行展示",
			"Outline": 1,
			"OutlineColour": "000000",
			"Alignment": "TopCenter",
			"FontSize": 40,
			"FontColor": "#ffffff",
			"FontFace": {
				"Bold": true,
				"Italic": false,
				"Underline": false
			}
		}, {
			"Type": "Text",
			"X": 0,
			"Y": 1000,
			"Font": "KaiTi",
			"Content": "设置字幕出入场时间",
			"Alignment": "TopCenter",
			"FontSize": 40,
			"FontColor": "#ffffff",
			"TimelineIn": 5,
			"TimelineOut": 25,
			"FontFace": {
				"Bold": false,
				"Italic": true,
				"Underline": false
			}
		}]
	}]
}

设置字号、字体、自定义字体、描边、阴影、字幕旋转角度

说明
  1. FontSize表示字幕的字号。如果使用Effects下的字幕,建议使用FixedFontSize来设置字号,这样字幕不会随着视频尺寸的变化而发生变化。

  2. 使用Font来指定系统字体,使用FontURL来指定自定义字体OSS文件路径。当两者同时设置时,系统将优先按照FontURL来渲染字幕。

  3. 可以利用Outline、OutlineColour、Shadow、BackColour等参数来生成简单的单层描边阴影效果。如果需要实现复杂的多层描边效果,可以参考示例3中有关自定义花字的示例。

  4. 设置Angle来调整字幕逆时针旋转角度。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h2.mp4",
          "Effects": [
            {
              "Type": "Background",
              "SubType": "Blur",
              "Radius": 0.1
            }
          ]
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "Type": "Text",
          "X": 0,
          "Y": 200,
          "Content": "主标题80号字",
          "Alignment": "TopCenter",
          "FontSize": 80,
          "FontColorOpacity": 1,
          "EffectColorStyle": "CS0003-000023",
          "FontFace": {
            "Bold": true
          }
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 320,
          "Font": "KaiTi",
          "Content": "副标题楷体",
          "Alignment": "TopCenter",
          "FontSize": 45,
          "FontColor": "#ffffff",
          "FontFace": {
            "Italic": true,
            "Underline": true
          }
        },
        {
          "Type": "Text",
          "X": 50,
          "Y": 740,
          "Font": "AlibabaPuHuiTi",
          "Content": "角度旋转",
          "FontColor": "#FFD700",
          "Outline": 4,
          "Angle": 350,
          "OutlineColour": "#000000",
          "FontSize": 60,
          "FontFace": {
            "Bold": true
          }
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 900,
          "Content": "这里是横幅字幕,使用自定义字体\n设置宽度为1的黑色描边",
          "FontUrl": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/font/fangzhengfangsong.ttf",
          "Outline": 1,
          "OutlineColour": "000000",
          "Alignment": "TopCenter",
          "FontSize": 40,
          "FontColor": "#ffffff",
          "FontFace": {
            "Bold": true,
            "Italic": false,
            "Underline": false
          }
        },
        {
          "Type": "Text",
          "X": 20,
          "Y": 20,
          "Font": "KaiTi",
          "Content": "设\n置\n字\n幕\n阴\n影",
          "Alignment": "BottomRight",
          "FontSize": 40,
          "FontColor": "#ffffff",
          "Shadow": 3,
          "BackColour": "#000000",
          "FontFace": {
            "Bold": false,
            "Italic": true,
            "Underline": false
          }
        }
      ]
    }
  ]
}

设置花字、自定义花字

说明
  1. 使用EffectColorStyleId字段来一键式设置花字,关于花字效果,请参考:花字效果示例

  2. 如果需要自定义字体效果,可以使用SubtitleEffects设置多层描边和阴影效果。有关详细字段说明,请参考SubtitleEffect部分。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaUrl": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h3.mp4",
          "In": 0,
          "Out": 8
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "TimelineIn": 0,
          "TimelineOut": 2,
          "Type": "Text",
          "Y": 0.2,
          "Font": "WenQuanYi Zen Hei Mono",
          "Content": "云端智能剪辑",
          "Alignment": "TopCenter",
          "FontSize": 200,
          "FontColor": "#FFFFFF",
          "SubtitleEffects": [
            {
              "Color": "#0420B6",
              "Type": "Shadow",
              "XBord": 0.07,
              "YBord": 0.07,
              "YShift": 0.06
            },
            {
              "Color": "#F2213F",
              "Type": "Shadow",
              "XBord": 0.07,
              "YBord": 0.07,
              "YShift": 0.03
            },
            {
              "Color": "#000000",
              "Type": "Shadow",
              "XShift": 0.01,
              "YShift": 0.01
            },
            {
              "Color": "#000000",
              "Type": "Outline",
              "XBord": 0.01,
              "YBord": 0.01
            }
          ]
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 2,
          "Type": "Text",
          "Y": 0.6,
          "Content": "高级花字",
          "Alignment": "TopCenter",
          "FontSize": 150,
          "EffectColorStyle": "CS0001-000011"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.1,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0001-000004"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.3,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0001-000005"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.5,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0001-000014"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.7,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0001-000007"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.1,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0002-000002"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.3,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0002-000004"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.5,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0002-000009"
        },
        {
          "TimelineIn": 2,
          "TimelineOut": 5,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.7,
          "Content": "系统花字",
          "FontSize": 150,
          "EffectColorStyle": "CS0002-000016"
        },
        {
          "Comment": "增加左偏移阴影",
          "TimelineIn": 5,
          "TimelineOut": 8,
          "Type": "Text",
          "FontSize": 150,
          "Content": "自定义花字",
          "Y": 0.1,
          "Alignment": "TopCenter",
          "Font": "HappyZcool-2016",
          "FontColor": "#F688AA",
          "SubtitleEffects": [
            {
              "Color": "#F5D2CC",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": -0.04,
              "Opacity": 1
            }
          ]
        },
        {
          "Comment": "增加右偏移阴影",
          "TimelineIn": 5,
          "TimelineOut": 8,
          "Type": "Text",
          "FontSize": 150,
          "Content": "自定义花字",
          "Y": 0.3,
          "Alignment": "TopCenter",
          "Font": "HappyZcool-2016",
          "FontColor": "#F688AA",
          "SubtitleEffects": [
            {
              "Color": "#A33952",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": 0.04,
              "Opacity": 1
            },
            {
              "Color": "#F5D2CC",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": -0.04,
              "Opacity": 1
            }
          ]
        },
        {
          "Comment": "增加第一层发光",
          "TimelineIn": 5,
          "TimelineOut": 8,
          "Type": "Text",
          "FontSize": 150,
          "Content": "自定义花字",
          "Y": 0.5,
          "Alignment": "TopCenter",
          "Font": "HappyZcool-2016",
          "FontColor": "#F688AA",
          "SubtitleEffects": [
            {
              "Color": "#FFFFA0",
              "Type": "Shadow",
              "Blur": 0.08,
              "XBord": 0.08,
              "YBord": 0.08
            },
            {
              "Color": "#A33952",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": 0.04,
              "Opacity": 1
            },
            {
              "Color": "#F5D2CC",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": -0.04,
              "Opacity": 1
            }
          ]
        },
        {
          "Comment": "增加第二层发光",
          "TimelineIn": 5,
          "TimelineOut": 8,
          "Type": "Text",
          "FontSize": 150,
          "Content": "自定义花字",
          "Y": 0.7,
          "Alignment": "TopCenter",
          "Font": "HappyZcool-2016",
          "FontColor": "#F688AA",
          "SubtitleEffects": [
            {
              "Color": "#F688AA",
              "Type": "Shadow",
              "Blur": 0.3,
              "XBord": 0.15,
              "YBord": 0.15
            },
            {
              "Color": "#FFFFA0",
              "Type": "Shadow",
              "Blur": 0.08,
              "XBord": 0.08,
              "YBord": 0.08
            },
            {
              "Color": "#A33952",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": 0.04,
              "Opacity": 1
            },
            {
              "Color": "#F5D2CC",
              "Type": "Shadow",
              "XBord": 0,
              "YBord": 0,
              "XShift": -0.04,
              "Opacity": 1
            }
          ]
        }
      ]
    }
  ]
}

字幕局部效果

说明

通过在Content字段中添加覆写代码,可以实现字幕的局部效果。下面是覆写代码的说明:

  • 所有覆写代码均以两个反斜杠(\\)开头。

  • 所有局部参数覆写代码必须在{}中,且一个{}可以包含多个覆写代码。

  • 覆写代码会作用于其后的字幕上,如果想要结束该覆写代码,需要加一个与之对应的结束覆写代码来取消该效果。

覆写参数详细说明:

覆写参数

描述

Content参数示例

  • \\1c&[BBGGRR]&

  • \\2c&[BBGGRR]&

  • \\3c&[BBGGRR]&

  • 1c、2c、3c分别为字体、边框、阴影对应的颜色。

  • [BBGGRR]表示的是十六进制颜色的BGR值,其颜色顺序与一般的RGB相反。

"这里设置{\\1c&00FF7F&}绿{\\1c}色"

  • \\bord[宽度]

  • \\xbord[宽度]

  • \\ybord[宽度]

bord、xbord、ybord分别表示边框、沿X轴边框和沿Y轴边框的宽度,单位为像素。

"这里设置{\\bord3\\3c&EBCE87&}描边宽度{\\bord\\3c}颜色和大小"

\\b1 \\b0

b1为加粗,b0为取消加粗。

"这里设置{\\b1}加粗{\\b0}效果",

\\i1 \\i0

i1为斜体,i0为取消斜体。

"这里设置{\\i1}斜体{\\i0}效果"

\\u1 \\u0

u1为加下划线,u0为取消下划线。

"这里设置{\\u1}下划线{\\u0}效果"

\\s1 \\s0

s1为添加文本删除线,s0为取消删除线。

"这里设置{\\s1}删除线{\\s0}效果"

\\fs[字体尺寸]

字幕大小,单位为像素。

"这里设置{\\fs100}100号{\\fs}文字"

\\fn[字体名称]

字幕名称,暂不支持设置自定义字体。

"这里设置{\\fnKaiTi}黑体{\\fn}字体"

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4"
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "Type": "Text",
          "X": 0,
          "Y": 150,
          "Font": "FZKai-Z03S",
          "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": 300,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\fs100}100号{\\fs}字体",
          "Alignment": "TopCenter",
          "FontColor": "#F5FFFA",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 450,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\bord3\\3c&CD0000&}描边{\\bord\\3c}颜色和大小",
          "Alignment": "TopCenter",
          "FontSize": 65,
          "FontColor": "#F5FFFA",
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 600,
          "Content": "这里设置{\\bord3\\3c&701919&}不透明背景{\\bord\\3c}颜色和大小",
          "Comment": "不透明背景必须设置 BoderStyle = 3 "
          "Font": "FZKai-Z03S",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Alignment": "TopCenter",
          "FontColor": "#F5FFFA",
          "BorderStyle": 3,
          "Outline": 0,
          "OutlineColour": "#0000CD"
        },
        {
          "Type": "Text",
          "Y": 750,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\fnKaiTi}楷体{\\fn}字体",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "FontColor": "#F5FFFA",
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 900,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\b1}加粗{\\b0}效果",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "FontColor": "#F5FFFA",
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 1050,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\i1}斜体{\\i0}效果",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "FontColor": "#F5FFFA",
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 1200,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\u1}下划线{\\u0}效果",
          "FontColor": "#F5FFFA",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 1350,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\s1}删除线{\\s0}效果",
          "FontColor": "#F5FFFA",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "Y": 1500,
          "Font": "FZKai-Z03S",
          "Content": "这里设置{\\1c&00FF00&\\b1\\fs100\\i1}组合{\\1c\\b0\\fs\\i0}效果",
          "FontColor": "#F5FFFA",
          "FontSize": 65,
          "TimelineIn": 0,
          "TimelineOut": 10,
          "Alignment": "TopCenter",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        }
      ]
    }
  ]
}

字幕自动换行

说明
  1. 设置字幕的"AdaptMode"为"AutoWrap",可以实现在字幕超出画布范围时自动换行,以保证字幕内容完全显示出来。同时可以通过设置TextWidth,支持绝对像素和按照画布百分比来换行,以确保文字在指定宽度范围内进行换行。

  2. 在英文等场景下,只允许在空格位置换行时,可以设置"AdaptMode": "AutoWrapAtSpaces",以确保字幕换行不会出现在英文单词的中间位置。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4"
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "Type": "Text",
          "X": 0,
          "Y": 200,
          "Font": "FZKai-Z03S",
          "Content": "当不设置字幕自动换行时,字幕过长会超出视频画布",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 600,
          "Font": "FZKai-Z03S",
          "Content": "当字幕超出视频画布宽度时触发自动换行",
          "AdaptMode": "AutoWrap",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 1000,
          "Font": "FZKai-Z03S",
          "Content": "设置TextWidth在指定区间内自动换行",
          "TextWidth": 0.7,
          "AdaptMode": "AutoWrap",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 1400,
          "Content": "Subtitles only automatically wrap at spaces.",
          "AdaptMode": "AutoWrapAtSpaces",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100"
        }
      ]
    }
  ]
}

字幕对齐

  • 在不同的字幕对齐方式下,定位方式也会有所不同。在设置Alignment时,对齐方式和默认的定点位置如下:

    Alignment

    对齐方式

    默认位置

    TopLeft

    左对齐

    视频左上角

    TopCenter

    居中对齐

    视频竖直中轴线上侧

    TopRight

    右对齐

    视频右上角

    CenterLeft

    左对齐

    视频水平中轴线左侧

    CenterCenter

    居中对齐

    视频中心位置视频水平中轴线右侧

    CenterRight

    右对齐

    视频水平中轴线右侧

    BottomLeft

    左对齐

    视频左下角

    BottomCenter

    居中对齐

    视频竖直中轴线下侧

    BottomRight

    右对齐

    视频右下角

  • 如果需要进行简单的对齐和定位,可以按照以上方式进行设置。若需要在三种不同对齐方式下依然能够精确定位字幕位置,可以设置Alignment为Left、Center、Right。字幕的定位基准点分别为:

    Alignment

    对齐方式

    定位基准点

    Left

    左对齐

    字幕文本框左上角顶点

    Center

    居中对齐

    字幕文本框上边界中点

    Right

    右对齐

    字幕文本框右上角顶点

  • 不同Alignment时的不同定位基准点如下图所示:

    image

成片效果

Timeline示例

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h3.mp4"
                }
            ]
        }
    ],
    "SubtitleTracks": [
        {
            "SubtitleTrackClips": [
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nTopLeft",
                    "Alignment": "TopLeft",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nTopCenter",
                    "Alignment": "TopCenter",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nTopRight",
                    "Alignment": "TopRight",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nCenterLeft",
                    "Alignment": "CenterLeft",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nCenterCenter",
                    "Alignment": "CenterCenter",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nCenterRight",
                    "Alignment": "CenterRight",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nBottomLeft",
                    "Alignment": "BottomLeft",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nBottomCenter",
                    "Alignment": "BottomCenter",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nBottomRight",
                    "Alignment": "BottomRight",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 0,
                    "TimelineOut": 4
                }
            ]
        },
        {
            "SubtitleTrackClips": [
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nLeft",
                    "X": 100,
                    "Y": 500,
                    "Alignment": "TopLeft",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 4,
                    "TimelineOut": 8
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "Content": "Alignment\nCenter",
                    "X": 950,
                    "Y": 500,
                    "Alignment": "Center",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 4,
                    "TimelineOut": 8
                },
                {
                    "Type": "Text",
                    "Font": "FZKai-Z03S",
                    "X": 1820,
                    "Y": 500,
                    "Content": "Alignment\nRight",
                    "Alignment": "Right",
                    "FontSize": 70,
                    "FontColor": "#F5FFFA",
                    "Outline": 2,
                    "OutlineColour": "#0e0100",
                    "TimelineIn": 4,
                    "TimelineOut": 8
                }
            ]
        }
    ]
}

字幕特效

说明
  1. 出场入场特效可以指定出场和入场时间,而循环特效则可以设置循环速度。

  2. 出场入场特效和循环特效不可同时使用。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4"
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "Type": "Text",
          "X": 0,
          "Y": 200,
          "Font": "HappyZcool-2016",
          "Content": "入场特效,入场时间2s",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100",
          "AaiMotionInEffect": "rotateflip_in",
          "AaiMotionIn": 2
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 600,
          "Font": "HappyZcool-2016",
          "Content": "出场特效,出场时间2s",
          "AdaptMode": "AutoWrap",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100",
          "AaiMotionOutEffect": "slide_down_out",
          "AaiMotionOut": 2
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 1000,
          "Font": "HappyZcool-2016",
          "Content": "循环特效,循环速度2倍速",
          "TextWidth": 0.7,
          "AdaptMode": "AutoWrap",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100",
          "AaiMotionLoopEffect": "rainbrush_display",
          "Ratio": 2
        },
        {
          "Type": "Text",
          "X": 0,
          "Y": 1400,
          "Font": "HappyZcool-2016",
          "Content": "同时叠加出场、入场特效",
          "AdaptMode": "AutoWrapAtSpaces",
          "Alignment": "TopCenter",
          "FontSize": 70,
          "FontColor": "#F5FFFA",
          "Outline": 2,
          "OutlineColour": "#0e0100",
          "AaiMotionInEffect": "zoomin_i",
          "AaiMotionIn": 2,
          "AaiMotionOutEffect": "dissolve_out",
          "AaiMotionOut": 2
        }
      ]
    }
  ]
}

字幕背景

说明

可以利用SubtitleEffects中的Box字段来实现字幕纯色背景效果,同时支持设置花字、换行等样式。

成片效果

Timeline示例

{
    "VideoTracks": [
      {
        "VideoTrackClips": [
          {
            "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4"
          }
        ]
      }
    ],
    "SubtitleTracks": [
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 150,
            "Font": "HappyZcool-2016",
            "Content": "设置字幕纯色背景偏移量宽高\n以及圆角",
            "AdaptMode": "AutoWrap",
            "Alignment": "TopCenter",
            "FontSize": 70,
            "FontColor": "#F5FFFA",
            "SubtitleEffects": [
              {
                "Type": "Box",
                "Color": "1E90FF",
                "XShift": 20,
                "YShift": -20,
                "Bord": 20,
                "Radius": 20
              }
            ]
          }
        ]
      },
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 500,
            "Font": "HappyZcool-2016",
            "Content": "设置字幕背景不透明度",
            "AdaptMode": "AutoWrap",
            "Alignment": "TopCenter",
            "FontSize": 70,
            "FontColor": "#F5FFFA",
            "SubtitleEffects": [
              {
                "Type": "Box",
                "Color": "1E90FF",
                "Opacity": "0.5",
                "Bord": 20
              }
            ]
          }
        ]
      },
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 850,
            "Font": "HappyZcool-2016",
            "Content": "设置字幕换行场景下的字幕纯色背景效果",
            "AdaptMode": "AutoWrap",
            "TextWidth": 0.6,
            "Alignment": "TopCenter",
            "FontSize": 70,
            "FontColor": "#F5FFFA",
            "SubtitleEffects": [
              {
                "Type": "Box",
                "Color": "1E90FF",
                "Bord": 20
              }
            ]
          }
        ]
      },
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 1200,
            "Font": "HappyZcool-2016",
            "Content": "字幕纯色背景同时设置花字、特效",
            "AdaptMode": "AutoWrapAtSpaces",
            "Alignment": "TopCenter",
            "FontSize": 70,
            "EffectColorStyle": "CS0003-000006",
            "AaiMotionInEffect": "zoomin_i",
            "AaiMotionIn": 2,
            "AaiMotionOutEffect": "dissolve_out",
            "AaiMotionOut": 2,
            "SubtitleEffects": [
              {
                "Type": "Box",
                "Color": "1E90FF",
                "Bord": 20
              }
            ]
          }
        ]
      },
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 1550,
            "Font": "HappyZcool-2016",
            "Content": "字幕背景指定贴图纹理\n以及圆角效果",
            "AdaptMode": "AutoWrapAtSpaces",
            "Alignment": "TopCenter",
            "FontSize": 70,
            "EffectColorStyle": "CS0003-000006",
            "AaiMotionInEffect": "zoomin_i",
            "AaiMotionIn": 2,
            "AaiMotionOutEffect": "dissolve_out",
            "AaiMotionOut": 2,
            "SubtitleEffects": [
              {
                "Type": "Box",
                "Color": "1E90FF",
                "Bord": 20,
                "Radius": 20,
                "ImageURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/image/subtitle_background.png"
              }
            ]
          }
        ]
      }
    ]
  }

官方气泡字、自定义气泡字

说明
  1. 可以使用BubbleStyleId一键设置气泡的样式Id,气泡样式请参见:气泡字示例

  2. 在气泡字模式下,支持设置BubbleWidth和BubbleHeight来调整气泡的宽度和高度。此外,X和Y分别表示气泡图片左上角相对于视频左上角的坐标。

  3. 在SubtitleEffects中的Box样式下,支持设置图片来实现自定义气泡字效果。需要传入Width和Height,分别表示气泡原始图片的宽和高,以及TextArea文本框相对于气泡的位置和大小。其中四个字段分别表示字幕文本框左上角坐标相对于气泡的位置,以及字幕文本框相对于气泡的宽高。

  4. 在使用气泡字功能时,文字会在气泡内部自动换行,并自动进行缩放处理。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaUrl": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h3.mp4"
        }
      ]
    }
  ],
  "SubtitleTracks": [
    {
      "SubtitleTrackClips": [
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.1,
          "Y": 0,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0001-000001"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.2,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0001-000002"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.4,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0001-000003"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.6,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0001-000004"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.1,
          "Y": 0.8,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0001-000005"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.6,
          "Y": 0,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0002-000001"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.2,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0002-000002"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.4,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0002-000003"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.6,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0002-000004"
        },
        {
          "TimelineIn": 0,
          "TimelineOut": 4,
          "Type": "Text",
          "X": 0.6,
          "Y": 0.8,
          "FontSize": 150,
          "BubbleHeight": 0.18,
          "Alignment": "TopCenter",
          "BubbleStyleId": "BS0002-000005"
        },
        {
          "TimelineIn": 4,
          "TimelineOut": 8,
          "Type": "Text",
          "Content": "自定义气泡字",
          "FontColor": "#000000",
          "X": 0.1,
          "Y": 0.3,
          "BubbleWidth": 0.8,
          "Alignment": "TopCenter",
          "SubtitleEffects": [
            {
              "Type": "Box",
              "Width": 1050,
              "Height": 250,
              "TextArea": "0.1,0.2,0.8,0.6",
              "ImageURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/image/round_rectangle.png"
            }
          ]
        }
      ]
    }
  ]
}

字幕滚动示例

说明

您可以通过设置ScrollStartY和ScrollEndY来指定字幕滚动的起始和结束位置,同时使用ScrollSpeed参数来控制字幕滚动的速度,单位均为像素。

成片效果

Timeline示例

{
  "VideoTracks": [
    {
      "VideoTrackClips": [
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4",
          "Effects": [
            {
              "Type": "Text",
              "TimelineIn": 0,
              "TimelineOut": 18,
              "Content": "阿里云智能媒体服务IMS是围绕直播和点播场景下的媒体采集、媒资管理、内容生产、制作和分发能力的一站式服务集,提供广播级、全智能、灵活多样的专业能力,并面向复杂业务流场景提供成熟的低代码终端SDK集成方案。\n\n\n\n智能媒体服务特点如下所示:\n\n专业度高:具备广播级、高性能、标准化的服务能力。\n\n灵活性强:不必重复授权即可跑通全链路,提供可视化编排的工作流,高效容错。\n\n智能化:在采集、媒资、生产、处理、播放等场景中体系化的提供AI服务。\n\n多样性:PaaS、PaaS+和SaaS的多重交付形式。",
              "FontSize": 70,
              "FontColorOpacity": 1,
              "Spacing": 0,
              "LineSpacing": 10,
              "AdaptMode": "AutoWrap",
              "X": 0.1,
              "TextWidth": 0.8,
              "EffectColorStyle": "CS0003-000010",
              "ScrollStartY": 1000,
              "ScrollSpeed": 75,
              "ScrollEndY": 192
            }
          ]
        },
        {
          "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/v1.mp4"
        }
      ]
    }
  ]
}

通过设置FECanvas实现相同FontSize在不同分辨率成片下字幕显示大小一致

说明

FontSize代表的是字幕文字高度在成片视频中所占的像素数。在默认情况下,相同FontSize在输出到不同分辨率的视频中时,占比往往是不一致的,比如FontSize:100时,输出到480P的视频字幕占比比较大,输出到720P的视频字幕占比比较小。如果期望使用合成到720P下的字幕FontSize,在合成到480P视频时,字幕占比不变,可以在Timeline中设置FECanvas来实现该效果。

成片效果

Timeline示例

{
    "FECanvas": {
        "Height": 1280,
        "Width": 720
      },
    "VideoTracks": [
      {
        "VideoTrackClips": [
          {
            "MediaURL": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/h2.mp4",
            "Effects": [
              {
                "Type": "Background",
                "SubType": "Blur",
                "Radius": 0.1
              }
            ]
          }
        ]
      }
    ],
    "SubtitleTracks": [
      {
        "SubtitleTrackClips": [
          {
            "Type": "Text",
            "X": 0,
            "Y": 200,
            "Content": "主标题80号字",
            "Alignment": "TopCenter",
            "FontSize": 80,
            "FontColorOpacity": 1,
            "EffectColorStyle": "CS0003-000023",
            "FontFace": {
              "Bold": true
            }
          },
          {
            "Type": "Text",
            "X": 0,
            "Y": 320,
            "Font": "KaiTi",
            "Content": "副标题楷体",
            "Alignment": "TopCenter",
            "FontSize": 45,
            "FontColor": "#ffffff",
            "FontFace": {
              "Italic": true,
              "Underline": true
            }
          },
          {
            "Type": "Text",
            "X": 50,
            "Y": 740,
            "Font": "AlibabaPuHuiTi",
            "Content": "角度旋转",
            "FontColor": "#FFD700",
            "Outline": 4,
            "Angle": 350,
            "OutlineColour": "#000000",
            "FontSize": 60,
            "FontFace": {
              "Bold": true
            }
          },
          {
            "Type": "Text",
            "X": 0,
            "Y": 900,
            "Content": "这里是横幅字幕,使用自定义字体\n设置宽度为1的黑色描边",
            "FontUrl": "https://ice-document-materials.oss-cn-shanghai.aliyuncs.com/test_media/font/fangzhengfangsong.ttf",
            "Outline": 1,
            "OutlineColour": "000000",
            "Alignment": "TopCenter",
            "FontSize": 40,
            "FontColor": "#ffffff",
            "FontFace": {
              "Bold": true,
              "Italic": false,
              "Underline": false
            }
          },
          {
            "Type": "Text",
            "X": 20,
            "Y": 20,
            "Font": "KaiTi",
            "Content": "设\n置\n字\n幕\n阴\n影",
            "Alignment": "BottomRight",
            "FontSize": 40,
            "FontColor": "#ffffff",
            "Shadow": 3,
            "BackColour": "#000000",
            "FontFace": {
              "Bold": false,
              "Italic": true,
              "Underline": false
            }
          }
        ]
      }
    ]
  }