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.

import com.aliyuncs.vod.model.v20170321.AddTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.AddTranscodeTemplateGroupResponse;

/**
 * Method for adding a transcoding template group
 */
public static AddTranscodeTemplateGroupResponse addTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
    // Sets the name of the transcoding template group.
    request.setName("grouptest");
    request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
    return client.getAcsResponse(request);
}

/**
 * Method for constructing the transcoding template configuration
 *
 * @return
 */
public static JSONArray buildTranscodeTemplateList() {
    JSONObject transcodeTemplate = new JSONObject();
    // Sets the template name.
    transcodeTemplate.put("TemplateName", "testtemplate");

    // Sets the definition.
    transcodeTemplate.put("Definition", "LD");

    // Specifies the video stream transcoding configuration.
    JSONObject video = new JSONObject();
    video.put("Width", 640);
    video.put("Bitrate", 400);
    video.put("Fps", 25);
    video.put("Remove", false);
    video.put("Codec", "H. 264");
    video.put("Gop", "250");
    transcodeTemplate.put("Video", video);

    // Specifies the audio stream transcoding configuration.
    JSONObject audio = new JSONObject();
    audio.put("Codec", "AAC");
    audio.put("Bitrate", "64");
    audio.put("Channels", "2");
    audio.put("Samplerate", "32000");
    transcodeTemplate.put("Audio", audio);

    // Specifies the encapsulation container.
    JSONObject container = new JSONObject();
    container.put("Format", "mp4");
    transcodeTemplate.put("Container", container);

    // Specifies the conditional transcoding configuration.
    JSONObject transconfig = new JSONObject();
    transconfig.put("IsCheckReso", false);
    transconfig.put("IsCheckResoFail", false);
    transconfig.put("IsCheckVideoBitrate", false);
    transconfig.put("IsCheckVideoBitrateFail", false);
    transconfig.put("IsCheckAudioBitrate", false);
    transconfig.put("IsCheckAudioBitrateFail", false);
    transcodeTemplate.put("TransConfig", transconfig);

    // Specifies the encryption configuration, which supports only the M3U8 format.
    //JSONObject encryptSetting = new JSONObject();
    //encryptSetting.put("EncryptType", "Private");
    //transcodeTemplate.put("EncryptSetting", encryptSetting);

    // Associates watermark IDs with transcoding template IDs.
    JSONArray watermarkIdList = new JSONArray();
    watermarkIdList.add("263261bdc1ff65782f8995c6dd22a16a");
    // USER_DEFAULT_WATERMARK indicates the default watermark ID.
    watermarkIdList.add("USER_DEFAULT_WATERMARK");
    transcodeTemplate.put("WatermarkIds", watermarkIdList);

    JSONArray transcodeTemplateList = new JSONArray();
    transcodeTemplateList.add(transcodeTemplate);
    return transcodeTemplateList;
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    AddTranscodeTemplateGroupResponse response = new AddTranscodeTemplateGroupResponse();
    try {
        response = addTranscodeTemplateGroup(client);
        System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupId());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Modify a transcoding template group

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

import com.aliyuncs.vod.model.v20170321.UpdateTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.UpdateTranscodeTemplateGroupResponse;

/**
 * Method for modifying a transcoding template group
 */
public static UpdateTranscodeTemplateGroupResponse updateTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
    request.setName("grouptest1");
    // Sets the ID of the transcoding template group.
    request.setTranscodeTemplateGroupId("4c71a339fecec0152b4fa6f4527b89");
    request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
    return client.getAcsResponse(request);
}

/**
 * Method for constructing the transcoding template configuration
 *
 * @return
 */
