视频截图是指对视频截取指定时间、指定尺寸的图片,用于生产视频封面、雪碧图、播放器进度条缩略图等场景,截图作业支持指定时间点、时间间隔、截图数量、类型以及是否拼图等。您可以通过媒体处理控制台、API或SDK提交截图作业。本文提供了Node.js SDK V2.0设置截图的完整代码示例。
完整代码
'use strict';
const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');
class Client {
/**
* 使用AK&SK初始化账号Client
* @return Client
* @throws Exception
*/
static createClient() {
let config = new OpenApi.Config({
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
});
config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
return new Mts20140618.default(config);
}
static async main(args) {
let client = Client.createClient();
let submitSnapshotJobRequest = new Mts20140618.SubmitSnapshotJobRequest({
//作业输入
input: '{"Bucket":"example-bucket","Location":"example-location","Object":"example%2Ftest.flv"}',
//截图配置
snapshotConfig: '{"OutputFile":{"Bucket":"example-001","Location":"example-location","Object":"{Count}.jpg"},"Time":"5","Num":"10","Interval":"20"}',
//用户自定义数据
userData: 'testid-001',
//管道ID
pipelineId: 'dd3dae411e704030b921e52698e5****',
});
let runtime = new Util.RuntimeOptions({ });
try {
// 复制代码运行请自行打印 API 的返回值
await client.submitSnapshotJobWithOptions(submitSnapshotJobRequest, runtime);
} catch (error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
console.log(error.message);
// 诊断地址
console.log(error.data["Recommend"]);
Util.default.assertAsString(error.message);
}
}
}
exports.Client = Client;
Client.main(process.argv.slice(2));