通过阅读本文,您可以了解通过服务端SDK调用OpenAPI创建智能媒体服务剪辑合成任务的示例代码。

示例代码

您可以通过阿里云OpenAPI开发者门户在线调试。

import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Credential, { Config } from '@alicloud/credentials';
const Client = require('@alicloud/ice20201109').default;

// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。配置方法请参见:https://help.aliyun.com/document_detail/378664.html

const cred = new Credential();
const iceClient = new Client(new $OpenApi.Config({
  credential: cred,
  endpoint: 'ice.cn-shanghai.aliyuncs.com'
}));

// 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// 通过timeline创建合成任务
iceClient.submitMediaProducingJob({
    Timeline: "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"b4d7cf14dc7b83b0e801cbe****\"}]}]}",
    ProduceTarget: "{\"mediaURL\":\"http://ice-editing.oss-cn-hangzhou.aliyuncs.com/ice/\"}",
    ProjectMetadata: "{\"coverURL\":\"http://test.testvod123.com/media/cover/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\",\"tags\":\"Tag1,Tag2,Test\"}"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 通过模板创建合成任务
iceClient.submitMediaProducingJob({
  TemplateId : "IceSys_VideoMerge",
  ClipsParam : "{\"VideoArray\":[\"s05512043f49f697f7425as****\",\"s2788e810116a45109f2efd****\",\"sd67f44f4964e6c998dee8df****\",]}",
  ProduceTarget : "{\"mediaURL\":\"http://ice-editing.oss-cn-hangzhou.aliyuncs.com/ice/\"}"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 通过project创建合成任务
iceClient.submitMediaProducingJob({
    ProjectId : "****9b4d7cf14dc7b83b0e801cbe****",
    ProduceTarget : "{\"mediaURL\":\"http://ice-editing.oss-cn-hangzhou.aliyuncs.com/ice/\"}",
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 查询剪辑合成作业
iceClient.getMediaProducingJob({
    JobId: "9b4d7cf14dc7b83b0e801cbe****"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

相关接口