全部产品
云市场

转码模板

更新时间:2019-03-06 16:25:56

初始化客户端

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

添加转码模板组

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.VoD.Sdk.AddTranscodeTemplateGroup
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// The entry point of the program, where the program control starts and ends.
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. try
  18. {
  19. // 初始化客户端
  20. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. // 发起请求,并得到 response
  22. AddTranscodeTemplateGroupResponse response = AddTranscodeTemplateGroup(client);
  23. // 打印请求ID
  24. Console.WriteLine("RequestId = " + response.RequestId);
  25. // 打印转码模板ID
  26. Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroupId);
  27. }
  28. catch (ServerException e)
  29. {
  30. if (e.RequestId != null)
  31. {
  32. Console.WriteLine("RequestId = " + e.RequestId);
  33. }
  34. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  35. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  36. }
  37. catch (ClientException e)
  38. {
  39. if (e.RequestId != null)
  40. {
  41. Console.WriteLine("RequestId = " + e.RequestId);
  42. }
  43. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  44. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  45. }
  46. catch (Exception e)
  47. {
  48. Console.WriteLine("ErrorMessage = " + e.ToString());
  49. }
  50. }
  51. /// <summary>
  52. /// 添加转码模板组
  53. /// </summary>
  54. /// <returns>转码模板组</returns>
  55. /// <param name="client">Client.</param>
  56. public static AddTranscodeTemplateGroupResponse AddTranscodeTemplateGroup(DefaultAcsClient client)
  57. {
  58. // 构造请求
  59. AddTranscodeTemplateGroupRequest request = new AddTranscodeTemplateGroupRequest();
  60. // 转码模板组名称
  61. request.Name = "grouptest";
  62. request.TranscodeTemplateList = BuildTranscodeTemplateList();
  63. // 返回结果
  64. return client.GetAcsResponse(request);
  65. }
  66. private static String BuildTranscodeTemplateList()
  67. {
  68. JArray transcodeTemplateList = new JArray();
  69. JObject transcodeTemplate = new JObject();
  70. //视频流转码配置
  71. JObject video = new JObject();
  72. video.Add("Width", 640);
  73. video.Add("Bitrate", 400);
  74. video.Add("Fps", "25");
  75. video.Add("Remove", false);
  76. video.Add("Codec", "H.264");
  77. video.Add("Gop", 250);
  78. transcodeTemplate.Add("Video", video);
  79. //音频流转码配置
  80. JObject audio = new JObject();
  81. audio.Add("Codec", "AAC");
  82. audio.Add("Bitrate", "64");
  83. audio.Add("Channels", "2");
  84. audio.Add("Samplerate", "32000");
  85. transcodeTemplate.Add("Audio", audio);
  86. //封装容器
  87. JObject container = new JObject();
  88. container.Add("Format", "mp4");
  89. transcodeTemplate.Add("Container", container);
  90. //条件转码配置
  91. JObject transconfig = new JObject();
  92. transconfig.Add("IsCheckReso", false);
  93. transconfig.Add("IsCheckResoFail", false);
  94. transconfig.Add("IsCheckVideoBitrate", false);
  95. transconfig.Add("IsCheckVideoBitrateFail", false);
  96. transconfig.Add("IsCheckAudioBitrate", false);
  97. transconfig.Add("IsCheckAudioBitrateFail", false);
  98. transcodeTemplate.Add("TransConfig", transconfig);
  99. //加密配置(只支持m3u8)
  100. //JObject encryptSetting = new JObject();
  101. //encryptSetting.Add("EncryptType", "Private");
  102. //transcodeTemplate.Add("EncryptSetting", encryptSetting);
  103. //清晰度
  104. transcodeTemplate.Add("Definition", "LD");
  105. //模板名称
  106. transcodeTemplate.Add("TemplateName", "testtemplate");
  107. //水印ID(多水印关联)
  108. //JArray watermarkIdList = new JArray();
  109. //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22a16a");
  110. //USER_DEFAULT_WATERMARK 代表默认水印ID
  111. //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
  112. //transcodeTemplate.Add("WatermarkIds", watermarkIdList);
  113. transcodeTemplateList.Add(transcodeTemplate);
  114. return transcodeTemplateList.ToString();
  115. }
  116. }
  117. }

