This topic describes how to use ApsaraVideo Media Processing (MPS) SDK for Node.js to set the opening and ending scenes during video merging. This topic also provides the complete sample code.

Procedure

  1. Create a client instance.
    var RPCClient = require('@alicloud/pop-core').RPCClient;
    
    var client = initVodClient('<Your AccessKeyId>', '<Your AccessKeySecret>', '<YourRegionId>');
  2. Set parameters.
    • Input
      var input = {};
      input.Location= ossLocation;
      input.Bucket= ossBucket;
      input.Object=encodeURIComponent(headObject);
    • Output
      var outputOSSObject=encodeURIComponent(ossOutputObject);;
      var output = {};
      output.OutputObject= outputOSSObject;
      output.TemplateId= templateId;
    • Video
      var video = {};
      video.Width= "1280";
      video.Height= "720");
      output.Video=JSON.stringify(video);
    • OpeningList
      var openingVideo = {};
      var httpStri="http://";
      var dot='.';
      var openingVideoURL=httpStri.concat(ossBucket, dot,ossLocation, dot, '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);
    • TailSlateList
      var tailSlateVideo = {};
      var httpStri="http://";
      var dot='.';
      var tailSlateVideoURL=httpStri.concat(ossBucket, dot, ossLocation, dot, '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);
  3. Initiate a request and obtain the response.
    var client=client.request('SubmitJobs', {
        Input: JSON.stringify(input),
        Outputs: JSON.stringtify(outputs),
        OutputBucket: ossBucket,
        PipelineId: pipelineId,
        OutputLocation: ossLocation
        }, {}).then(function (response) {
          console.log('response success: = ' + response.JobResultList.JobResult[0].Success);
          console.log('response jobID: ' + response.JobResultList.JobResult[0].Job.JobId);
      }).catch(function (response) {
        console.log(JSON.stringify(response));
    });
Sample code
var accessKeyId = "xxx";
var accessKeySecret = "xxx";
var mpsRegionId = "xxx";
var pipelineId = "xxx";
var templateId = "S00000001-200030";
var ossLocation = "xxx";
var ossBucket = "xxx";
var ossInputObject = "xxx.mp4";
var ossOutputObject = "xxx.mp4";
var headObject = "head.mp4";
var tailObject = "tail.mp4";
var httpStri = "http://";
var dot = '.';

var RPCClient = require('@alicloud/pop-core').RPCClient;

function initMtsClient(accessKeyId, accessKeySecret, regionId) {
    var client = new RPCClient({
        accessKeyId: accessKeyId,
        accessKeySecret: accessKeySecret,
        endpoint: 'http://mts.' + regionId + '.aliyuncs.com',
        apiVersion: '2014-06-18'
    });
    return client;
};

var client = initMtsClient(accessKeyId, accessKeySecret, mpsRegionId);
var input = {};
input.Location = ossLocation;
input.Bucket = ossBucket;
input.Object = encodeURIComponent(ossInputObject);

var outputOSSObject = encodeURIComponent(ossOutputObject);
var output = {};
output.OutputObject = outputOSSObject;
output.TemplateId = templateId;
// Output->OpeningList

var openingVideo = {};
var openingVideoURL = httpStri.concat(ossBucket, dot, ossLocation, dot, '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);

// Output->TailSlateList
var tailSlateVideo = {};
var tailSlateVideoURL = httpStri.concat(ossBucket, dot, ossLocation, dot, '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);

// Outputs
var outputs = new Array();
outputs.push(output);

var client = client.request('SubmitJobs', {
    Input: JSON.stringify(input),
    Outputs: JSON.stringify(outputs),
    OutputBucket: ossBucket,
    PipelineId: pipelineId,
    OutputLocation: ossLocation
}, {}).then(function (response) {
    console.log('response success: = ' + response.JobResultList.JobResult[0].Success);
    console.log('response jobID: ' + response.JobResultList.JobResult[0].Job.JobId);
    console.log(JSON.stringify(response));
}).catch(function (response) {
    console.log(JSON.stringify(response));
});