All Products
Search
Document Center

Watermark

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see init_vod_client.

Add a watermark

For more information about the request and response parameters, see AddWatermark.

  • For more information about how to obtain the upload URL and credential for a file, see CreateUploadAttachedMedia.
  • For more information about how to upload a watermark file to Object Storage Service (OSS), see OSS upload.
from aliyunsdkvod.request.v20170321 import AddWatermarkRequest
def add_watermark(clt):
    request = AddWatermarkRequest.AddWatermarkRequest()

    request.set_Name('watermark-sample')
    # The OSS URL must be specified for an image watermark file. This watermark file must be stored in the same region as the relevant video. For example, if a video is stored in China (Shanghai), its watermark file must also be stored in China (Shanghai).
    request.set_FileUrl('http://sample.oss-cn-shanghai.aliyuncs.com/watermark/test.png')

    # Specifies the configuration of a text watermark.
    request.set_Type('Text')
    # Specifies the content, font, font size, color, transparency, and other configurations of the text watermark.
    watermarkConfig = {'Content': 'watermark Text', 'FontName': 'SimSun', 'FontSize': 25, 'FontColor': 'Black',
                       'FontAlpha': 0.2, 'BorderColor': 'White', 'BorderWidth': 1, 'Top': 20, 'Left': 15}
    request.set_WatermarkConfig(json.dumps(watermarkConfig))

    """
    # Specifies the configuration of an image watermark.
    request.set_Type('Image')
    # Sets the start time and end time for watermark display.
    timeline = {'Start': 2, 'Duration': 'ToEND'}
    # Specifies the display position and other configurations of the image watermark.
    watermarkConfig = {'Dx': 8, 'Dy': 8, 'Width': 55, 'Height': 55, 'ReferPos': 'BottomRight', 'Timeline': timeline}
    request.set_WatermarkConfig(json.dumps(watermarkConfig))
    """

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    watermark = add_watermark(clt)
    print(json.dumps(watermark, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Modify a watermark

For more information about the request and response parameters, see UpdateWatermark.

Note: The URL of an image watermark file cannot be directly modified. If you want to modify the URL, you need to create watermark information again and set the new URL in the information.

from aliyunsdkvod.request.v20170321 import UpdateWatermarkRequest
def update_watermark(clt):
    request = UpdateWatermarkRequest.UpdateWatermarkRequest()
    request.set_WatermarkId('<watermarkId>') 
    request.set_Name('new-watermark-name')

    # Modifies the configuration of a text watermark.
    # Specifies the content, font, font size, color, transparency, and other configurations of the text watermark.
    watermarkConfig = {'Content': 'watermark Text', 'FontName': 'SimSun', 'FontSize': 25, 'FontColor': 'Black',
                       'FontAlpha': 0.2, 'BorderColor': 'White', 'BorderWidth': 1, 'Top': 20, 'Left': 15}
    request.set_WatermarkConfig(json.dumps(watermarkConfig))

    """
    # Modifies the configuration of an image watermark.
    # Sets the start time and end time for watermark display.
    timeline = {'Start': 2, 'Duration': 'ToEND'}
    # Specifies the display position and other configurations of the image watermark.
    watermarkConfig = {'Dx': 8, 'Dy': 8, 'Width': 55, 'Height': 55, 'ReferPos': 'BottomRight', 'Timeline': timeline}
    request.set_WatermarkConfig(json.dumps(watermarkConfig))
    """

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    watermark = update_watermark(clt)
    print(json.dumps(watermark, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Delete a watermark

For more information about the request and response parameters, see DeleteWatermark.

from aliyunsdkvod.request.v20170321 import DeleteWatermarkRequest
def delete_watermark(clt):
    request = DeleteWatermarkRequest.DeleteWatermarkRequest()
    request.set_WatermarkId('<watermarkId>')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = delete_watermark(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query a list of watermarks

For more information about the request and response parameters, see ListWatermark.

from aliyunsdkvod.request.v20170321 import ListWatermarkRequest
def list_watermark(clt):
    request = ListWatermarkRequest.ListWatermarkRequest()
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    watermarks = list_watermark(clt)
    print(watermarks['WatermarkInfos'])
    print(json.dumps(watermarks, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Query a watermark

For more information about the request and response parameters, see GetWatermark.

from aliyunsdkvod.request.v20170321 import GetWatermarkRequest
def get_watermark(clt):
    request = GetWatermarkRequest.GetWatermarkRequest()
    request.set_WatermarkId('<watermarkId>')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    watermark = get_watermark(clt)
    print(watermark['WatermarkInfo'])
    print(json.dumps(watermark, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

Set the default watermark

For more information about the request and response parameters, see SetDefaultWatermark.

from aliyunsdkvod.request.v20170321 import SetDefaultWatermarkRequest
def set_default_watermark(clt):
    request = SetDefaultWatermarkRequest.SetDefaultWatermarkRequest()
    request.set_WatermarkId('<watermarkId>')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>') 
    res = set_default_watermark(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())