全部产品
云市场

视频水印

更新时间:2018-12-29 11:43:47

初始化客户端

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

添加水印

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

  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.AddWatermark
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// 主函数
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. AddWatermarkResponse response = AddWatermark(client);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. }
  23. catch (ServerException e)
  24. {
  25. if (e.RequestId != null)
  26. {
  27. Console.WriteLine("RequestId = " + e.RequestId);
  28. }
  29. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  30. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  31. }
  32. catch (ClientException e)
  33. {
  34. if (e.RequestId != null)
  35. {
  36. Console.WriteLine("RequestId = " + e.RequestId);
  37. }
  38. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  39. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  40. }
  41. catch (Exception e)
  42. {
  43. Console.WriteLine("ErrorMessage = " + e.ToString());
  44. }
  45. }
  46. /// <summary>
  47. /// 添加水印方法
  48. /// </summary>
  49. /// <returns>The watermark.</returns>
  50. /// <param name="client">Client.</param>
  51. public static AddWatermarkResponse AddWatermark(DefaultAcsClient client)
  52. {
  53. // 构造请求
  54. AddWatermarkRequest request = new AddWatermarkRequest();
  55. // 水印名称
  56. request.Name = "addwatermark";
  57. // 图片水印必传图片文件的oss文件地址,水印文件必须和视频在同一个区域,例如:华东2视频,水印文件必须存放在华东2
  58. request.FileUrl = "http://test-bucket.oss-cn-shanghai.aliyuncs.com/watermark/test.png";
  59. // 图片水印的位置配置数据
  60. request.WatermarkConfig = BuildImageWatermarkConfig();
  61. // 文字水印的位置配置数据
  62. request.WatermarkConfig = BuildTextWatermarkConfig();
  63. // 文字水印:Text; 图片水印:Image
  64. request.Type = "Image";
  65. return client.GetAcsResponse(request);
  66. }
  67. /// <summary>
  68. /// 构建图片水印的配置数据,根据具体设置需求修改对应的参数值
  69. /// </summary>
  70. /// <returns>The image watermark config.</returns>
  71. public static string BuildImageWatermarkConfig()
  72. {
  73. JObject watermarkConfig = new JObject();
  74. // 水印的横向偏移距离
  75. watermarkConfig.Add("Dx", "8");
  76. // 水印的纵向偏移距离
  77. watermarkConfig.Add("Dy", "8");
  78. // 水印显示的宽
  79. watermarkConfig.Add("Width", "55");
  80. // 水印显示的高
  81. watermarkConfig.Add("Height", "55");
  82. // 水印显示的相对位置(左上、右上、左下、右下)
  83. watermarkConfig.Add("ReferPos", "BottomRight");
  84. // 水印显示的时间线(开始显示和结束显示时间)
  85. JObject timeline = new JObject();
  86. // 水印开始显示时间
  87. timeline.Add("Start", "2");
  88. // 水印结束显示时间
  89. timeline.Add("Duration", "ToEND");
  90. watermarkConfig.Add("Timeline", timeline);
  91. return watermarkConfig.ToString();
  92. }
  93. /// <summary>
  94. /// 构建文字水印的配置数据,根据具体设置需求修改对应的参数值
  95. /// </summary>
  96. /// <returns>The text watermark config.</returns>
  97. public static string BuildTextWatermarkConfig()
  98. {
  99. JObject watermarkConfig = new JObject();
  100. // 文字水印显示的内容
  101. watermarkConfig.Add("Content", "testwatermark");
  102. // 文字水印的字体名称
  103. watermarkConfig.Add("FontName", "SimSun");
  104. // 文字水印的字体大小
  105. watermarkConfig.Add("FontSize", 25);
  106. // 文字水印的颜色(也可为RGB颜色取值,例如:#000000)
  107. watermarkConfig.Add("FontColor", "Black");
  108. // 文字水印的透明度
  109. watermarkConfig.Add("FontAlpha", "0.2");
  110. // 文字水印的字体描边颜色(也可为RGB颜色取值,例如:#ffffff)
  111. watermarkConfig.Add("BorderColor", "White");
  112. // 文字水印的描边宽度
  113. watermarkConfig.Add("BorderWidth", 1);
  114. // 文字水印距离视频画面上边的偏移距离
  115. watermarkConfig.Add("Top", 20);
  116. // 文字水印距离视频画面左边的偏移距离
  117. watermarkConfig.Add("Left", 15);
  118. return watermarkConfig.ToString();
  119. }
  120. }
  121. }

