全部产品
云市场

转码模板

更新时间:2019-03-15 20:33:37

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

添加转码模板组

接口参数和返回字段请参考 AddTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.AddTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.AddTranscodeTemplateGroupResponse;
  3. /**
  4. * 添加转码模板组配置
  5. */
  6. public static AddTranscodeTemplateGroupResponse addTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
  8. //转码模板ID
  9. request.setName("grouptest");
  10. request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 构建需要添加的转码模板配置数据
  15. *
  16. * @return
  17. */
  18. public static JSONArray buildTranscodeTemplateList() {
  19. JSONObject transcodeTemplate = new JSONObject();
  20. //模板名称
  21. transcodeTemplate.put("TemplateName", "testtemplate");
  22. //清晰度
  23. transcodeTemplate.put("Definition", "LD");
  24. //视频流转码配置
  25. JSONObject video = new JSONObject();
  26. video.put("Width", 640);
  27. video.put("Bitrate", 400);
  28. video.put("Fps", 25);
  29. video.put("Remove", false);
  30. video.put("Codec", "H.264");
  31. video.put("Gop", "250");
  32. transcodeTemplate.put("Video", video);
  33. //音频流转码配置
  34. JSONObject audio = new JSONObject();
  35. audio.put("Codec", "AAC");
  36. audio.put("Bitrate", "64");
  37. audio.put("Channels", "2");
  38. audio.put("Samplerate", "32000");
  39. transcodeTemplate.put("Audio", audio);
  40. //封装容器
  41. JSONObject container = new JSONObject();
  42. container.put("Format", "mp4");
  43. transcodeTemplate.put("Container", container);
  44. //条件转码配置
  45. JSONObject transconfig = new JSONObject();
  46. transconfig.put("IsCheckReso", false);
  47. transconfig.put("IsCheckResoFail", false);
  48. transconfig.put("IsCheckVideoBitrate", false);
  49. transconfig.put("IsCheckVideoBitrateFail", false);
  50. transconfig.put("IsCheckAudioBitrate", false);
  51. transconfig.put("IsCheckAudioBitrateFail", false);
  52. transcodeTemplate.put("TransConfig", transconfig);
  53. //加密配置(只支持m3u8)
  54. //JSONObject encryptSetting = new JSONObject();
  55. //encryptSetting.put("EncryptType", "Private");
  56. //transcodeTemplate.put("EncryptSetting", encryptSetting);
  57. //水印ID(多水印关联)
  58. JSONArray watermarkIdList = new JSONArray();
  59. watermarkIdList.add("263261bdc1ff65782f8995c6dd22a16a");
  60. //USER_DEFAULT_WATERMARK 代表默认水印ID
  61. watermarkIdList.add("USER_DEFAULT_WATERMARK");
  62. transcodeTemplate.put("WatermarkIds", watermarkIdList);
  63. JSONArray transcodeTemplateList = new JSONArray();
  64. transcodeTemplateList.add(transcodeTemplate);
  65. return transcodeTemplateList;
  66. }
  67. /**
  68. * 以下为调用示例
  69. */
  70. public static void main(String[] args) throws ClientException {
  71. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  72. AddTranscodeTemplateGroupResponse response = new AddTranscodeTemplateGroupResponse();
  73. try {
  74. response = addTranscodeTemplateGroup(client);
  75. System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupId());
  76. } catch (Exception e) {
  77. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  78. }
  79. System.out.println("RequestId = " + response.getRequestId());
  80. }

修改转码模板组

