文档

截图

更新时间:

视频截图是指对视频截取指定时间、指定尺寸的图片,用于生产视频封面、雪碧图、播放器进度条缩略图等场景,截图作业支持指定时间点、时间间隔、截图数量、类型以及是否拼图等。您可以通过媒体处理控制台、API或SDK提交截图作业。本文提供了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*****"; 
var ossLocation = "oss-cn-shanghai";
var bucket = "<bucket name>";
var ossInputObject = "input.mp4";
var ossOutputObject = "output_{Count}.jpg";



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.SubmitSnapshotJobRequest({
        input: inputParam(),
        outputBucket: bucket,
        pipelineId: pipelineId,
        outputLocation: ossLocation,
        snapshotConfig: snapshotConfig()
    });
    let response = await client.submitSnapshotJob(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 snapshotConfig(){
    var snapshotConfig:any = {};
    var output:any = {};
    output.Location = ossLocation;
    output.Bucket = bucket;
    output.Object = encodeURIComponent(ossOutputObject);
    snapshotConfig.OutputFile = JSON.stringify(output);
    snapshotConfig.Time = "2";
    snapshotConfig.Interval = "2";
    snapshotConfig.Num = "3";
    snapshotConfig.Height = "360"; 
  	//return JSON.stringify(snapshotConfig);
}

相关文档

  • 本页导读 (1)
文档反馈