全部产品
云市场

媒体处理

更新时间:2019-08-29 10:07:25

初始化客户端

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

提交转码作业

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Kms.Model.V20160120;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.vod.Sdk.SubmitTranscodeJobs
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// 主函数
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. try
  18. {
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. SubmitTranscodeJobsResponse response = SubmitTranscodeJobs(client);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. }
  24. catch (ServerException e)
  25. {
  26. if (e.RequestId != null)
  27. {
  28. Console.WriteLine("RequestId = " + e.RequestId);
  29. }
  30. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  31. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  32. }
  33. catch (ClientException e)
  34. {
  35. if (e.RequestId != null)
  36. {
  37. Console.WriteLine("RequestId = " + e.RequestId);
  38. }
  39. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  40. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine("ErrorMessage = " + e.ToString());
  45. }
  46. }
  47. /// <summary>
  48. /// 提交转码作业函数
  49. /// </summary>
  50. /// <returns>转码JobId.</returns>
  51. /// <param name="client">Client</param>
  52. public static SubmitTranscodeJobsResponse SubmitTranscodeJobs(DefaultAcsClient client)
  53. {
  54. // 构造请求
  55. SubmitTranscodeJobsRequest request = new SubmitTranscodeJobsRequest();
  56. // 需要转码的视ID
  57. request.VideoId = "1f7ed5623409489193e41d16f6c7e0fc";
  58. // 转码模板ID
  59. request.TemplateGroupId = "3cac80cddb4455e37460f491aecca588";
  60. // 构建需要替换的水印参数(只有需要替换水印相关信息才需要构建)
  61. request.OverrideParams = BuildOverrideParams();
  62. // 覆盖参数,暂只支持水印部分参数替换(只有需要替换水印相关信息才需要传递)
  63. request.EncryptConfig = BuildEncryptConfig(client);
  64. return client.GetAcsResponse(request);
  65. }
  66. /// <summary>
  67. /// 生成加密需要的秘钥,response中包含密文秘钥和明文秘钥,用户只需要将密文秘钥传递给点播即可
  68. /// 注意:KeySpec 必须传递AES_128,且不能设置NumberOfBytes
  69. /// </summary>
  70. /// <returns> DataKey </returns>
  71. /// <param name="client">KMS-SDK Client.</param>
  72. /// <param name="serviceKey">点播提供生成秘钥的service key,在用户的秘钥管理服务中可看到描述为vod的加密key.</param>
  73. ///
  74. public static GenerateDataKeyResponse GenerateDataKey(DefaultAcsClient client, string serviceKey)
  75. {
  76. GenerateDataKeyRequest request = new GenerateDataKeyRequest();
  77. request.KeyId = serviceKey;
  78. request.KeySpec = "AES_128";
  79. return client.GetAcsResponse(request);
  80. }
  81. /// <summary>
  82. /// 构建HLS标准加密的配置信息
  83. /// </summary>
  84. /// <returns>配置信息</returns>
  85. /// <param name="client"> VoD Client.</param>
  86. ///
  87. public static string BuildEncryptConfig(DefaultAcsClient client)
  88. {
  89. // 点播给用户在KMS(秘钥管理服务)中的Service Key,可在用户秘钥管理服务对应的区域看到描述为vod的service key
  90. string serviceKey = "<Your Service Key>";
  91. // 随机生成一个加密的秘钥,返回的response包含明文秘钥以及密文秘钥,
  92. // 视频标准加密只需要传递密文秘钥即可
  93. GenerateDataKeyResponse response = GenerateDataKey(client, serviceKey);
  94. JObject encryptConfig = new JObject();
  95. // 解密接口地址,该参数需要将每次生成的密文秘钥与接口URL拼接生成,表示每个视频的解密的密文秘钥都不一样
  96. // 至于Ciphertext这个解密接口参数的名称,用户可自行制定,这里只作为参考参数名称
  97. encryptConfig.Add("DecryptKeyUri", "http://decrypt.demo.com/decrypt?" + "Ciphertext=" + response.CiphertextBlob);
  98. // 秘钥服务的类型,目前只支持KMS
  99. encryptConfig.Add("KeyServiceType", "KMS");
  100. // 密文秘钥
  101. encryptConfig.Add("CipherText", response.CiphertextBlob);
  102. return encryptConfig.ToString();
  103. }
  104. /// <summary>
  105. /// 1、构建覆盖参数,目前只支持图片水印文件地址、文字水印的内容覆盖;
  106. /// 2、需要替换的水印信息对应水印ID必须是关联在指定的模板ID(即TranscodeTemplateId)中;
  107. /// 3、不支持通过媒体处理接口去增加一个没有关联上的水印
  108. /// 注意:图片水印的文件存储源站需要和发起转码的视频存储源站一致
  109. /// </summary>
  110. /// <returns>The override parameters.</returns>
  111. ///
  112. public static string BuildOverrideParams() {
  113. // 覆盖参数
  114. JObject overrideParams = new JObject();
  115. // 图片水印文件地址替换
  116. JArray watermarks = new JArray();
  117. JObject watermark1 = new JObject();
  118. // 模板上面关联需要替换的水印文件图片水印ID
  119. watermark1.Add("WatermarkId", "2ea587477c5a1bc8b5742d7");
  120. // 需要替换成对应图片水印文件的OSS地址,水印文件存储源站需要和视频存储源站一致
  121. watermark1.Add("FileUrl", "https://outin-40564284ef05113e1403e7.oss-cn-shanghai.aliyuncs.com/watermarks/02A1B22DF25D46C3C725A4-6-2.png");
  122. watermarks.Add(watermark1);
  123. // 文字水印内容替换
  124. JObject watermark2 = new JObject();
  125. // 模板上面关联需要替换内容的文字水印ID
  126. watermark2.Add("WatermarkId", "d297ba31ac5242d2071bf7");
  127. // 需要替换成对应的内容
  128. watermark2.Add("Content", "用户ID:66666");
  129. watermarks.Add(watermark2);
  130. overrideParams.Add("Watermarks", watermarks);
  131. return overrideParams.ToString();
  132. }
  133. }
  134. }