接口参数和返回字段请参考 UpdateTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.UpdateTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateTranscodeTemplateGroupResponse;
  3. /**
  4. * 修改转码模板组配置
  5. */
  6. public static UpdateTranscodeTemplateGroupResponse updateTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
  8. request.setName("grouptest1");
  9. //转码模板组ID
  10. request.setTranscodeTemplateGroupId("4c71a339fecec0152b4fa6f4527b89");
  11. request.setTranscodeTemplateList(buildTranscodeTemplateList().toJSONString());
  12. return client.getAcsResponse(request);
  13. }
  14. /**
  15. * 构建需要修改的转码模板配置数据
  16. *
  17. * @return
  18. */
  19. public static JSONArray buildTranscodeTemplateList() {
  20. JSONObject transcodeTemplate = new JSONObject();
  21. //转码模板ID
  22. transcodeTemplate.put("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56242f");
  23. //模板名称
  24. transcodeTemplate.put("TemplateName", "testtemplate");
  25. //视频流转码配置
  26. JSONObject video = new JSONObject();
  27. video.put("Width", 960);
  28. video.put("Bitrate", 900);
  29. video.put("Fps", 25);
  30. video.put("Remove", false);
  31. video.put("Codec", "H.264");
  32. video.put("Gop", "250");
  33. transcodeTemplate.put("Video", video);
  34. //音频流转码配置
  35. JSONObject audio = new JSONObject();
  36. audio.put("Codec", "AAC");
  37. audio.put("Bitrate", "96");
  38. audio.put("Channels", "2");
  39. audio.put("Samplerate", "32000");
  40. transcodeTemplate.put("Audio", audio);
  41. //封装容器
  42. JSONObject container = new JSONObject();
  43. container.put("Format", "mp4");
  44. transcodeTemplate.put("Container", container);
  45. //条件转码配置
  46. JSONObject transconfig = new JSONObject();
  47. transconfig.put("IsCheckReso", false);
  48. transconfig.put("IsCheckResoFail", false);
  49. transconfig.put("IsCheckVideoBitrate", false);
  50. transconfig.put("IsCheckVideoBitrateFail", false);
  51. transconfig.put("IsCheckAudioBitrate", false);
  52. transconfig.put("IsCheckAudioBitrateFail", false);
  53. transcodeTemplate.put("TransConfig", transconfig);
  54. //加密配置(只支持m3u8)
  55. JSONObject encryptSetting = new JSONObject();
  56. encryptSetting.put("EncryptType", "Private");
  57. //水印ID(多水印关联)
  58. JSONArray watermarkIdList = new JSONArray();
  59. watermarkIdList.add("263261bdc1ff65782f95c6dd22a16a");
  60. //USER_DEFAULT_WATERMARK 代表默认水印ID
  61. watermarkIdList.add("USER_DEFAULT_WATERMARK");
  62. transcodeTemplate.put("WatermarkIds", watermarkIdList);
  63. JSONArray transcodeTemplateList = new JSONArray();
  64. transcodeTemplateList.add(transcodeTemplate);
  65. return transcodeTemplateList;
  66. }
  67. /**
  68. * 以下为调用示例
  69. */
  70. public static void main(String[] args) throws ClientException {
  71. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  72. UpdateTranscodeTemplateGroupResponse response = new UpdateTranscodeTemplateGroupResponse();
  73. try {
  74. response = updateTranscodeTemplateGroup(client);
  75. System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupId());
  76. } catch (Exception e) {
  77. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  78. }
  79. System.out.println("RequestId = " + response.getRequestId());
  80. }

查询转码模板组列表

接口参数和返回字段请参考 ListTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.ListTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.ListTranscodeTemplateGroupResponse;
  3. /**
  4. * 查询转码模板组列表
  5. */
  6. public static ListTranscodeTemplateGroupResponse listTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
  8. return client.getAcsResponse(request);
  9. }
  10. /**
  11. * 以下为调用示例
  12. */
  13. public static void main(String[] args) throws ClientException {
  14. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  15. ListTranscodeTemplateGroupResponse response = new ListTranscodeTemplateGroupResponse();
  16. try {
  17. response = listTranscodeTemplateGroup(client);
  18. System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroupList().get(0).getTranscodeTemplateGroupId());
  19. System.out.println("GroupName = " + response.getTranscodeTemplateGroupList().get(0).getName());
  20. } catch (Exception e) {
  21. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  22. }
  23. System.out.println("RequestId = " + response.getRequestId());
  24. }

查询单个转码模板组

