All Products
Search
Document Center

ApsaraVideo VOD:Snapshot templates

Last Updated:Feb 27, 2026

Manage snapshot templates with the ApsaraVideo VOD SDK for Python. The examples on this page use the aliyunsdkvod package to create, modify, query, and delete snapshot templates.

Prerequisites

Before you begin, make sure that you have:

  • Python 3.x installed

  • The aliyunsdkvod package installed

  • An AccessKey pair with ApsaraVideo VOD permissions

  • An initialized VOD client. For details, see Initialization

All examples on this page initialize the client by calling init_vod_client(). For the implementation, see the initialization guide linked above.

Usage notes

  • All examples authenticate with an AccessKey pair.

  • For request and response parameter details, see the API reference in OpenAPI Explorer. Click API Documentation in the top navigation bar for details.

  • To get sample code for other API operations, open OpenAPI Explorer, select an operation in the left-side navigation pane, specify parameters on the Parameters tab, click Initiate Call, and download code from the SDK Sample Code tab.

Snapshot configuration parameters

The create and modify examples share the same configuration structure. The following tables describe each parameter.

SnapshotConfig

ParameterTypeRequiredDescriptionExample
CountLongYesThe number of snapshots to capture.50
IntervalLongYesThe interval at which to capture snapshots, in seconds. A value of 0 indicates that snapshots are captured at even intervals based on the video duration and the value of Count.1
SpecifiedOffsetTimeLongYesThe start time for capturing snapshots, in milliseconds.0
WidthIntegerNoThe width of the snapshot, in pixels. Valid values: [8, 4096]. Default value: the width of the source video.200
HeightIntegerNoThe height of the snapshot, in pixels. Valid values: [8, 4096]. Default value: the height of the source video.200
FrameTypeStringYesThe frame type for snapshots. Valid values: intra (keyframe), normal (normal frame)."normal"

TemplateConfig

ParameterTypeDescriptionValid values
SnapshotConfigObjectThe snapshot configuration object.See the table above
SnapshotTypeStringThe snapshot type.NormalSnapshot, SpriteSnapshot

SpriteSnapshotConfig (optional)

To create a sprite snapshot template, add SpriteSnapshotConfig inside SnapshotConfig and set SnapshotType to SpriteSnapshot.

ParameterTypeRequiredDescriptionExample
CellWidthStringNoThe width of each small image in the sprite, in pixels. Default value: the width of a normal snapshot."120"
CellHeightStringNoThe height of each small image in the sprite, in pixels. Default value: the height of a normal snapshot."68"
ColumnsStringYesThe number of columns of small images. Valid values: [1, 10000]."3"
LinesStringYesThe number of rows of small images. Valid values: [1, 10000]."10"
PaddingStringYesThe padding of each small image, in pixels."20"
MarginStringYesThe margin of each small image, in pixels."50"
KeepCellPicStringYesSpecifies whether to retain individual cell images. Valid values: keep (retain), delete (remove)."keep"
ColorStringYesThe background color of the sprite image. For more information, see Color settings. Setting the color by using RGB values is not supported."tomato"

Create a snapshot template

Call AddVodTemplate to create a snapshot template. Set TemplateType to Snapshot.

For API details, see AddVodTemplate.

Normal snapshot template

from aliyunsdkvod.request.v20170321 import AddVodTemplateRequest
import json
import traceback

def add_vod_template(clt):
    request = AddVodTemplateRequest.AddVodTemplateRequest()
    # Template name
    request.set_Name('Sample Snapshot Template')
    # Template type: must be "Snapshot"
    request.set_TemplateType('Snapshot')

    # Snapshot configuration
    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 = add_vod_template(clt)
    # The response contains the template ID
    print(template['VodTemplateId'])
    print(json.dumps(template, ensure_ascii=False, indent=4))

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

Sprite snapshot template

To create a sprite snapshot template, add SpriteSnapshotConfig to the snapshot configuration and set SnapshotType to SpriteSnapshot:

# Sprite snapshot configuration (includes normal snapshot config)
snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
                  'FrameType': 'normal'}

# Add sprite-specific settings
spriteSnapshotConfig = {'CellWidth': 120, 'CellHeight': 68, 'Columns': 3, 'Lines': 10, 'Padding': 20,
                        'Margin': 50, 'KeepCellPic': 'keep', 'Color': 'tomato'}
snapshotConfig['SpriteSnapshotConfig'] = spriteSnapshotConfig

templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'SpriteSnapshot'}

Replace the snapshotConfig and templateConfig variables in the normal snapshot example above to create a sprite snapshot template.

Modify a snapshot template

Call UpdateVodTemplate to update an existing snapshot template. Specify the template ID with VodTemplateId.

For API details, see UpdateVodTemplate.

from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
import json
import traceback

def update_vod_template(clt):
    request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
    # Specify the template to update
    request.set_VodTemplateId('<templateId>')
    # Update the template name
    request.set_Name('New Snapshot Template Name')
    # Update the snapshot configuration
    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())

Replace <templateId> with the actual template ID returned when you created the template.

Query snapshot templates

ApsaraVideo VOD provides two query operations:

Query a single template

from aliyunsdkvod.request.v20170321 import GetVodTemplateRequest
import json
import traceback

def get_vod_template(clt):
    request = GetVodTemplateRequest.GetVodTemplateRequest()
    request.set_VodTemplateId('<templateId>')

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

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

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

List all snapshot templates

from aliyunsdkvod.request.v20170321 import ListVodTemplateRequest
import json
import traceback

def list_vod_template(clt):
    request = ListVodTemplateRequest.ListVodTemplateRequest()
    # Filter by template type
    request.set_TemplateType('Snapshot')

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

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

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

Delete a snapshot template

Call DeleteVodTemplate to delete a snapshot template by ID.

For API details, see DeleteVodTemplate.

from aliyunsdkvod.request.v20170321 import DeleteVodTemplateRequest
import json
import traceback

def delete_vod_template(clt):
    request = DeleteVodTemplateRequest.DeleteVodTemplateRequest()
    request.set_VodTemplateId('<templateId>')

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

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

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

References