Alibaba cloud video transcoding batch submission (mp4 to m3u8)

There are hundreds of videos in oss that need to be transferred to m3u8. It is found that the interface does not have the function of batch submission. So we want to find out the form parameters and submit them with js.

The following content is only valid for Alibaba cloud background around 2020-02-11.

1. Form interface

2. Submit parameters

3. Reference code

After calling sendData('directory / video. mp4 ')

Output: "directory / video / video. m3u8“

The following code cannot be used directly. The parameters in the code: Bucket, OutputBucket, PipelineId, Location, OutputLocation, TemplateId, need to be replaced with their own.

function sendData(str){
	
	var input_file_name = str.substr(str.lastIndexOf('/') + 1).replace('.mp4','');
	var input_file = str;
	var output_file = str.substr(0,str.lastIndexOf('/') + 1) + input_file_name + "/" + input_file_name;

    function encodeCHURI(p){
        // encodeURIComponent
        return encodeURI(encodeURI(p));
    }

    var pObj = {
        Input:{ Bucket:"hzwh-video",Object:encodeCHURI(input_file),Location:"oss-cn-hangzhou"}, PipelineId:"1329180cda9f4931a73b94653afecda4",
        OutputBucket:"hzwh-video",
        OutputLocation:"oss-cn-hangzhou",
        Outputs:[
            {OutputObject:encodeCHURI(output_file),TemplateId:"S00000001-100020",Container:{Format:"m3u8"}}]
        }

     params_str = JSON.stringify(pObj);

	let formData = new FormData();
    formData.append("action",'SubmitJobs');
    formData.append("params",params_str);
    formData.append("product",'mts');
    formData.append("region",'cn-hangzhou');
    formData.append("umid",window.RISK_INFO.UMID);
    formData.append("collina",RISK_INFO.GETUA());
    formData.append("sec_token",ALIYUN_CONSOLE_CONFIG.SEC_TOKEN);

    var str = '';
    formData.forEach(function(v,k){
        str += k + '=' + v ;
        str += '&';
    });

    console.log(str);

	fetch('https://mps.console.aliyun.com/data/api.json?action=SubmitJobs&t='+new Date().getTime(), {
	  method: 'POST',
	  // credentials: 'include',
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      }, 
	  body: str
	}).then(function(response) {
	  console.log(response);
	});

}

Tags: JSON

Posted on Tue, 11 Feb 2020 10:16:45 -0500 by tzuriel