public static JSONArray buildTranscodeTemplateList() {
    JSONObject transcodeTemplate = new JSONObject();
    // Sets the transcoding template ID.
    transcodeTemplate.put("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56242f");

     // Sets the template name.
    transcodeTemplate.put("TemplateName", "testtemplate");

    // Specifies the video stream transcoding configuration.
    JSONObject video = new JSONObject();
    video.put("Width", 960);
    video.put("Bitrate", 900);
    video.put("Fps", 25);
    video.put("Remove", false);
    video.put("Codec", "H. 264");
    video.put("Gop", "250");
    transcodeTemplate.put("Video", video);

    // Specifies the audio stream transcoding configuration.
    JSONObject audio = new JSONObject();
    audio.put("Codec", "AAC");
    audio.put("Bitrate", "96");
    audio.put("Channels", "2");
    audio.put("Samplerate", "32000");
    transcodeTemplate.put("Audio", audio);

    // Specifies the encapsulation container.
    JSONObject container = new JSONObject();
    container.put("Format", "mp4");
    transcodeTemplate.put("Container", container);

    // Specifies the conditional transcoding configuration.
    JSONObject transconfig = new JSONObject();
    transconfig.put("IsCheckReso", false);
    transconfig.put("IsCheckResoFail", false);
    transconfig.put("IsCheckVideoBitrate", false);
    transconfig.put("IsCheckVideoBitrateFail", false);
    transconfig.put("IsCheckAudioBitrate", false);
    transconfig.put("IsCheckAudioBitrateFail", false);
    transcodeTemplate.put("TransConfig", transconfig);

    // Specifies the encryption configuration, which supports only the M3U8 format.
    JSONObject encryptSetting = new JSONObject();
    encryptSetting.put("EncryptType", "Private");

    // Associates watermark IDs with transcoding template IDs.
    JSONArray watermarkIdList = new JSONArray();
    watermarkIdList.add("263261bdc1ff65782f95c6dd22a16a");
    // USER_DEFAULT_WATERMARK indicates the default watermark ID.
    watermarkIdList.add("USER_DEFAULT_WATERMARK");
    transcodeTemplate.put("WatermarkIds", watermarkIdList);

    JSONArray transcodeTemplateList = new JSONArray();
    transcodeTemplateList.add(transcodeTemplate);
    return transcodeTemplateList;
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    UpdateTranscodeTemplateGroupResponse response = new UpdateTranscodeTemplateGroupResponse();
    try {
        response = updateTranscodeTemplateGroup(client);
        System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupId());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Query a list of transcoding template groups

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

import com.aliyuncs.vod.model.v20170321.ListTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.ListTranscodeTemplateGroupResponse;

/**
 * Method for querying a list of transcoding template groups
 */
public static ListTranscodeTemplateGroupResponse listTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
    return client.getAcsResponse(request);
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    ListTranscodeTemplateGroupResponse response = new ListTranscodeTemplateGroupResponse();
    try {
        response = listTranscodeTemplateGroup(client);
        System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupList().get(0).getTranscodeTemplateGroupId());
        System.out.println("GroupName = " + response.getTranscodeTemplateGroupList().get(0).getName());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Query a transcoding template group

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

import com.aliyuncs.vod.model.v20170321.GetTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.GetTranscodeTemplateGroupResponse;

/**
 * Method for querying a transcoding template group
 */
public static GetTranscodeTemplateGroupResponse getTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("a0fa0fda545e50e7a3eb75491f9f4");
    return client.getAcsResponse(request);
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetTranscodeTemplateGroupResponse response = new GetTranscodeTemplateGroupResponse();
    try {
        response = getTranscodeTemplateGroup(client);
       if (response.getTranscodeTemplateGroup().getTranscodeTemplateList().size() > 0) { 
                // The ID of the transcoding template group.
                System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateGroupId());
                // The name of the transcoding template group.
                System.out.println("Name = " + response.getTranscodeTemplateGroup().getName());
                // Indicates whether the transcoding template group is the default transcoding template group.
                System.out.println("Name = " + response.getTranscodeTemplateGroup().getIsDefault());
                // The video stream transcoding configuration.
                System.out.println("Video = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getVideo());
                // The audio stream transcoding configuration.
                System.out.println("Audio = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getAudio());
                // The definition.
                System.out.println("Definition = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getDefinition());
                // The associated watermark IDs.
                System.out.println("WatermarkIds = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getWatermarkIds());
                // The encapsulation container.
                System.out.println("Container = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getContainer());
                // The transcoding template ID.
                System.out.println("TranscodeTemplateId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getTranscodeTemplateId());
                // The transcoding template name.
                System.out.println("TemplateName = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getTemplateName());
            }
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Set the default transcoding template group

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

import com.aliyuncs.vod.model.v20170321.SetDefaultTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.SetDefaultTranscodeTemplateGroupResponse;

/**
 * Method for setting the default transcoding template group
 */
public static SetDefaultTranscodeTemplateGroupResponse setDefaultTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("ecf03526c945ae022165c469f4548e");
    return client.getAcsResponse(request);
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    SetDefaultTranscodeTemplateGroupResponse response = new SetDefaultTranscodeTemplateGroupResponse();
    try {
        response = setDefaultTranscodeTemplateGroup(client);
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

Delete a transcoding template group

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

import com.aliyuncs.vod.model.v20170321.DeleteTranscodeTemplateGroupRequest;
import com.aliyuncs.vod.model.v20170321.DeleteTranscodeTemplateGroupResponse;

/**
 * Method for deleting a transcoding template group
 */
public static DeleteTranscodeTemplateGroupResponse deleteTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("a0fa0fda545e50e91a3eb75491f9f4");
    request.setForceDelGroup("false");
    request.setTranscodeTemplateIds("ddddddd,ffffffff");
    return client.getAcsResponse(request);
}

/**
 * Call example
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteTranscodeTemplateGroupResponse response = new DeleteTranscodeTemplateGroupResponse();
    try {
        response = deleteTranscodeTemplateGroup(client);
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}