修改水印

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

  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.UpdateWatermark
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// 主函数
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. UpdateWatermarkResponse response = UpdateWatermark(client);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. }
  23. catch (ServerException e)
  24. {
  25. if (e.RequestId != null)
  26. {
  27. Console.WriteLine("RequestId = " + e.RequestId);
  28. }
  29. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  30. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  31. }
  32. catch (ClientException e)
  33. {
  34. if (e.RequestId != null)
  35. {
  36. Console.WriteLine("RequestId = " + e.RequestId);
  37. }
  38. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  39. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  40. }
  41. catch (Exception e)
  42. {
  43. Console.WriteLine("ErrorMessage = " + e.ToString());
  44. }
  45. }
  46. /// <summary>
  47. /// 更新水印
  48. /// </summary>
  49. /// <returns>The watermark.</returns>
  50. /// <param name="client">Client.</param>
  51. public static UpdateWatermarkResponse UpdateWatermark(DefaultAcsClient client)
  52. {
  53. // 构造请求
  54. UpdateWatermarkRequest request = new UpdateWatermarkRequest();
  55. // 水印名称
  56. request.Name = "updateWatermark";
  57. // 需要更新配置信息的水印ID
  58. request.WatermarkId = "421ddddd4f6e734a526fd2e442";
  59. // 图片水印的位置配置数据
  60. request.WatermarkConfig = BuildImageWatermarkConfig();
  61. // 文字水印的位置配置数据
  62. // request.WatermarkConfig = BuildTextWatermarkConfig();
  63. return client.GetAcsResponse(request);
  64. }
  65. /// <summary>
  66. /// 构建图片水印的配置数据,根据具体设置需求修改对应的参数值
  67. /// </summary>
  68. /// <returns>The image watermark config.</returns>
  69. public static string BuildImageWatermarkConfig()
  70. {
  71. JObject watermarkConfig = new JObject();
  72. // 水印的横向偏移距离
  73. watermarkConfig.Add("Dx", "8");
  74. // 水印的纵向偏移距离
  75. watermarkConfig.Add("Dy", "8");
  76. // 水印显示的宽
  77. watermarkConfig.Add("Width", "55");
  78. // 水印显示的高
  79. watermarkConfig.Add("Height", "55");
  80. // 水印显示的相对位置(左上、右上、左下、右下)
  81. watermarkConfig.Add("ReferPos", "BottomRight");
  82. // 水印显示的时间线(开始显示和结束显示时间)
  83. JObject timeline = new JObject();
  84. // 水印开始显示时间
  85. timeline.Add("Start", "2");
  86. // 水印结束显示时间
  87. timeline.Add("Duration", "ToEND");
  88. watermarkConfig.Add("Timeline", timeline);
  89. return watermarkConfig.ToString();
  90. }
  91. /// <summary>
  92. /// 构建文字水印的配置数据,根据具体设置需求修改对应的参数值
  93. /// </summary>
  94. /// <returns>The text watermark config.</returns>
  95. public static string BuildTextWatermarkConfig()
  96. {
  97. JObject watermarkConfig = new JObject();
  98. // 文字水印显示的内容
  99. watermarkConfig.Add("Content", "testwatermark");
  100. // 文字水印的字体名称
  101. watermarkConfig.Add("FontName", "SimSun");
  102. // 文字水印的字体大小
  103. watermarkConfig.Add("FontSize", 25);
  104. // 文字水印的颜色(也可为RGB颜色取值,例如:#000000)
  105. watermarkConfig.Add("FontColor", "Black");
  106. // 文字水印的透明度
  107. watermarkConfig.Add("FontAlpha", "0.2");
  108. // 文字水印的字体描边颜色(也可为RGB颜色取值,例如:#ffffff)
  109. watermarkConfig.Add("BorderColor", "White");
  110. // 文字水印的描边宽度
  111. watermarkConfig.Add("BorderWidth", 1);
  112. // 文字水印距离视频画面上边的偏移距离
  113. watermarkConfig.Add("Top", 20);
  114. // 文字水印距离视频画面左边的偏移距离
  115. watermarkConfig.Add("Left", 15);
  116. return watermarkConfig.ToString();
  117. }
  118. }
  119. }