修改转码模板组

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.VoD.Sdk.UpdateTranscodeTemplateGroup
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// The entry point of the program, where the program control starts and ends.
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. try
  18. {
  19. // 初始化客户端
  20. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. // 发起请求,并得到 response
  22. UpdateTranscodeTemplateGroupResponse response = UpdateTranscodeTemplateGroup(client);
  23. // 打印请求ID
  24. Console.WriteLine("RequestId = " + response.RequestId);
  25. // 打印转码模版ID
  26. Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroupId);
  27. }
  28. catch (ServerException e)
  29. {
  30. if (e.RequestId != null)
  31. {
  32. Console.WriteLine("RequestId = " + e.RequestId);
  33. }
  34. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  35. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  36. }
  37. catch (ClientException e)
  38. {
  39. if (e.RequestId != null)
  40. {
  41. Console.WriteLine("RequestId = " + e.RequestId);
  42. }
  43. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  44. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  45. }
  46. catch (Exception e)
  47. {
  48. Console.WriteLine("ErrorMessage = " + e.ToString());
  49. }
  50. }
  51. /// <summary>
  52. /// 修改转码模板组
  53. /// </summary>
  54. /// <returns>转码模板组</returns>
  55. /// <param name="client">Client.</param>
  56. public static UpdateTranscodeTemplateGroupResponse UpdateTranscodeTemplateGroup(DefaultAcsClient client)
  57. {
  58. // 构造请求
  59. UpdateTranscodeTemplateGroupRequest request = new UpdateTranscodeTemplateGroupRequest();
  60. request.Name = "newgrouptest";
  61. // 转码模板组ID
  62. request.TranscodeTemplateGroupId = "4c71a339fecec0152b4fa6f4527b89";
  63. request.TranscodeTemplateList = BuildTranscodeTemplateList();
  64. // 返回结果
  65. return client.GetAcsResponse(request);
  66. }
  67. private static String BuildTranscodeTemplateList()
  68. {
  69. JArray transcodeTemplateList = new JArray();
  70. JObject transcodeTemplate = new JObject();
  71. //视频流转码配置
  72. JObject video = new JObject();
  73. video.Add("Width", 640);
  74. video.Add("Bitrate", 400);
  75. video.Add("Fps", "25");
  76. video.Add("Remove", false);
  77. video.Add("Codec", "H.264");
  78. video.Add("Gop", 250);
  79. transcodeTemplate.Add("Video", video);
  80. //音频流转码配置
  81. JObject audio = new JObject();
  82. audio.Add("Codec", "AAC");
  83. audio.Add("Bitrate", "64");
  84. audio.Add("Channels", "2");
  85. audio.Add("Samplerate", "32000");
  86. transcodeTemplate.Add("Audio", audio);
  87. //封装容器
  88. JObject container = new JObject();
  89. container.Add("Format", "mp4");
  90. transcodeTemplate.Add("Container", container);
  91. //条件转码配置
  92. JObject transconfig = new JObject();
  93. transconfig.Add("IsCheckReso", false);
  94. transconfig.Add("IsCheckResoFail", false);
  95. transconfig.Add("IsCheckVideoBitrate", false);
  96. transconfig.Add("IsCheckVideoBitrateFail", false);
  97. transconfig.Add("IsCheckAudioBitrate", false);
  98. transconfig.Add("IsCheckAudioBitrateFail", false);
  99. transcodeTemplate.Add("TransConfig", transconfig);
  100. //加密配置(只支持m3u8)
  101. //JObject encryptSetting = new JObject();
  102. //encryptSetting.Add("EncryptType", "Private");
  103. //transcodeTemplate.Add("EncryptSetting", encryptSetting);
  104. //清晰度
  105. transcodeTemplate.Add("Definition", "SD");
  106. //模板名称
  107. transcodeTemplate.Add("TemplateName", "testtemplate");
  108. //转码模板ID
  109. transcodeTemplate.Add("TranscodeTemplateId", "85c2b18ac08fda33e8f6d9c56242f");
  110. //水印ID(多水印关联)
  111. //JArray watermarkIdList = new JArray();
  112. //watermarkIdList.Add("263261bdc1ff65782f8995c6dd22a16a");
  113. //USER_DEFAULT_WATERMARK 代表默认水印ID
  114. //watermarkIdList.Add("USER_DEFAULT_WATERMARK");
  115. //transcodeTemplate.Add("WatermarkIds", watermarkIdList);
  116. transcodeTemplateList.Add(transcodeTemplate);
  117. return transcodeTemplateList.ToString();
  118. }
  119. }
  120. }

