在视频制作中,可以将含有关键信息的视频起始、结尾内容以画中画的形式拼接嵌入到正片视频中,称为开板、尾板。本文为您介绍媒体处理中Node.js SDK设置开板和尾板的示例代码。
示例代码
import Console from '@alicloud/tea-console';
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Env from '@alicloud/darabonba-env';
import Util from '@alicloud/tea-util';
import mts20140618, * as $mts20140618 from '@alicloud/mts20140618';
import * as $tea from '@alicloud/tea-typescript';
/**
* Node.js环境版本为8.x及以上。
* 安装阿里云SDK npm install @alicloud/pop-core --save
* 安装Credentials工具。 npm install @alicloud/credentials
* 安装MPS SDK npm install --save @alicloud/mts20140618
*
*/
/** 管道ID 可在控制台查看 */
var pipelineId = "d7cedd984be7dd63395c*****";
/** 转码模板ID,按需配置 */
var templateId = "S00000001-100020";
var ossLocation = "oss-cn-shanghai";
var bucket = "<bucket name>";
var ossInputObject = "input.mp4";
var ossOutputObject = "merged.mp4";
var headObject = "head.mp4";
var tailObject = "tail.mp4";
export default class Client {
/** 初始化 Client */
static async createClient(accessKeyId: string, accessKeySecret: string, regionId: string): Promise<mts20140618> {
let config = new $OpenApi.Config({ });
config.accessKeyId = accessKeyId;
config.accessKeySecret = accessKeySecret;
/** 接口服务地域 */
config.regionId = "cn-shanghai";
return new mts20140618(config);
}
static async main(args: string[]): Promise<void> {
let client = await Client.createClient(Env.getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env.getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), args[0]);
let request = new $mts20140618.SubmitJobsRequest({
input: inputParam(),
outputs: outputParam(),
outputBucket: bucket,
pipelineId: pipelineId,
outputLocation: ossLocation
});
let response = await client.submitJobs(request);
Console.log(Util.toJSONString($tea.toMap(response)));
}
}
Client.main(process.argv.slice(2));
function inputParam() {
var input:any = {};
input.Location = ossLocation;
input.Bucket = bucket;
input.Object = encodeURIComponent(ossInputObject);
return JSON.stringify(input);
}
function outputParam() {
var outputOSSObject = encodeURIComponent(ossOutputObject);
var output:any = {};
output.OutputObject = outputOSSObject;
output.TemplateId = templateId;
/** video参数 */
var video:any = {};
video.Width = "1280";
video.Height = "720";
output.Video = JSON.stringify(video);
/** 开板视频 */
var openingVideo:any = {};
var openingVideoURL = "http://example-bucket.oss-cn-shanghai.aliyuncs.com/" + encodeURIComponent(headObject)
openingVideo.OpenUrl = openingVideoURL;
openingVideo.Width = "640";
openingVideo.Start = "2";
var openingVideoList = new Array();
openingVideoList.push(openingVideo);
output.OpeningList = JSON.stringify(openingVideoList);
/** 尾板视频 */
var tailSlateVideo:any = {};
var tailSlateVideoURL = "http://example-bucket.oss-cn-shanghai.aliyuncs.com/" + encodeURIComponent(tailObject)
tailSlateVideo.TailUrl = tailSlateVideoURL;
tailSlateVideo.Width = "640";
tailSlateVideo.BlendDuration = "3";
tailSlateVideo.BgColor = "Black";
var tailSlateVideoList = new Array();
tailSlateVideoList.push(tailSlateVideo);
output.TailSlateList = JSON.stringify(tailSlateVideoList);
var outputs = new Array();
outputs.push(output);
return JSON.stringify(outputs);
}
文档内容是否对您有帮助?