接口参数和返回字段请参考 GetTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.GetTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetTranscodeTemplateGroupResponse;
  3. /**
  4. * 查询单个转码模板组配置
  5. */
  6. public static GetTranscodeTemplateGroupResponse getTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
  8. request.setTranscodeTemplateGroupId("a0fa0fda545e50e7a3eb75491f9f4");
  9. return client.getAcsResponse(request);
  10. }
  11. /**
  12. * 以下为调用示例
  13. */
  14. public static void main(String[] args) throws ClientException {
  15. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  16. GetTranscodeTemplateGroupResponse response = new GetTranscodeTemplateGroupResponse();
  17. try {
  18. response = getTranscodeTemplateGroup(client);
  19. if (response.getTranscodeTemplateGroup().getTranscodeTemplateList().size() > 0) {
  20. //转码模板组ID
  21. System.out.println("TranscodeTemplateGroupId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateGroupId());
  22. //转码模板组名称
  23. System.out.println("Name = " + response.getTranscodeTemplateGroup().getName());
  24. //是否是默认转码模板组
  25. System.out.println("Name = " + response.getTranscodeTemplateGroup().getIsDefault());
  26. //转码模板视频转码配置
  27. System.out.println("Video = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getVideo());
  28. //转码模板音频转码配置
  29. System.out.println("Audio = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getAudio());
  30. //转码模板清晰度标记
  31. System.out.println("Definition = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getDefinition());
  32. //转码需要压制的水印对应ID
  33. System.out.println("WatermarkIds = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getWatermarkIds());
  34. //转码模板封装格式配置
  35. System.out.println("Container = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getContainer());
  36. //转码模板ID
  37. System.out.println("TranscodeTemplateId = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getTranscodeTemplateId());
  38. //转码模板名称
  39. System.out.println("TemplateName = " + response.getTranscodeTemplateGroup().getTranscodeTemplateList().get(0).getTemplateName());
  40. }
  41. } catch (Exception e) {
  42. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  43. }
  44. System.out.println("RequestId = " + response.getRequestId());
  45. }

设置默认转码模板组

接口参数和返回字段请参考 SetDefaultTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.SetDefaultTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.SetDefaultTranscodeTemplateGroupResponse;
  3. /**
  4. * 设置默认转码模板组
  5. */
  6. public static SetDefaultTranscodeTemplateGroupResponse setDefaultTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
  8. request.setTranscodeTemplateGroupId("ecf03526c945ae022165c469f4548e");
  9. return client.getAcsResponse(request);
  10. }
  11. /**
  12. * 以下为调用示例
  13. */
  14. public static void main(String[] args) throws ClientException {
  15. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  16. SetDefaultTranscodeTemplateGroupResponse response = new SetDefaultTranscodeTemplateGroupResponse();
  17. try {
  18. response = setDefaultTranscodeTemplateGroup(client);
  19. } catch (Exception e) {
  20. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  21. }
  22. System.out.println("RequestId = " + response.getRequestId());
  23. }

删除转码模板组

接口参数和返回字段请参考 DeleteTranscodeTemplateGroup

  1. import com.aliyuncs.vod.model.v20170321.DeleteTranscodeTemplateGroupRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteTranscodeTemplateGroupResponse;
  3. /**
  4. * 删除转码模板组配置
  5. */
  6. public static DeleteTranscodeTemplateGroupResponse deleteTranscodeTemplateGroup(DefaultAcsClient client) throws Exception {
  7. DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
  8. request.setTranscodeTemplateGroupId("a0fa0fda545e50e91a3eb75491f9f4");
  9. request.setForceDelGroup("false");
  10. request.setTranscodeTemplateIds("ddddddd,ffffffff");
  11. return client.getAcsResponse(request);
  12. }
  13. /**
  14. * 以下为调用示例
  15. */
  16. public static void main(String[] args) throws ClientException {
  17. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  18. DeleteTranscodeTemplateGroupResponse response = new DeleteTranscodeTemplateGroupResponse();
  19. try {
  20. response = deleteTranscodeTemplateGroup(client);
  21. } catch (Exception e) {
  22. System.out.println("ErrorMessage = " + e.getLocalizedMessage());
  23. }
  24. System.out.println("RequestId = " + response.getRequestId());
  25. }