查询转码模板组列表

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.VoD.Sdk.ListTranscodeTemplateGroup
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// The entry point of the program, where the program control starts and ends.
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. ListTranscodeTemplateGroupResponse response = ListTranscodeTemplateGroup(client);
  22. // 打印请求ID
  23. Console.WriteLine("RequestId = " + response.RequestId);
  24. // 打印模板组信息
  25. if (response.TranscodeTemplateGroupList != null && response.TranscodeTemplateGroupList.Count > 0)
  26. {
  27. foreach (ListTranscodeTemplateGroupResponse.ListTranscodeTemplateGroup_TranscodeTemplateGroup templateGroup in response.TranscodeTemplateGroupList)
  28. {
  29. Console.WriteLine("Name = " + templateGroup.Name);
  30. Console.WriteLine("TranscodeTemplateGroupId = " + templateGroup.TranscodeTemplateGroupId);
  31. Console.WriteLine("IsDefault = " + templateGroup.IsDefault);
  32. Console.WriteLine("CreationTime = " + templateGroup.CreationTime);
  33. }
  34. }
  35. }
  36. catch (ServerException e)
  37. {
  38. if (e.RequestId != null)
  39. {
  40. Console.WriteLine("RequestId = " + e.RequestId);
  41. }
  42. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  43. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  44. }
  45. catch (ClientException e)
  46. {
  47. if (e.RequestId != null)
  48. {
  49. Console.WriteLine("RequestId = " + e.RequestId);
  50. }
  51. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  52. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  53. }
  54. catch (Exception e)
  55. {
  56. Console.WriteLine("ErrorMessage = " + e.ToString());
  57. }
  58. }
  59. /// <summary>
  60. /// 查询转码模板组列表
  61. /// </summary>
  62. /// <returns>模板组列表</returns>
  63. /// <param name="client">Client.</param>
  64. public static ListTranscodeTemplateGroupResponse ListTranscodeTemplateGroup(DefaultAcsClient client)
  65. {
  66. // 构造请求
  67. ListTranscodeTemplateGroupRequest request = new ListTranscodeTemplateGroupRequest();
  68. // 返回结果
  69. return client.GetAcsResponse(request);
  70. }
  71. }
  72. }

查询单个转码模板组

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.VoD.Sdk.GetTranscodeTemplateGroup
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// The entry point of the program, where the program control starts and ends.
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. GetTranscodeTemplateGroupResponse response = GetTranscodeTemplateGroup(client);
  22. // 打印请求ID
  23. Console.WriteLine("RequestId = " + response.RequestId);
  24. // 打印模板组信息
  25. Console.WriteLine("Name = " + response.TranscodeTemplateGroup.Name);
  26. Console.WriteLine("TranscodeTemplateGroupId = " + response.TranscodeTemplateGroup.TranscodeTemplateGroupId);
  27. Console.WriteLine("IsDefault = " + response.TranscodeTemplateGroup.IsDefault);
  28. Console.WriteLine("CreationTime = " + response.TranscodeTemplateGroup.CreationTime);
  29. }
  30. catch (ServerException e)
  31. {
  32. if (e.RequestId != null)
  33. {
  34. Console.WriteLine("RequestId = " + e.RequestId);
  35. }
  36. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  37. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  38. }
  39. catch (ClientException e)
  40. {
  41. if (e.RequestId != null)
  42. {
  43. Console.WriteLine("RequestId = " + e.RequestId);
  44. }
  45. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  46. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  47. }
  48. catch (Exception e)
  49. {
  50. Console.WriteLine("ErrorMessage = " + e.ToString());
  51. }
  52. }
  53. /// <summary>
  54. /// 查询单个转码模板组
  55. /// </summary>
  56. /// <returns>模板组</returns>
  57. /// <param name="client">Client.</param>
  58. public static GetTranscodeTemplateGroupResponse GetTranscodeTemplateGroup(DefaultAcsClient client)
  59. {
  60. // 构造请求
  61. GetTranscodeTemplateGroupRequest request = new GetTranscodeTemplateGroupRequest();
  62. request.TranscodeTemplateGroupId = "94bcd9366be0df7ffba3b6f7b715d826";
  63. // 返回结果
  64. return client.GetAcsResponse(request);
  65. }
  66. }
  67. }

