Os snapshots de vídeo capturam quadros com tamanho específico em momentos determinados para uso como miniaturas, sprites de imagem ou pré-visualizações na barra de progresso. Envie jobs de snapshot no console do ApsaraVideo Media Processing (MPS), pela API ou por SDKs. Este exemplo usa o MPS SDK for Node.js V2.0 para enviar um job de snapshot com tempo de captura, intervalo, quantidade, tipo e composição de sprites configuráveis.
Código de exemplo
'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 {
/**
* Use your AccessKey ID and AccessKey secret to initialize a client.
* @return Client
* @throws Exception
*/
static createClient() {
let config = new OpenApi.Config({
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
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({
// The job input.
input: '{"Bucket":"example-bucket","Location":"example-location","Object":"example%2Ftest.flv"}',
// The configuration of the snapshot job.
snapshotConfig: '{"OutputFile":{"Bucket":"example-001","Location":"example-location","Object":"{Count}.jpg"},"Time":"5","Num":"10","Interval":"20"}',
// The user-defined data.
userData: 'testid-001',
// The ID of the MPS queue.
pipelineId: 'dd3dae411e704030b921e52698e5****',
});
let runtime = new Util.RuntimeOptions({ });
try {
// Write your own code to display the response of the API operation if necessary.
await client.submitSnapshotJobWithOptions(submitSnapshotJobRequest, runtime);
} catch (error) {
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
console.log(error.message);
// The URL of the corresponding error diagnostics page.
console.log(error.data["Recommend"]);
Util.default.assertAsString(error.message);
}
}
}
exports.Client = Client;
Client.main(process.argv.slice(2));