Snapshot templates
Video snapshots are generated from snapshot templates. By configuring a snapshot template, you can customize the size, count, and time of the snapshots. This topic provides sample Python SDK calls for the snapshot template API operations, including how to create and manage snapshot templates.
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 the client
Before you use the SDK, initialize a client instance. For more information, see Initialization.
Add a snapshot template
Call the AddVodTemplate operation to generate the SDK sample for adding a snapshot template.
Alibaba Cloud OpenAPI Portal: AddVodTemplate.
The following is a sample call:
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. The value is fixed to Snapshot.
request.set_TemplateType('Snapshot')
# Snapshot template configuration
snapshotConfig = {'Count': 50, 'Interval': 1, 'SpecifiedOffsetTime': 0, 'Width': 200, 'Height': 200,
'FrameType': 'normal'}
templateConfig = {'SnapshotConfig': snapshotConfig, 'SnapshotType': 'NormalSnapshot'}
"""
# Optional: sprite snapshot configuration. A sprite snapshot must be configured based on a normal snapshot.
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
Call the UpdateVodTemplate operation to generate the SDK sample for modifying a snapshot template.
Alibaba Cloud OpenAPI Portal: UpdateVodTemplate .
The following is a sample call:
from aliyunsdkvod.request.v20170321 import UpdateVodTemplateRequest
import json
import traceback
def update_vod_template(clt):
request = UpdateVodTemplateRequest.UpdateVodTemplateRequest()
request.set_VodTemplateId('<templateId>')
# New template name
request.set_Name('New Snapshot Template Name')
# New snapshot template 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())
Query snapshot templates
-
Call the GetVodTemplate operation to query a snapshot template.
Alibaba Cloud OpenAPI Portal: GetVodTemplate.
-
Call the ListVodTemplate operation to query a list of snapshot templates.
Alibaba Cloud OpenAPI Portal: ListVodTemplate.
Delete a snapshot template
Call the DeleteVodTemplate operation to generate the SDK sample for deleting a snapshot template.
Alibaba Cloud OpenAPI Portal: DeleteVodTemplate .
References
-
Video screenshots: Supported screenshot types and usage instructions for ApsaraVideo VOD.
-
Snapshot jobs and template management and Query media snapshot data provide complete SDK sample code for video snapshots.