删除水印

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

  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.DeleteWatermark
  6. {
  7. class MainClass
  8. {
  9. /// <summary>
  10. /// 主函数
  11. /// </summary>
  12. /// <param name="args">The command-line arguments.</param>
  13. public static void Main(string[] args)
  14. {
  15. try
  16. {
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. DeleteWatermarkResponse response = DeleteWatermark(client);
  20. Console.WriteLine("RequestId = " + response.RequestId);
  21. }
  22. catch (ServerException e)
  23. {
  24. if (e.RequestId != null)
  25. {
  26. Console.WriteLine("RequestId = " + e.RequestId);
  27. }
  28. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  29. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  30. }
  31. catch (ClientException e)
  32. {
  33. if (e.RequestId != null)
  34. {
  35. Console.WriteLine("RequestId = " + e.RequestId);
  36. }
  37. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  38. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  39. }
  40. catch (Exception e)
  41. {
  42. Console.WriteLine("ErrorMessage = " + e.ToString());
  43. }
  44. }
  45. /// <summary>
  46. /// 删除水印配置信息函数
  47. /// </summary>
  48. /// <returns>The watermark response.</returns>
  49. /// <param name="client">Client.</param>
  50. public static DeleteWatermarkResponse DeleteWatermark(DefaultAcsClient client)
  51. {
  52. // 构造请求
  53. DeleteWatermarkRequest request = new DeleteWatermarkRequest();
  54. // 水印ID
  55. request.WatermarkId = "53f9d796fad9d7b862b2e5e5b";
  56. return client.GetAcsResponse(request);
  57. }
  58. }
  59. }

