All Products
Search
Document Center

ApsaraVideo VOD:Video watermarks

Last Updated:Sep 22, 2026

This topic provides examples on how to use the API operations of the video watermark module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to add, modify, delete, and query watermarks. You can also specify a watermark as the default one.

Usage notes

  • All examples in this topic use an AccessKey pair to initialize a client instance.

  • For request and response parameter details, visit Alibaba Cloud OpenAPI Explorer and open the API Documentations tab.

  • For SDK examples of other API operations, visit Alibaba Cloud OpenAPI Explorer. On the Parameters tab, specify the parameters and initiate the call. Then select the SDK version and language on the SDK Sample Code tab to view and download the code.

  • The examples in this topic use SDK V1.0. For V2.0 examples, select the correct SDK version in OpenAPI Explorer.

Initialize a client

Before you use the SDK, initialize a client. For more information, see Initialization.

Add a watermark

You can call the AddWatermark operation to add a watermark.

OpenAPI Portal: or AddWatermark.

Sample code:

Note
  • For more information about the file upload URL and credential, see CreateUploadAttachedMedia.

  • For more information about how to upload a watermark file to an Object Storage Service (OSS) bucket, see Upload OSS objects.

from aliyunsdkvod.request.v20170321 import AddWatermarkRequest
def add_watermark(clt):
    request = AddWatermarkRequest.AddWatermarkRequest()

    request.set_Name('watermark-sample')
    # If you want to use an image watermark, the image must be stored in an OSS bucket and the image file and source video file must be stored in the same region, such as China (Shanghai).
    # Example of FileUrl: http://example-bucket-****.oss-cn-shanghai.aliyuncs.com/watermark/test-****.png.  
    request.set_FileUrl('<your File URL>')

    # Example on how to configure a text watermark:
    request.set_Type('Text')
    # Specify the text content, font, size, color, transparency, and other configurations.
    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))

    """
    # Example on how to configure an image watermark:
    request.set_Type('Image')
    # The start time and duration of the watermark.
    timeline = {'Start': 2, 'Duration': 'ToEND'}
    # The position configurations of the 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()
    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

You can call the UpdateWatermark operation to modify a watermark.

OpenAPI Portal: | UpdateWatermark.

Sample code:

Important

You cannot call this operation to modify the URL of the image watermark. If you want to modify the URL of the image watermark, create a watermark.

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

    # Example on how to modify a text watermark:
    # Specify the text content, font, size, color, transparency, and other configurations.
    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))

    """
    # Example on how to modify an image watermark:
    # The start time and duration of the watermark.
    timeline = {'Start': 2, 'Duration': 'ToEND'}
    # The position configurations of the 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()
    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

You can call the DeleteWatermark operation to delete a watermark.

OpenAPI Portal: / DeleteWatermark.

Query watermarks

  • You can call the GetWatermark operation to query the details about a single watermark.

    OpenAPI Portal: GetWatermark.

  • You can call the ListWatermark operation to query multiple watermarks.

    OpenAPI Portal: ListWatermark.

Specify a watermark as the default one

You can call the SetDefaultWatermark operation to specify a watermark as the default one.

OpenAPI Portal: SetDefaultWatermark.