All Products
Search
Document Center

Transcoding template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Add a transcoding template group

For more information about the request and response parameters, see AddTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

var transcodeTemplateList = [
    {
        // Specifies the video stream transcoding configuration.
        Video: {
            Width: 640,
            Bitrate: 400,
            Fps: 25,
            Remove: false,
            Codec: 'H. 264',
            Gop: '250'
        },
        // Specifies the audio stream transcoding configuration.
        Audio: {
            Codec: 'AAC',
            Bitrate: '64',
            Channels: '2',
            Samplerate: '32000'
        },
        // Specifies the encapsulation container.
        Container: {
            Format: 'mp4'
        },
        // Specifies the conditional transcoding configuration.
        TransConfig: {
            IsCheckReso: false,
            IsCheckResoFail: false,
            IsCheckVideoBitrate: false,
            IsCheckVideoBitrateFail: false,
            IsCheckAudioBitrate: false,
            IsCheckAudioBitrateFail: false
        },
        // // Specifies the encryption configuration, which supports only the M3U8 format.
        // EncryptSetting: {
        //     EncryptType: 'Private'
        // },
        // Sets the definition.
        Definition: 'LD',
        // Sets the template name.
        TemplateName: 'testtemplate',
        // Associates watermark IDs with transcoding template IDs.
        WatermarkIds: ['USER_DEFAULT_WATERMARK','xxxxxxbdc1ff65782f8995c6ddxxxxxx']
    }
];
client.request("AddTranscodeTemplateGroup", {
    // Sets the name of the transcoding template group.
    Name: 'grouptest',
    // Specifies the transcoding template configuration.
    TranscodeTemplateList: JSON.stringify(transcodeTemplateList)
}, {}).then(function (response) {
    console.log('TranscodeTemplateGroupId = ' + response.TranscodeTemplateGroupId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Modify a transcoding template group

For more information about the request and response parameters, see UpdateTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

var transcodeTemplateList = [
    {
        // Sets the transcoding template ID.
        TranscodeTemplateId: 'xxxxxx4423bca267f931d3b256xxxxxx',
        // Specifies the video stream transcoding configuration.
        Video: {
            Width: 640,
            Bitrate: 500,
            Fps: 25,
            Remove: false,
            Codec: 'H. 264',
            Gop: '250'
        },
        // Specifies the audio stream transcoding configuration.
        Audio: {
            Codec: 'AAC',
            Bitrate: '64',
            Channels: '2',
            Samplerate: '32000'
        },
        // Specifies the encapsulation container.
        Container: {
            Format: 'mp4'
        },
        // Specifies the conditional transcoding configuration.
        TransConfig: {
            IsCheckReso: false,
            IsCheckResoFail: false,
            IsCheckVideoBitrate: false,
            IsCheckVideoBitrateFail: false,
            IsCheckAudioBitrate: false,
            IsCheckAudioBitrateFail: false
        },
        // // Specifies the encryption configuration, which supports only the M3U8 format.
        // EncryptSetting: {
        //     EncryptType: 'Private' 
        // },
        // Sets the definition.
        Definition: 'LD',
        // Sets the template name.
        TemplateName: 'testtemplate',
        // Associates watermark IDs with transcoding template IDs.
        WatermarkIds: ['USER_DEFAULT_WATERMARK','xxxxxxbdc1ff65782f8995c6ddxxxxxx']
    }
];
client.request("UpdateTranscodeTemplateGroup", {
    TranscodeTemplateGroupId: 'xxxxxx42788dfd94e27d7358b2xxxxxx',
    TranscodeTemplateList: JSON.stringify(transcodeTemplateList)
}, {}).then(function (response) {
    console.log('TranscodeTemplateGroupId = ' + response.TranscodeTemplateGroupId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query a list of transcoding template groups

For more information about the request and response parameters, see ListTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("ListTranscodeTemplateGroup", {}, {}).then(function (response) {
    if (response.TranscodeTemplateGroupList && response.TranscodeTemplateGroupList.length > 0){ 
        for (var i=0; i<response.TranscodeTemplateGroupList.length; i++){
            var transcodeTemplateGroup = response.TranscodeTemplateGroupList[i];
            console.log('The ' + i + ' TranscodeTemplateGroup.') ;
            // The ID of the transcoding template group.
            console.log('TranscodeTemplateGroupId = ' + transcodeTemplateGroup.TranscodeTemplateGroupId);
            // The name of the transcoding template group.
            console.log('Name = ' + transcodeTemplateGroup.Name);
            // The creation time of the transcoding template group.
            console.log('CreationTime = ' + transcodeTemplateGroup.CreationTime);
            // The last modification time of the transcoding template group.
            console.log('ModifyTime = ' + transcodeTemplateGroup.ModifyTime);
            // Indicates whether the transcoding template group is the default transcoding template group.
            console.log('IsDefault = ' + transcodeTemplateGroup.IsDefault);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query a transcoding template group

For more information about the request and response parameters, see GetTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("GetTranscodeTemplateGroup", {
    TranscodeTemplateGroupId: 'xxxxxx42788dfd94e27d7358b2xxxxxx'
}, {}).then(function (response) {
    console.log(response);
    if (response.TranscodeTemplateGroup){
        // The ID of the transcoding template group.
        console.log('TranscodeTemplateGroupId = ' + response.TranscodeTemplateGroup.TranscodeTemplateGroupId);
        // The name of the transcoding template group.
        console.log('Name = ' + response.TranscodeTemplateGroup.Name);
        // The creation time of the transcoding template group.
        console.log('CreationTime = ' + response.TranscodeTemplateGroup.CreationTime);
        // The last modification time of the transcoding template group.
        console.log('ModifyTime = ' + response.TranscodeTemplateGroup.ModifyTime);
        // The transcoding template information.
        if (response.TranscodeTemplateGroup.TranscodeTemplateList && response.TranscodeTemplateGroup.TranscodeTemplateList.length > 0){ 
            for (var i=0; i<response.TranscodeTemplateGroup.TranscodeTemplateList.length; i++){ 
                var transcodeTemplate = response.TranscodeTemplateGroup.TranscodeTemplateList[i];
                console.log("The " + i + " TranscodeTemplate.") ;
                // The transcoding template ID.
                console.log('TranscodeTemplateId = ' + transcodeTemplate.TranscodeTemplateId);
                // The transcoding template name.
                console.log('TemplateName = ' + transcodeTemplate.TemplateName);
                // The definition.
                console.log('Definition = ' + transcodeTemplate.Definition);
                // The encapsulation container.
                console.log('Container = ');
                console.log(transcodeTemplate.Container);
                // The video stream transcoding configuration.
                console.log('Video = ');
                console.log(transcodeTemplate.Video);
                // The audio stream transcoding configuration.
                console.log('Audio = ');
                console.log(transcodeTemplate.Audio);
                // The conditional transcoding configuration.
                console.log('TransConfig = ');
                console.log(transcodeTemplate.TransConfig);
                // The associated watermark IDs.
                console.log('WatermarkIds = ');
                console.log(transcodeTemplate.WatermarkIds);
            }
        }
    }

    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Set the default transcoding template group

For more information about the request and response parameters, see SetDefaultTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("SetDefaultTranscodeTemplateGroup", {
    // Sets the ID of the transcoding template group.
    TranscodeTemplateGroupId: 'xxxxxx42788dfd94e27d7358b2xxxxxx'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Delete a transcoding template group

For more information about the request and response parameters, see DeleteTranscodeTemplateGroup.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DeleteTranscodeTemplateGroup", {
    TranscodeTemplateGroupId: 'xxxxxx42788dfd94e27d7358b2xxxxxx'
}, {}).then(function (response) {
    console.log(response);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});