Creating a Snapshot Task
Function
This API is used to create a task for capturing snapshots from the first to the last frame at every set interval. Ensure that an input media file is stored in an OBS bucket in the same region as MPC and the permission for accessing the OBS bucket has been granted to MPC.
Constraints: Currently, only JPG image files can be generated.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/thumbnails
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details about how to obtain the project ID, see Obtaining a Project ID . |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
No |
String |
User token The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. |
Authorization |
No |
String |
Authentication information. This parameter is mandatory when AK/SK-based authentication is used. |
X-Project_Id |
No |
String |
Project ID. This parameter is mandatory when AK/SK-based authentication is used. It is same as the project ID in path parameters. |
X-Sdk-Date |
No |
String |
Time when the request is sent. This parameter is mandatory when AK/SK-based authentication is used. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
input |
Yes |
ObsObjInfo object |
Storage location of an input file |
output |
Yes |
ObsObjInfo object |
Storage location of an output file |
user_data |
No |
String |
Custom user data |
thumbnail_para |
Yes |
ThumbnailPara object |
Snapshot parameters |
tar |
No |
Integer |
Whether to compress captured snapshots to a TAR package. Possible values:
|
sync |
No |
Integer |
Whether to enable synchronous processing. Synchronous processing quickly locates the snapshot position to capture a snapshot. The options are as follows:
Default value: 0 |
original_dir |
No |
Integer |
Whether to use the original output directory. Possible values:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
bucket |
Yes |
String |
OBS bucket name |
location |
Yes |
String |
Region where an OBS bucket is located. It must be the same as the region where MPC is deployed. |
object |
Yes |
String |
OBS object path, which complies with the OSS Object definition.
|
file_name |
No |
String |
File name
When it is used as the output file name:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
No |
String |
Sampling type Possible options are:
Default value: TIME |
time |
No |
Integer |
Interval for capturing snapshots. Default value: 12 Unit: second |
start_time |
No |
Integer |
Start time for the sampling type set to TIME. This parameter is used together with time. Default value: 0 Unit: second
NOTE:
If the value of start_time exceeds the media file duration, frames are not extracted. |
duration |
No |
Integer |
Capture duration when the sampling type is set to TIME. This parameter is used together with time and start_time, indicating that the first snapshot is captured at the time specified by start_time and snapshots are captured at the interval specified by time until the duration specified by this parameter elapses. Value range: [Number, ToEND]. ToEND indicates that snapshot capturing lasts till the end of the video. Default value: ToEND Unit: second
NOTE:
0 indicates that snapshot capturing lasts from start_time to the end of the video. |
dots |
No |
Array of integers |
Array of time points when a snapshot is captured For example, if you enter [1,3,5], the image frames at the first, third, and fifth seconds of the video are captured.
|
dots_ms |
No |
Array of integers |
Time point array of snapshot at a specified time in synchronous snapshot mode, in milliseconds. For example, enter [1000] to capture the image frame at the 1000th ms position of the video. Only one time point is allowed. |
output_filename |
No |
String |
Snapshot file name
|
format |
No |
Integer |
Snapshot file format. The value is: 1: JPG |
width |
No |
Integer |
Image width The options are as follows:
Unit: pixel |
height |
No |
Integer |
Image height The options are as follows:
Unit: pixel |
max_length |
No |
Integer |
The longest side of a snapshot. The width of the snapshot is scaled proportionally with the longest side and input video pixel. The value ranges from 240 to 3,840. Unit: pixel
NOTE:
This parameter is used together with width/height. If neither width nor height is 0, the image size is calculated based on width/height. Otherwise, the image size is calculated based on max_length. If this parameter and width/height are not selected, snapshots are output based on the aspect ratio of the source media file. |
Response Parameters
Status code: 202
Parameter |
Type |
Description |
---|---|---|
task_id |
String |
Task ID |
status |
String |
Task status |
create_time |
String |
Time when a task is created |
output |
ObsObjInfo object |
Storage location of snapshots |
output_file_name |
String |
Snapshot file name |
thumbnail_time |
String |
Capture time |
description |
String |
Task description |
Parameter |
Type |
Description |
---|---|---|
bucket |
String |
OBS bucket name |
location |
String |
Region where an OBS bucket is located. It must be the same as the region where MPC is deployed. |
object |
String |
OBS object path, which complies with the OSS Object definition.
|
file_name |
String |
File name
When it is used as the output file name:
|
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code |
error_msg |
String |
Error description |
Example Requests
-
Creates an asynchronous snapshot capturing task to capture snapshots from a video at every set interval.
POST https://{endpoint}/v1/{project_id}/thumbnails { "input" : { "bucket" : "example-bucket", "location" : "region01", "object" : "example-path/input.mp4" }, "output" : { "bucket" : "example-bucket", "location" : "region01", "object" : "example-path/output" }, "tar" : 1, "thumbnail_para" : { "time" : 2, "format" : 1, "max_length" : 480 }, "sync" : 0 }
-
Creates a synchronous snapshot capturing task (sync set to 1) to capture snapshots from a video at every set interval.
POST https://{endpoint}/v1/{project_id}/thumbnails { "input" : { "bucket" : "example-bucket", "location" : "region01", "object" : "example-path/input.mp4" }, "output" : { "bucket" : "example-bucket", "location" : "region01", "object" : "example-path/output" }, "tar" : 1, "thumbnail_para" : { "time" : 2, "format" : 1, "max_length" : 480 }, "sync" : 1 }
Example Responses
Status code: 202
Snapshot task created successfully.
-
Asynchronous snapshot capturing task created.
{ "task_id" : "100211" }
-
Synchronous snapshot capturing task created.
{ "task_id" : "100212", "status" : "FINISHED", "create_time" : "20231201020412", "output" : { "bucket" : "bucket-demo", "location" : "cn-north-4", "object" : "output/demo_object", "file_name" : "" }, "output_file_name" : "H_270.png", "thumbnail_time" : "30", "description" : "Task completed." }
Status code: 400
Failed to create a snapshot task.
{ "error_code" : "MPC.10202", "error_msg" : "Invalid request parameter" }
Status Codes
Status Code |
Description |
---|---|
202 |
Snapshot task created successfully. |
400 |
Failed to create a snapshot task. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot