全部产品

转码模板

本篇文档提供了Java SDK转码模板模块相关功能的API调用示例。包含添加转码模板组、修改转码模板组、删除转码模板组、查询转码模板组、设置默认转码模板组等。

初始化客户端

使用前请先初始化客户端,请参见初始化

添加转码模板组

调用AddTranscodeTemplateGroup接口,完成添加转码模板组功能。

接口参数和返回字段请参见AddTranscodeTemplateGroup。调用示例如下:

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

/**
 * 添加转码模板组配置
 */
public static AddTranscodeTemplateGroupResponse addTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
    //转码模板ID
    request.setName("grouptest");
    request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
    return client.getAcsResponse(request);
}

/**
 * 构建需要添加的转码模板配置数据
 *
 * @return
 */
public static JSONArray buildTranscodeTemplateList() {
    JSONObject transcodeTemplate = new JSONObject();
    //模板名称
    transcodeTemplate.put("TemplateName", "testtemplate");

    //清晰度
    transcodeTemplate.put("Definition", "LD");

    //视频流转码配置
    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);

    //音频流转码配置
    JSONObject audio = new JSONObject();
    audio.put("Codec", "AAC");
    audio.put("Bitrate", "64");
    audio.put("Channels", "2");
    audio.put("Samplerate", "32000");
    transcodeTemplate.put("Audio", audio);

    //封装容器
    JSONObject container = new JSONObject();
    container.put("Format", "mp4");
    transcodeTemplate.put("Container", container);

    //条件转码配置
    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);

    //加密配置(只支持m3u8)
    //JSONObject encryptSetting = new JSONObject();
    //encryptSetting.put("EncryptType", "Private");
    //transcodeTemplate.put("EncryptSetting", encryptSetting);

    //水印ID(多水印关联)
    JSONArray watermarkIdList = new JSONArray();
    watermarkIdList.add("263261bdc1ff65782f8995c6dd22a16a");
    //USER_DEFAULT_WATERMARK 代表默认水印ID
    watermarkIdList.add("USER_DEFAULT_WATERMARK");
    transcodeTemplate.put("WatermarkIds", watermarkIdList);

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

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    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());
}

修改转码模板组

调用UpdateTranscodeTemplateGroup接口,完成修改转码模板组功能。

接口参数和返回字段请参见UpdateTranscodeTemplateGroup。调用示例如下:

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

/**
 * 修改转码模板组配置
 */
public static UpdateTranscodeTemplateGroupResponse updateTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
    request.setName("grouptest1");
    //转码模板组ID
    request.setTranscodeTemplateGroupId("4c71a339fecec0152b4fa6f452****");
    request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
    return client.getAcsResponse(request);
}

/**
 * 构建需要修改的转码模板配置数据
 *
 * @return
 */
public static JSONArray buildTranscodeTemplateList() {
    JSONObject transcodeTemplate = new JSONObject();
    //转码模板ID
    transcodeTemplate.put("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56242f");

     //模板名称
    transcodeTemplate.put("TemplateName", "testtemplate");

    //视频流转码配置
    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);

    //音频流转码配置
    JSONObject audio = new JSONObject();
    audio.put("Codec", "AAC");
    audio.put("Bitrate", "96");
    audio.put("Channels", "2");
    audio.put("Samplerate", "32000");
    transcodeTemplate.put("Audio", audio);

    //封装容器
    JSONObject container = new JSONObject();
    container.put("Format", "mp4");
    transcodeTemplate.put("Container", container);

    //条件转码配置
    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);

    //加密配置(只支持m3u8)
    JSONObject encryptSetting = new JSONObject();
    encryptSetting.put("EncryptType", "Private");

    //水印ID(多水印关联)
    JSONArray watermarkIdList = new JSONArray();
    watermarkIdList.add("263261bdc1ff65782f95c6dd22a16a");
    //USER_DEFAULT_WATERMARK 代表默认水印ID
    watermarkIdList.add("USER_DEFAULT_WATERMARK");
    transcodeTemplate.put("WatermarkIds", watermarkIdList);

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

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    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());
}

查询转码模板组列表

调用ListTranscodeTemplateGroup接口,完成查询转码模板组列表功能。

接口参数和返回字段请参见ListTranscodeTemplateGroup。调用示例如下:

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

/**
 * 查询转码模板组列表
 */
public static ListTranscodeTemplateGroupResponse listTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
    return client.getAcsResponse(request);
}

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    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());
}

查询单个转码模板组

调用GetTranscodeTemplateGroup接口,完成查询单个转码模板组功能。

接口参数和返回字段请参见GetTranscodeTemplateGroup。调用示例如下:

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

/**
 * 查询单个转码模板组配置
 */
public static GetTranscodeTemplateGroupResponse getTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("a0fa0fda545e50e7a3eb75491f9f4");
    return client.getAcsResponse(request);
}

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    GetTranscodeTemplateGroupResponse response = new GetTranscodeTemplateGroupResponse();
    try {
        response = getTranscodeTemplateGroup(client);
       if (response.getTranscodeTemplateGroup().getTranscodeTemplateList().size() > 0) {
                //转码模板组ID
                System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateGroupId());
                //转码模板组名称
                System.out.println("Name = " + response.getTranscodeTemplateGroup().getName());
                //是否是默认转码模板组
                System.out.println("Name = " + response.getTranscodeTemplateGroup().getIsDefault());
                //转码模板视频转码配置
                System.out.println("Video = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getVideo());
                //转码模板音频转码配置
                System.out.println("Audio = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getAudio());
                //转码模板清晰度标记
                System.out.println("Definition = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getDefinition());
                //转码需要压制的水印对应ID
                System.out.println("WatermarkIds = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getWatermarkIds());
                //转码模板封装格式配置
                System.out.println("Container = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getContainer());
                //转码模板ID
                System.out.println("TranscodeTemplateId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getTranscodeTemplateId());
                //转码模板名称
                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());
}

设置默认转码模板组

调用SetDefaultTranscodeTemplateGroup接口,完成设置默认转码模板组功能。

接口参数和返回字段请参见SetDefaultTranscodeTemplateGroup。调用示例如下:

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

/**
 * 设置默认转码模板组
 */
public static SetDefaultTranscodeTemplateGroupResponse setDefaultTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("ecf03526c945ae022165c469f4548e");
    return client.getAcsResponse(request);
}

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    SetDefaultTranscodeTemplateGroupResponse response = new SetDefaultTranscodeTemplateGroupResponse();
    try {
        response = setDefaultTranscodeTemplateGroup(client);
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

删除转码模板组

调用DeleteTranscodeTemplateGroup接口,完成删除转码模板组功能。

接口参数和返回字段请参见DeleteTranscodeTemplateGroup。调用示例如下:

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

/**
 * 删除转码模板组配置
 */
public static DeleteTranscodeTemplateGroupResponse deleteTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
    DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
    request.setTranscodeTemplateGroupId("a0fa0fda545e50e91a3eb75491****");
    request.setForceDelGroup("false");
    request.setTranscodeTemplateIds("ddddddd,ffffffff");
    return client.getAcsResponse(request);
}

/**
 * 以下为调用示例
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    DeleteTranscodeTemplateGroupResponse response = new DeleteTranscodeTemplateGroupResponse();
    try {
        response = deleteTranscodeTemplateGroup(client);
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}