设置默认转码模板组

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.VoD.Sdk.SetDefaultTranscodeTemplateGroup
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// The entry point of the program, where the program control starts and ends.
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. SetDefaultTranscodeTemplateGroupResponse response = SetDefaultTranscodeTemplateGroup(client);
  22. // 打印请求ID
  23. Console.WriteLine("RequestId = " + response.RequestId);
  24. }
  25. catch (ServerException e)
  26. {
  27. if (e.RequestId != null)
  28. {
  29. Console.WriteLine("RequestId = " + e.RequestId);
  30. }
  31. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  32. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  33. }
  34. catch (ClientException e)
  35. {
  36. if (e.RequestId != null)
  37. {
  38. Console.WriteLine("RequestId = " + e.RequestId);
  39. }
  40. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  41. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  42. }
  43. catch (Exception e)
  44. {
  45. Console.WriteLine("ErrorMessage = " + e.ToString());
  46. }
  47. }
  48. /// <summary>
  49. /// 设置默认转码模板组
  50. /// </summary>
  51. /// <returns>默认转码模板组</returns>
  52. /// <param name="client">Client.</param>
  53. public static SetDefaultTranscodeTemplateGroupResponse SetDefaultTranscodeTemplateGroup(DefaultAcsClient client)
  54. {
  55. // 构造请求
  56. SetDefaultTranscodeTemplateGroupRequest request = new SetDefaultTranscodeTemplateGroupRequest();
  57. // 设置模板ID
  58. request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ffxxxxxx";
  59. // 返回结果
  60. return client.GetAcsResponse(request);
  61. }
  62. }
  63. }

删除转码模板组

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.VoD.Sdk.DeleteTranscodeTemplateGroup
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// The entry point of the program, where the program control starts and ends.
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. DeleteTranscodeTemplateGroupResponse response = DeleteTranscodeTemplateGroup(client);
  22. // 打印请求ID
  23. Console.WriteLine("RequestId = " + response.RequestId);
  24. }
  25. catch (ServerException e)
  26. {
  27. if (e.RequestId != null)
  28. {
  29. Console.WriteLine("RequestId = " + e.RequestId);
  30. }
  31. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  32. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  33. }
  34. catch (ClientException e)
  35. {
  36. if (e.RequestId != null)
  37. {
  38. Console.WriteLine("RequestId = " + e.RequestId);
  39. }
  40. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  41. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  42. }
  43. catch (Exception e)
  44. {
  45. Console.WriteLine("ErrorMessage = " + e.ToString());
  46. }
  47. }
  48. /// <summary>
  49. /// 删除转码模板组配置
  50. /// </summary>
  51. /// <param name="client">Client.</param>
  52. public static DeleteTranscodeTemplateGroupResponse DeleteTranscodeTemplateGroup(DefaultAcsClient client)
  53. {
  54. // 构造请求
  55. DeleteTranscodeTemplateGroupRequest request = new DeleteTranscodeTemplateGroupRequest();
  56. request.TranscodeTemplateGroupId = "dc063078c1d845139e2a5bd8ffxxxxxx";
  57. // 返回结果
  58. return client.GetAcsResponse(request);
  59. }
  60. }
  61. }