查询水印列表

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

  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.ListWatermark
  6. {
  7. class MainClass
  8. {
  9. /// <summary>
  10. /// 主函数
  11. /// </summary>
  12. /// <param name="args">The command-line arguments.</param>
  13. public static void Main(string[] args)
  14. {
  15. try
  16. {
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. ListWatermarkResponse response = ListWatermark(client);
  20. if (response.WatermarkInfos != null && response.WatermarkInfos.Count > 0)
  21. {
  22. foreach (ListWatermarkResponse.ListWatermark_WatermarkInfo watermarkInfo in response.WatermarkInfos)
  23. {
  24. //水印ID
  25. Console.WriteLine("WatermarkId = " + watermarkInfo.WatermarkId);
  26. //水印的位置、效果配置数据
  27. Console.WriteLine("WatermarkConfig = " + watermarkInfo.WatermarkConfig);
  28. //水印文件的FileUrl(文字水印该字段值为空)
  29. Console.WriteLine("FileUrl = " + watermarkInfo.FileUrl);
  30. }
  31. }
  32. Console.WriteLine("RequestId = " + response.RequestId);
  33. }
  34. catch (ServerException 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 (ClientException e)
  44. {
  45. if (e.RequestId != null)
  46. {
  47. Console.WriteLine("RequestId = " + e.RequestId);
  48. }
  49. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  50. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  51. }
  52. catch (Exception e)
  53. {
  54. Console.WriteLine("ErrorMessage = " + e.ToString());
  55. }
  56. }
  57. /// <summary>
  58. /// 获取水印列表
  59. /// </summary>
  60. /// <returns>The watermark list.</returns>
  61. /// <param name="client">Client.</param>
  62. public static ListWatermarkResponse ListWatermark(DefaultAcsClient client)
  63. {
  64. // 构造请求
  65. ListWatermarkRequest request = new ListWatermarkRequest();
  66. return client.GetAcsResponse(request);
  67. }
  68. }
  69. }

查询单个水印

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

  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.GetWatermark
  6. {
  7. class MainClass
  8. {
  9. /// <summary>
  10. /// 主函数
  11. /// </summary>
  12. /// <param name="args">The command-line arguments.</param>
  13. public static void Main(string[] args)
  14. {
  15. try
  16. {
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. GetWatermarkResponse response = GetWatermark(client);
  20. if (response.WatermarkInfo != null)
  21. {
  22. //水印ID
  23. Console.WriteLine("WatermarkId = " + response.WatermarkInfo.WatermarkId);
  24. //水印的位置、效果配置数据
  25. Console.WriteLine("WatermarkConfig = " + response.WatermarkInfo.WatermarkConfig);
  26. //水印文件的FileUrl(文字水印该字段值为空)
  27. Console.WriteLine("FileUrl = " + response.WatermarkInfo.FileUrl);
  28. }
  29. Console.WriteLine("RequestId = " + response.RequestId);
  30. }
  31. catch (ServerException e)
  32. {
  33. if (e.RequestId != null)
  34. {
  35. Console.WriteLine("RequestId = " + e.RequestId);
  36. }
  37. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  38. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  39. }
  40. catch (ClientException e)
  41. {
  42. if (e.RequestId != null)
  43. {
  44. Console.WriteLine("RequestId = " + e.RequestId);
  45. }
  46. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  47. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  48. }
  49. catch (Exception e)
  50. {
  51. Console.WriteLine("ErrorMessage = " + e.ToString());
  52. }
  53. }
  54. /// <summary>
  55. /// 查询单个水印配置信息函数
  56. /// </summary>
  57. /// <returns>The watermark.</returns>
  58. /// <param name="client">Client.</param>
  59. public static GetWatermarkResponse GetWatermark(DefaultAcsClient client)
  60. {
  61. // 构造请求
  62. GetWatermarkRequest request = new GetWatermarkRequest();
  63. //需要查询水印信息的水印ID
  64. request.WatermarkId = "96d4f6e734a526fd2e442";
  65. return client.GetAcsResponse(request);
  66. }
  67. }
  68. }

设置默认水印

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

  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.SetDefaultWatermark
  6. {
  7. class MainClass
  8. {
  9. /// <summary>
  10. /// 主函数
  11. /// </summary>
  12. /// <param name="args">The command-line arguments.</param>
  13. public static void Main(string[] args)
  14. {
  15. try
  16. {
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. SetDefaultWatermarkResponse response = SetDefaultWatermark(client);
  20. Console.WriteLine("RequestId = " + response.RequestId);
  21. }
  22. catch (ServerException e)
  23. {
  24. if (e.RequestId != null)
  25. {
  26. Console.WriteLine("RequestId = " + e.RequestId);
  27. }
  28. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  29. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  30. }
  31. catch (ClientException e)
  32. {
  33. if (e.RequestId != null)
  34. {
  35. Console.WriteLine("RequestId = " + e.RequestId);
  36. }
  37. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  38. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  39. }
  40. catch (Exception e)
  41. {
  42. Console.WriteLine("ErrorMessage = " + e.ToString());
  43. }
  44. }
  45. /// <summary>
  46. /// 设置默认水印配置信息函数
  47. /// </summary>
  48. /// <returns>The default watermark.</returns>
  49. /// <param name="client">Client.</param>
  50. public static SetDefaultWatermarkResponse SetDefaultWatermark(DefaultAcsClient client)
  51. {
  52. // 构造请求
  53. SetDefaultWatermarkRequest request = new SetDefaultWatermarkRequest();
  54. // 设置默认的水印ID
  55. request.WatermarkId = "82105a29c6e96d4f6e734a";
  56. return client.GetAcsResponse(request);
  57. }
  58. }
  59. }