All Products
Search
Document Center

Intelligent Media Services:Snapshot jobs

Last Updated:Jun 16, 2026

This topic provides sample code that demonstrates how to use a server-side software development kit (SDK) to call OpenAPI to submit and query snapshot jobs in Intelligent Media Services.

Usage notes

Before you submit a snapshot job, you must create a snapshot template. Use the TemplateId (snapshot template ID) to submit the job. When you submit the job, you can overwrite and reset the template parameters. After the job is processed, use the returned JobId (job ID) to query job details, retrieve a list of snapshot jobs, and obtain the access URLs for the snapshots.

Sample code

Use Alibaba Cloud OpenAPI Explorer to debug API calls online.

import json
import os
import sys
from typing import List

from alibabacloud_ice20201109.client import Client as ICE20201109Client
# Import Alibaba Cloud IMS SDK.
from alibabacloud_ice20201109 import models as ice20201109_models
# Import a client for credentials and SDKs of cloud services and create an alias for the client.
from alibabacloud_credentials.client import Client as CredClient
# Import the core package of Alibaba Cloud SDKs.
from alibabacloud_tea_openapi.models import Config


#######Required dependencies#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:

    # Initialize the client.
    @staticmethod
    def create_client(region: str) -> ICE20201109Client:
        # Use the default credential to initialize the credentials client.        
        cred = CredClient()
        config = Config(credential = cred)
        # Specify the endpoint of the cloud service.        
        config.endpoint = 'ice.' + region + '.aliyuncs.com'

        # Use the credentials client to initialize the ECS SDK client.        
        return ICE20201109Client(config)

    # @staticmethod
    # def create_client(
    #     access_key_id: str,
    #     access_key_secret: str,
    #     region: str,

    # ) -> ICE20201109Client:
    #     To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised.
    #     config = open_api_models.Config(
    #         # Required. Specify your AccessKey ID.
    #         access_key_id = access_key_id,
    #         # Required. Specify your AccessKey secret.
    #         access_key_secret = access_key_secret
    #     )
    #     # Specify the endpoint that you want to access.
    #     config.endpoint = 'ice.' + region + '.aliyuncs.com'
    #     return ICE20201109Client(config)

    # Read command line parameters.
    @staticmethod
    def main() -> None:
        region = 'cn-shanghai'
        # Initialize the client.
        client = Sample.create_client(region)

        # Create a snapshot template.
        snapshot_template_config = '{"Type":"Normal","FrameType":"normal","Time":0,"Count":10}'
        create_custom_template_request = ice20201109_models.CreateCustomTemplateRequest(
            name = 'sdk_sample_snapshot_template',
            type = 2,
            template_config = snapshot_template_config
        )
        create_custom_template_response = client.create_custom_template(create_custom_template_request)
        print('[LOG]', json.dumps(create_custom_template_response.to_map()))
        template_id = create_custom_template_response.body.custom_template.template_id

        # Initiate a snapshot job.
        submit_snapshot_job_request = ice20201109_models.SubmitSnapshotJobRequest(
            name = 'sdk_sample_snapshot_job',
            input = ice20201109_models.SubmitSnapshotJobRequestInput(
                type = 'Media',
                media = '3945e42d-1823498****'
            ),
            output = ice20201109_models.SubmitSnapshotJobRequestOutput(
                type = 'Media',
                media = '3945e42d-1823498****'
            ),
            template_config = ice20201109_models.SubmitSnapshotJobRequestTemplateConfig(
                template_id = template_id
            )
        )
        submit_snapshot_job_response = client.submit_snapshot_job(submit_snapshot_job_request)
        print('[LOG]', json.dumps(submit_snapshot_job_response.to_map()))

        job_id = submit_snapshot_job_response.body.job_id
        # Query the details of the snapshot job.
        get_snapshot_job_request = ice20201109_models.GetSnapshotJobRequest(
            job_id=job_id
        )
        get_snapshot_job_response = client.get_snapshot_job(get_snapshot_job_request)
        print('[LOG]', json.dumps(get_snapshot_job_response.to_map()))

        # Obtain the snapshot job list.
        list_snapshot_jobs_request = ice20201109_models.ListSnapshotJobsRequest(
            page_size=5
        )
        list_snapshot_jobs_response = client.list_snapshot_jobs(list_snapshot_jobs_request)
        print('[LOG]', json.dumps(list_snapshot_jobs_response.to_map()))

        # Obtain the URL of the output snapshot of the snapshot job.
        get_snapshot_urls_request = ice20201109_models.GetSnapshotUrlsRequest(
            job_id='20b48fb04483915d4f2cd8ac****',
            page_size=5
        )
        get_snapshot_urls_response = client.get_snapshot_urls(get_snapshot_urls_request)
        print('[LOG]', json.dumps(get_snapshot_urls_response.to_map()))

if __name__ == '__main__':
    Sample.main()

Related API operations