全部产品
云市场

视频水印

更新时间:2018-12-27 18:36:06

初始化客户端

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

添加水印

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

  1. from aliyunsdkvod.request.v20170321 import AddWatermarkRequest
  2. def add_watermark(clt):
  3. request = AddWatermarkRequest.AddWatermarkRequest()
  4. request.set_Name('watermark-sample')
  5. # 图片水印必须传图片文件的OSS地址,且水印文件需要和视频在同一区域,如:华东2的视频添加水印,水印文件必须存放在华东2
  6. request.set_FileUrl('http://sample.oss-cn-shanghai.aliyuncs.com/watermark/test.png')
  7. # 文字水印设置示例
  8. request.set_Type('Text')
  9. # 水印的文本内容、字体、大小、颜色、透明度等配置
  10. watermarkConfig = {'Content': 'watermark Text', 'FontName': 'SimSun', 'FontSize': 25, 'FontColor': 'Black',
  11. 'FontAlpha': 0.2, 'BorderColor': 'White', 'BorderWidth': 1, 'Top': 20, 'Left': 15}
  12. request.set_WatermarkConfig(json.dumps(watermarkConfig))
  13. """
  14. # 图片水印设置示例
  15. request.set_Type('Image')
  16. # 水印显示的开始时间和结束时间
  17. timeline = {'Start': 2, 'Duration': 'ToEND'}
  18. # 水印的位置等配置
  19. watermarkConfig = {'Dx': 8, 'Dy': 8, 'Width': 55, 'Height': 55, 'ReferPos': 'BottomRight', 'Timeline': timeline}
  20. request.set_WatermarkConfig(json.dumps(watermarkConfig))
  21. """
  22. request.set_accept_format('JSON')
  23. response = json.loads(clt.do_action_with_exception(request))
  24. return response
  25. try:
  26. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  27. watermark = add_watermark(clt)
  28. print(json.dumps(watermark, ensure_ascii=False, indent=4))
  29. except Exception as e:
  30. print(e)
  31. print(traceback.format_exc())

修改水印

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

注:本接口不支持图片水印图片文件地址的修改,如要更换请创建新的水印。

  1. from aliyunsdkvod.request.v20170321 import UpdateWatermarkRequest
  2. def update_watermark(clt):
  3. request = UpdateWatermarkRequest.UpdateWatermarkRequest()
  4. request.set_WatermarkId('<watermarkId>')
  5. request.set_Name('new-watermark-name')
  6. # 更改文字水印设置示例
  7. # 水印的文本内容、字体、大小、颜色、透明度等配置
  8. watermarkConfig = {'Content': 'watermark Text', 'FontName': 'SimSun', 'FontSize': 25, 'FontColor': 'Black',
  9. 'FontAlpha': 0.2, 'BorderColor': 'White', 'BorderWidth': 1, 'Top': 20, 'Left': 15}
  10. request.set_WatermarkConfig(json.dumps(watermarkConfig))
  11. """
  12. # 更改图片水印设置示例
  13. # 水印显示的开始时间和结束时间
  14. timeline = {'Start': 2, 'Duration': 'ToEND'}
  15. # 水印的位置等配置
  16. watermarkConfig = {'Dx': 8, 'Dy': 8, 'Width': 55, 'Height': 55, 'ReferPos': 'BottomRight', 'Timeline': timeline}
  17. request.set_WatermarkConfig(json.dumps(watermarkConfig))
  18. """
  19. request.set_accept_format('JSON')
  20. response = json.loads(clt.do_action_with_exception(request))
  21. return response
  22. try:
  23. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  24. watermark = update_watermark(clt)
  25. print(json.dumps(watermark, ensure_ascii=False, indent=4))
  26. except Exception as e:
  27. print(e)
  28. print(traceback.format_exc())

删除水印

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

  1. from aliyunsdkvod.request.v20170321 import DeleteWatermarkRequest
  2. def delete_watermark(clt):
  3. request = DeleteWatermarkRequest.DeleteWatermarkRequest()
  4. request.set_WatermarkId('<watermarkId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. res = delete_watermark(clt)
  11. print(json.dumps(res, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

查询水印列表

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

  1. from aliyunsdkvod.request.v20170321 import ListWatermarkRequest
  2. def list_watermark(clt):
  3. request = ListWatermarkRequest.ListWatermarkRequest()
  4. request.set_accept_format('JSON')
  5. response = json.loads(clt.do_action_with_exception(request))
  6. return response
  7. try:
  8. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  9. watermarks = list_watermark(clt)
  10. print(watermarks['WatermarkInfos'])
  11. print(json.dumps(watermarks, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())

查询单个水印

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

  1. from aliyunsdkvod.request.v20170321 import GetWatermarkRequest
  2. def get_watermark(clt):
  3. request = GetWatermarkRequest.GetWatermarkRequest()
  4. request.set_WatermarkId('<watermarkId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. watermark = get_watermark(clt)
  11. print(watermark['WatermarkInfo'])
  12. print(json.dumps(watermark, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

设置默认水印

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

  1. from aliyunsdkvod.request.v20170321 import SetDefaultWatermarkRequest
  2. def set_default_watermark(clt):
  3. request = SetDefaultWatermarkRequest.SetDefaultWatermarkRequest()
  4. request.set_WatermarkId('<watermarkId>')
  5. request.set_accept_format('JSON')
  6. response = json.loads(clt.do_action_with_exception(request))
  7. return response
  8. try:
  9. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  10. res = set_default_watermark(clt)
  11. print(json.dumps(res, ensure_ascii=False, indent=4))
  12. except Exception as e:
  13. print(e)
  14. print(traceback.format_exc())