提交截图作业

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

创建截图模板详细请参考 截图模板

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. using Newtonsoft.Json.Linq;
  6. namespace Aliyun.Acs.vod.Sdk.SubmitSnapshotJob
  7. {
  8. class MainClass
  9. {
  10. public static void Main(string[] args)
  11. {
  12. try
  13. {
  14. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  15. // 发起请求,并得到 response
  16. SubmitSnapshotJobResponse response = SubmitSnapshotJob(client);
  17. Console.WriteLine("RequestId = " + response.RequestId);
  18. }
  19. catch (ServerException e)
  20. {
  21. if (e.RequestId != null)
  22. {
  23. Console.WriteLine("RequestId = " + e.RequestId);
  24. }
  25. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  26. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  27. }
  28. catch (ClientException 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 (Exception e)
  38. {
  39. Console.WriteLine("ErrorMessage = " + e.ToString());
  40. }
  41. }
  42. public static SubmitSnapshotJobResponse SubmitSnapshotJob(DefaultAcsClient client)
  43. {
  44. // 构造请求
  45. SubmitSnapshotJobRequest request = new SubmitSnapshotJobRequest();
  46. //需要截图的视频ID(推荐传递截图模板ID)
  47. request.VideoId = "1f7ed5623409489193e41d16f6c7e0fc";
  48. //截图模板ID
  49. request.SnapshotTemplateId = "3cac80cddb4455e37460f491aecca588";
  50. //如果设置了SnapshotTemplateId,会忽略下面参数
  51. request.Count = 50;
  52. request.SpecifiedOffsetTime = 0;
  53. request.Interval = 1;
  54. request.Width = "200";
  55. request.Height = "200";
  56. request.SpriteSnapshotConfig = BuildSnapshotTemplateConfig();
  57. return client.GetAcsResponse(request);
  58. }
  59. /// <summary>
  60. /// 构建雪碧图截图配置
  61. /// </summary>
  62. /// <returns>雪碧图截图配置.</returns>
  63. public static string BuildSnapshotTemplateConfig()
  64. {
  65. // 覆盖参数
  66. JObject spriteSnapshotConfig = new JObject();
  67. spriteSnapshotConfig.Add("CellWidth", "120");
  68. spriteSnapshotConfig.Add("CellHeight", "68");
  69. spriteSnapshotConfig.Add("Columns", "3");
  70. spriteSnapshotConfig.Add("Lines", "10");
  71. spriteSnapshotConfig.Add("Padding", "20");
  72. spriteSnapshotConfig.Add("Margin", "50");
  73. //保留雪碧图原始图
  74. spriteSnapshotConfig.Add("KeepCellPic", "keep");
  75. spriteSnapshotConfig.Add("Color", "tomato");
  76. return spriteSnapshotConfig.ToString();
  77. }
  78. }
  79. }

查询截图数据

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.ListSnapshots
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  14. // 发起请求,并得到 response
  15. ListSnapshotsResponse response = ListSnapshots(client);
  16. Console.WriteLine("RequestId = " + response.RequestId);
  17. }
  18. catch (ServerException e)
  19. {
  20. if (e.RequestId != null)
  21. {
  22. Console.WriteLine("RequestId = " + e.RequestId);
  23. }
  24. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  25. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  26. }
  27. catch (ClientException e)
  28. {
  29. if (e.RequestId != null)
  30. {
  31. Console.WriteLine("RequestId = " + e.RequestId);
  32. }
  33. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  34. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  35. }
  36. catch (Exception e)
  37. {
  38. Console.WriteLine("ErrorMessage = " + e.ToString());
  39. }
  40. }
  41. public static ListSnapshotsResponse ListSnapshots(DefaultAcsClient client)
  42. {
  43. // 构造请求
  44. ListSnapshotsRequest request = new ListSnapshotsRequest();
  45. // 视频ID
  46. request.VideoId = "1f7ed5623409489193e41d16f6c7e1fc";
  47. // 截图类型
  48. request.SnapshotType = "CoverSnapshot";
  49. request.PageNo = "1";
  50. request.PageSize = "20";
  51. return client.GetAcsResponse(request);
  52. }
  53. }
  54. }

