Help Center/ Media Processing Center/ API Reference/ Application Examples/ Example 3: Submit a Video Snapshot Task
Updated on 2024-03-14 GMT+08:00

Example 3: Submit a Video Snapshot Task

Scenario

You can set snapshot parameters when submitting a video transcoding task for taking snapshots during transcoding. If you only want to take snapshots from a video file without transcoding, you can call the API for taking snapshots.

This section describes how to submit a video snapshot task by invoking an API.

Constraints

Cross-region transcoding is not supported. For example, MPC in the CN North-Beijing1 region cannot transcode video files stored in an OBS bucket in the CN North-Beijing4 region.

Prerequisites

  • You have obtained the project ID of the region where the snapshot task is to be created. For details, see Obtaining a Project ID.
  • You have determined the region where the snapshot capturing task to be created is located and obtained the endpoint of MPC for this region from the Regions and Endpoints.
  • You have stored the video file for which snapshots will be captured in an OBS bucket. If you have not, call the API for uploading an object to upload the file.
  • You have created an OBS bucket where snapshots will be stored. If you have not, call the API for creating a bucket.

Procedure

  1. Obtain a user token and use it to authenticate the calling of MPC APIs.

    Obtain the username, password, domainname, and projectname from the My Credentials page. Call the following API to obtain the token. For details, see Making an API Request.
    POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens
    Content-Type: application/json
    {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "********", //Username
              "password": "********", //Login password
              "domain": {
                "name": "domainname" //Name of the account to which the user belongs
              }
            }
          }
        },
        "scope": {
          "project": {
             "name": "*******"  //Project name
          }
        }
      }
    }

    As shown in Figure 1, information in the red box indicates the user token.

    Figure 1 Obtaining a user token

  2. Create a snapshot task.

    1. Select the POST request method and enter the request URI.
      https://{endpoint}/v1/{project_id}/thumbnails
    2. In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
    3. Specify the following parameters in the request body:
      {
      "input": {
                 "bucket": "example-bucket",
                 "location": "region01",
                 "object": "/mpc/input/sample.MP4"
      },
      "output": {
                 "bucket": "example-bucket",
                 "location": "region01",
                 "object": "/mpc/output/ "},
      
      "tar": 1,
      "thumbnail_para": {   
      		"type":"DOTS",
      		"dots":[2,4,6,8,10],      
      		"format":0,    
      		"aspect_ratio":1,     
      		"max_length":480  
      		} 
      } 
    4. If the request succeeds, the snapshot task ID is returned.
      {
          "task_id": "2081"
      }

  3. Query the task status.

    1. Select the GET request method and enter the request URI.
      https://{endpoint}/v1/{project_id}/thumbnails?task_id=2081
    2. In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
    3. If the request succeeds, details about the snapshot task are returned.