All Products
Search
Document Center

ApsaraVideo VOD:Snapshot templates

Last Updated:Aug 22, 2023

This topic provides examples on how to use the API operations of the snapshot template module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to create, delete, modify, and query snapshot templates.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

Initialize a client

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

Create a snapshot template

You can call the AddVodTemplate operation to create a snapshot template.

Click AddVodTemplate to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import AddVodTemplateRequest
def add_vod_template(clt):
    request = AddVodTemplateRequest.AddVodTemplateRequest()
    # The name of the template.
    request.set_Name('Sample Snapshot Template')
    # The type of the template type. Set the value to Snapshot.
    request.set_TemplateType('Snapshot')

    # The template configurations.
    snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
                      'FrameType': 'normal'}
    templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}

    """
    # Optional: The configurations of image sprites. The configurations of normal snapshots are included.
    spriteSnapshotConfig = {'CellWidth': 120, 'CellHeight': 68, 'Columns': 3, 'Lines': 10, 'Padding': 20,
                            'Margin': 50, 'KeepCellPic': 'keep', 'Color': 'tomato'}
    snapshotConfig['SpriteSnapshotConfig'] = spriteSnapshotConfig
    templateConfig['SnapshotType'] = 'SpriteSnapshot'
    """

    request.set_TemplateConfig(json.dumps(templateConfig))


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

try:
    clt = init_vod_client()
    template = add_vod_template(clt)
    print(template['VodTemplateId'])
    print(json.dumps(template, ensure_ascii=False, indent=4))

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

Modify a snapshot template

You can call the UpdateVodTemplate operation to modify a snapshot template.

Click UpdateVodTemplate to learn more about this API operation.

Sample code:

from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
def update_vod_template(clt):
    request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
    request.set_VodTemplateId('<templateId>')
    # Modify the template name.
    request.set_Name('New Snapshot Template Name')
    # Modify the configurations of the snapshot template.
    snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
                      'FrameType': 'normal'}
    templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
    request.set_TemplateConfig(json.dumps(templateConfig))

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

try:
    clt = init_vod_client()
    template = update_vod_template(clt)
    print(json.dumps(template, ensure_ascii=False, indent=4))

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

Query a snapshot template

  • You can call the GetVodTemplate operation to query a snapshot template.

    Click GetVodTemplate to learn more about this API operation.

  • You can call the ListVodTemplate operation to query a list of snapshot templates.

    Click ListVodTemplate to learn more about this API operation.

Delete a snapshot template

You can call the DeleteVodTemplate operation to delete a snapshot template.

Click DeleteVodTemplate to learn more about this API operation.