导播台视频预处理

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.SubmitPreprocessJobs
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  14. // 发起请求,并得到 response
  15. SubmitPreprocessJobsResponse response = SubmitPreprocessJobs(client);
  16. Console.WriteLine("RequestId = " + response.RequestId);
  17. }
  18. catch (ServerException e)
  19. {
  20. if (e.RequestId != null)
  21. {
  22. Console.WriteLine("RequestId = " + e.RequestId);
  23. }
  24. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  25. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  26. }
  27. catch (ClientException e)
  28. {
  29. if (e.RequestId != null)
  30. {
  31. Console.WriteLine("RequestId = " + e.RequestId);
  32. }
  33. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  34. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  35. }
  36. catch (Exception e)
  37. {
  38. Console.WriteLine("ErrorMessage = " + e.ToString());
  39. }
  40. }
  41. /// <summary>
  42. /// 导播台视频预处理.
  43. /// </summary>
  44. /// <returns>The preprocess jobs.</returns>
  45. /// <param name="client">Vod Client.</param>
  46. public static SubmitPreprocessJobsResponse SubmitPreprocessJobs(DefaultAcsClient client)
  47. {
  48. // 构造请求
  49. SubmitPreprocessJobsRequest request = new SubmitPreprocessJobsRequest();
  50. // 需要截图的视频ID(推荐传递截图模板ID)
  51. request.VideoId = "c86c0ceb8db54ae097965352418";
  52. // 截图类型
  53. request.PreprocessType = "PreprocessType";
  54. return client.GetAcsResponse(request);
  55. }
  56. }
  57. }