越来越多的产品选择使用短视频作为内容承载,通过对媒体素材进行简单的剪辑,即可进行使用和投放,本文基于智能媒体服务IMS,介绍短视频剪辑中的常用功能,通过对不同功能的组合,方便客户组装自己的剪辑场景,进行短视频批量合成。
1. 概述
1.1 背景
进入5G时代,越来越多的产品选择使用短视频作为内容承载,通过一定的策略把图文视频素材生产出短视频,投放在短视频平台,或者在自有产品中展示。
本文基于智能媒体服务IMS,用户通过组装Timeline,即可对云端的音视频素材进行剪辑。本文主要介绍短视频生产中的常用功能及实现,通过对基础功能的组装,客户可以很方便的定制自己的生产策略。
1.2 目标读者
有短视频批量制作的商家,或视频批量生产工具的开发者。
1.3 方案介绍
视频剪辑常见的功能有:多轨合成、特效转场、字幕制作、音频处理等等,通过不同功能的组合,业务方能组装成多种Timeline模板。当有新素材时,套用不同的Timeline模板,便能生产出多种多样的视频内容。
1.4 方案优势
云端剪辑
不同于市面上的C端工具,IMS可以直接剪辑云端的音视频文件,成片输出到云端。用户调用API即可进行剪辑,免去了安装工具的麻烦,且与用户的本机性能无关。
参数简单、跨平台
IMS的Timeline结构符合大众对剪辑工程的理解,JSON格式,开发同学简单易上手,IMS还对很多场景做了Timeline简化,用户不用拼完整的Timeline参数,由IMS进行补全,大大降低了开发成本。用户组装好Timeline后,提交一次请求即可合成出成片,代码示例:
String timeline = "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaURL\":" +
"\"http://your-bucket.oss-cn-shanghai.aliyuncs.com/your-video.mp4\",\"Out\":10}]}]}";
String outputMediaConfig = "{\"MediaURL\":\"https://your-bucket.oss-cn-shanghai.aliyuncs.com/your-output.mp4\"" +
",\"Width\":1280,\"Height\":720}";
SubmitMediaProducingJobRequest request = new SubmitMediaProducingJobRequest();
request.setTimeline(timeline);
request.setOutputMediaConfig(outputMediaConfig);
iceClient.submitMediaProducingJob(request);
2. 方案实施
2.1 前提条件
开通IMS服务。
开通OSS服务或VOD服务,用于存储素材和成片。
2.2 接口说明
输入Timeline和成片地址,提交剪辑合成作业,返回剪辑作业JobId。
根据JobId获取剪辑合成作业信息,检查任务状态。
2.3 常用功能及时间线示例
视频横转竖-补充上下黑边
时间线中的素材为横屏视频,在提交合成任务时设置成片视频为竖屏尺寸,IMS即可根据素材和成片的尺寸,将素材居中展示,上下补充黑边。设置成片视频尺寸参考OutputMediaConfig 参数示例。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video1.mp4"
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video2.mp4"
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4"
}]
}]
}
视频横转竖-补充上下模糊去区域
和补充上下黑边一样,背景模糊也是视频横屏转竖屏的常见手法,按照下面Timeline补充Blur特效,IMS即可根据素材和成片的尺寸,将素材居中展示,不足部分补充模糊效果。设置成片视频尺寸参考OutputMediaConfig 参数示例。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video1.mp4",
"Effects": [{
"Type": "Background",
"SubType": "Blur",
"Radius": 0.1
}]
}, {
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video2.mp4",
"Effects": [{
"Type": "Background",
"SubType": "Blur",
"Radius": 0.1
}]
}, {
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4",
"Effects": [{
"Type": "Background",
"SubType": "Blur",
"Radius": 0.1
}]
}]
}]
}
添加字幕
字幕一般添加在SubtitleTrack中,可自由设置字幕的字号、字体、坐标、出入场时间等属性。
当出入场时间未设置时,默认字幕从第0秒展示到视频结束,可用来设置全局字幕效果。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video1.mp4"
}, {
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video2.mp4"
}, {
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4"
}]
}],
"SubtitleTracks": [{
"SubtitleTrackClips": [{
"Type": "Text",
"X": 0,
"Y": 200,
"Font": "AlibabaPuHuiTi",
"Content": "这里是标题",
"Alignment": "TopCenter",
"FontSize": 80,
"FontColorOpacity": 1,
"FontColor": "#ffffff",
"FontFace": {
"Bold": true,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"X": 0,
"Y": 320,
"Font": "KaiTi",
"Content": "这里是副标题",
"Alignment": "TopCenter",
"FontSize": 45,
"FontColor": "#ffffff",
"FontFace": {
"Bold": false,
"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,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"X": 0,
"Y": 900,
"Font": "AlibabaPuHuiTi",
"Content": "这里是横幅字幕\n可以加换行符进行多行展示",
"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
}
}
]
}]
}
字幕描边、阴影、花字、字幕动画、自定义字体
字幕除了基础属性外,字幕特效也是常见需求,IMS也对字幕做了很多特效方面的优化。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video4.mp4"
}]
}],
"SubtitleTracks":[
{
"SubtitleTrackClips":[
{
"Type":"Text",
"X": 0,
"Y": 210,
"Font": "WenQuanYi Zen Hei Mono",
"Content": "这里是副标题",
"Alignment": "TopCenter",
"FontSize": 50,
"FontColor": "#000000",
"TimelineIn": 0,
"TimelineOut": 10,
"BorderStyle": 3,
"OutlineColour": "#ffffff",
"Outline": 2,
"FontFace": {
"Bold": false,
"Italic": false,
"Underline": false
}
},
{
"Type":"Text",
"X": 0,
"Y": 270,
"Font": "WenQuanYi Zen Hei Mono",
"Content": "这里是标题",
"Alignment": "TopCenter",
"OutlineColour": "#000000",
"Outline": 3,
"FontSize": 70,
"TimelineIn": 0,
"TimelineOut": 10,
"FontColor": "#ffffff",
"FontFace": {
"Bold": true,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"Y": 750,
"Font": "AlibabaPuHuiTi",
"Content": "这里是大标题",
"Alignment": "TopCenter",
"FontSize": 100,
"FontColor": "#FFD700",
"Outline": 4,
"OutlineColour": "#000000",
"TimelineIn": 0,
"TimelineOut": 10,
"FontFace": {
"Bold": true,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"Y": 850,
"Content": "自定义字体文件",
"Font": "KaiTi",
"FontSize": 42,
"Outline": 2,
"OutlineColour": "#ee00ff",
"FontUrl":"https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_font.ttf",
"TimelineIn": 0,
"TimelineOut": 10,
"Alignment": "TopCenter",
"FontColor": "#000000",
"FontFace": {
"Bold": false,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"Y": 900,
"Font": "WenQuanYi Zen Hei Mono",
"Content": "阴影效果",
"FontColor": "#ffffff",
"FontSize": 40,
"Outline": 2,
"OutlineColour": "#DB7093",
"Shadow": 3,
"BackColour": "#FFF0F5",
"TimelineIn": 0,
"TimelineOut": 10,
"Alignment": "TopCenter",
"FontFace": {
"Bold": false,
"Italic": false,
"Underline": false
}
},
{
"Type": "Text",
"Y": 980,
"Font": "WenQuanYi Zen Hei Mono",
"Content": "添加字幕动画",
"FontColor": "#ffffff",
"FontSize": 50,
"TimelineIn": 0,
"TimelineOut": 10,
"Alignment": "TopCenter",
"AaiMotionLoopEffect": "rollleft_display",
"FontFace": {
"Bold": true,
"Italic": false,
"Underline": false
}
}
]
}
]
}
添加Gif贴纸
DyncFrames为动图的帧率,需要设置。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video1.mp4"
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video2.mp4"
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4"
}]
},{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_sticker1.gif",
"Type": "image",
"Duration": 10,
"TimelineIn": 0,
"DyncFrames": 10,
"X": 50,
"Y": 1300,
"Effects": [{
"Type": "Scale",
"Width": 200,
"Height": 200
}]
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_sticker2.gif",
"Type": "image",
"Duration": 10,
"TimelineIn": 10,
"DyncFrames": 10,
"X": 800,
"Y": 400,
"Effects": [{
"Type": "Scale",
"Width": 200,
"Height": 200
}]
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_sticker3.gif",
"Type": "image",
"Duration": 10,
"TimelineIn": 20,
"DyncFrames": 10,
"X": 100,
"Y": 400,
"Effects": [{
"Type": "Scale",
"Width": 200,
"Height": 200
}]
}]
}]
}
特效、滤镜、转场
特效和滤镜可以加到VideoClip的Effects中,也可以加到EffectTrack中。
当需要为整个成片添加滤镜、特效时,可以在EffectTrack中添加一个特效,无需设置TimelineIn、TimelineOut,合成时会将特效从第0秒渲染至视频结束,方便配置一些全局特效。
转场会占用前后两个视频的时间,对成片时长会有影响,如:两个10s的视频拼接,中间加2s的转场,成片时长为 10 + 10 - 2 = 18s。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video1.mp4"
"Effects": [{
"Type": "Transition",
"SubType": "windowslice"
}]
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video2.mp4"
"Effects": [{
"Type": "Transition",
"SubType": "polka"
}]
},{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4"
}]
}],
"EffectTracks":[{
"EffectTrackItems": [{
"Type":"VFX",
"SubType":"starry"
}]
}]
}
文字转语音
添加音频片段,设置Type为AI_TTS,Content为要转化的文字,即可进行文字转语音,并合成到视频中。
可以设置Voice、SpeechRate、PitchRate、Format等,参数详见音频轨素材直接由文字转化生成。
可与AI_ASR共用,将生成的语音转换为字幕,合成到视频中,字幕同样可以设置字体样式、花字等属性,一般对于语音转换后的字幕,都会设置为居中对齐,Alignment为对齐属性。
效果:
时间线:
{
"VideoTracks": [{
"VideoTrackClips": [{
"MediaURL": "https://your-bucket.oss-cn-shanghai.aliyuncs.com/your_video3.mp4",
"Effects": [{
"Type":"Volume",
"Gain":0
}]
}]
}],
"AudioTracks": [{
"AudioTrackClips": [{
"Type": "AI_TTS",
"Content": "君不见黄河之水天上来,奔流到海不复回。君不见高堂明镜悲白发,朝如青丝暮成雪。",
"Voice": "zhichu",
"Effects": [{
"Type": "AI_ASR",
"Font": "AlibabaPuHuiTi",
"Alignment": "TopCenter",
"Y": 900,
"FontSize": 80,
"FontColor": "#ffffff",
"FontFace": {
"Bold": true,
"Italic": false,
"Underline": false
}
},{
"Type":"Volume",
"Gain":10
}]
}]
}]
}
2.4 成片示例
基于以上基础功能,客户可以组装出自己的剪辑策略,以下为基础功能组装的效果。
美食短视频
代码示例见 短视频批量混剪-字幕对齐
萌宠短视频
示例中一个分片固定2s,如需做卡点相册效果,可参考 批量混剪-卡点视频
欢迎访问官方文档查看更多示例:
欢迎加入智能媒体生产ICE官方答疑群咨询交流。