Creating a Transcoding Task
Function
This API is used to create a transcoding task to transcode media files, and add watermarks and capture snapshots during transcoding. A transcoding template must be configured before video transcoding. 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.
URI
POST /v1/{project_id}/transcodings
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Project ID. For details about how to obtain a project ID, see Obtaining a Project ID. |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
No |
String |
User token. The token is obtained by calling the IAM API used to obtain a user token. The token is the value of X-Subject-Token in the response header. |
|
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 |
No |
ObsObjInfo object |
Storage location of an input file. This parameter is mandatory in scenarios where audio is not added. |
|
output |
Yes |
ObsObjInfo object |
Storage location of an output file |
|
trans_template_id |
No |
Array of integers |
Transcoding template ID. If av_parameter is not specified, this parameter is mandatory. Each transcoding output corresponds to a transcoding template ID. A maximum of nine template IDs are supported. Only the following parameters in transcoding templates can be changed:
|
|
av_parameters |
No |
Array of AvParameters objects |
Transcoding parameters. If trans_template_id and this parameter are both set, transcode audio or video based on the settings defined in this parameter. If trans_template_id is not set, this parameter is mandatory. |
|
output_filenames |
No |
Array of strings |
Name of an output file.
|
|
user_data |
No |
String |
Custom user data. You can call a query API or send a notification to transfer this field to users. |
|
watermarks |
No |
Array of WatermarkRequest objects |
A maximum of 20 image watermarks and text watermarks are supported. |
|
thumbnail |
No |
Thumbnail object |
Snapshot information. Snapshot files are generated only when the output resolution set in the transcoding template or av_parameters is 1920x1080, 1280x720, 854x480, or 480x270. Otherwise, no snapshot files are generated. |
|
priority |
No |
Integer |
Task priority. Possible values are:
|
|
subtitle |
No |
Subtitle object |
Subtitle parameters |
|
encryption |
No |
Encryption object |
Encryption parameters |
|
crop |
No |
Crop object |
Number of seconds cropped from a video for which transcoding is performed on. |
|
audio_track |
No |
AudioTrack object |
Audio track parameters |
|
multi_audio |
No |
MultiAudio object |
Multi-language and multi-channel audio parameters |
|
video_process |
No |
VideoProcess object |
Video processing parameters |
|
audio_process |
No |
AudioProcess object |
Audio processing parameters |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
video |
No |
VideoParameters object |
Video parameters |
|
audio |
No |
Audio object |
Audio parameters |
|
common |
Yes |
Common object |
Common parameters |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
output_policy |
No |
String |
Output policy. Possible values are:
NOTE:
|
|
codec |
No |
Integer |
Video codec. Possible values are:
|
|
bitrate |
No |
Integer |
Average output bitrate. Its value is 0 or an integer ranging from 40 to 30,000. Unit: kbit/s If this parameter is set to 0, the average output bitrate is an adaptive value. |
|
profile |
No |
Integer |
Encoding profile. Possible values are:
|
|
level |
No |
Integer |
Encoding level. Possible values are:
|
|
preset |
No |
Integer |
Encoding quality. Possible values are:
|
|
ref_frames_count |
No |
Integer |
Maximum reference frames. Value range:
Unit: frame |
|
max_iframes_interval |
No |
Integer |
Maximum I-frame interval. The value ranges from 2 to 10. Default value: 5 Unit: second |
|
bframes_count |
No |
Integer |
Maximum number of B-frames. Value range:
Unit: frame |
|
frame_rate |
No |
Integer |
Frame rate. The value is 0 or ranges from 5 to 60. The value 0 indicates adaptive frame rate. Unit: FPS
NOTE:
If the configured frame rate is not within the value range, the value is automatically changed to 0. If the configured frame rate is higher than the frame rate of the input file, the value is automatically changed to the frame rate of the input file. |
|
width |
No |
Integer |
Video width (unit: px). The value can be:
|
|
height |
No |
Integer |
Video height (unit: px). The value can be:
|
|
black_cut |
No |
Integer |
Whether to enable black bar removal. Possible values are:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
output_policy |
No |
String |
Output policy. Possible values are:
NOTE:
|
|
codec |
Yes |
Integer |
Audio codec. Possible values are:
|
|
sample_rate |
Yes |
Integer |
Audio sampling rate. Possible values are:
|
|
bitrate |
No |
Integer |
Audio bitrate. The value is 0 or ranges from 8 to 1,000. Unit: kbit/s |
|
channels |
Yes |
Integer |
Number of audio channels. Possible values are:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
PVC |
Yes |
Boolean |
Whether to enable low bitrate HD. Possible values are:
Default value: false |
|
hls_interval |
Yes |
Integer |
HLS segment duration. This parameter is used only when pack_type is set to 1 or 3. The value ranges from 2 to 10. Default value: 5 Unit: s |
|
dash_interval |
Yes |
Integer |
Dash segment duration. This parameter is used only when pack_type is set to 2 or 3. The value ranges from 2 to 10. Default value: 5 Unit: s |
|
pack_type |
Yes |
Integer |
Packaging type. Possible values are:
NOTE:
If pack_type is set to 5 or 6, do not set video parameters. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
input |
No |
ObsObjInfo object |
Storage location of an input file. This parameter is mandatory if an image watermark is used. |
|
template_id |
No |
String |
ID of a watermark template. You can call an API to create a watermark template. |
|
text_context |
No |
String |
Base64-coded text watermark. For example, if the text watermark to be added is "Test Text Watermark", the value is 5rWL6K+V5paH5a2X5rC05Y2w. |
|
image_watermark |
No |
ImageWatermark object |
Watermark parameters used for overwriting the parameters with the same names in the watermark template |
|
text_watermark |
No |
TextWatermark object |
Text watermark configurations. If text_context is set, this field cannot be left blank. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
dx |
No |
String |
Horizontal offset between the start point of the watermark and the vertex of the output video.
For example, if the output video width is 1,920 pixels, dx is 0.1, and referpos is TopRight, the horizontal offset between the upper right corner of the watermark and the right vertex of the video is 192. |
|
dy |
No |
String |
Vertical offset between the start point of the watermark and the vertex of the output video.
For example, if the output video height is 1,080 pixels, dy is 0.1, and referpos is TopRight, the vertical offset between the upper right corner of the watermark and the right vertex of the video is 108. |
|
referpos |
No |
String |
Watermark position. Possible values are:
|
|
timeline_start |
No |
String |
Watermark start time, which is used together with timeline_duration. Its value is a digit. Unit: s |
|
timeline_duration |
No |
String |
How long the watermark lasts, which is used together with timeline_start. Its value is a digit greater than or equal to 0. Default value: ToEND ToEND indicates that the watermark lasts until the end of the video. |
|
image_process |
No |
String |
How the image watermark is processed. This parameter is used only when type is set to Image. Possible values are:
|
|
width |
No |
String |
Watermark width. The value can either be a positive integer or a decimal between 0.0 and 1.0.
|
|
height |
No |
String |
Watermark height. The value can either be a positive integer or a decimal between 0.0 and 1.0.
|
|
base |
No |
String |
Video which the watermark is overlaid on. Possible values are:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
dx |
No |
String |
Horizontal offset between the start point of the watermark and the vertex of the output video.
For example, if the output video width is 1,920 pixels, dx is 0.1, and referpos is TopRight, the horizontal offset between the upper right corner of the watermark and the right vertex of the video is 192. |
|
dy |
No |
String |
Vertical offset between the start point of the watermark and the vertex of the output video.
For example, if the output video height is 1,080 pixels, dy is 0.1, and referpos is TopRight, the vertical offset between the upper right corner of the watermark and the right vertex of the video is 108. |
|
referpos |
No |
String |
Watermark position. Possible values are:
|
|
timeline_start |
No |
String |
Watermark start time, which is used together with timeline_duration. Its value is a digit. Unit: s |
|
timeline_duration |
No |
String |
How long the watermark lasts, which is used together with timeline_start. Its value is a digit greater than or equal to 0. Default value: ToEND ToEND indicates that the watermark lasts until the end of the video. |
|
font_name |
No |
String |
Text watermark font. Possible values are:
|
|
font_size |
No |
Integer |
Font size. Value range: 4 to 120 |
|
font_color |
No |
String |
Font color. Possible values are:
|
|
base |
No |
String |
Video which the watermark is overlaid on. Possible values:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
tar |
No |
Integer |
Whether to compress captured snapshots to a TAR package Possible values are:
|
|
out |
No |
ObsObjInfo object |
Storage location of snapshots. If this parameter is not set, snapshots are stored in the same location as the output file. |
|
params |
Yes |
ThumbnailPara object |
Snapshot parameters |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
type |
No |
String |
Sampling type. Possible values are:
Default value: TIME |
|
time |
No |
Integer |
Interval for taking snapshots. Default value: 12 Unit: second |
|
start_time |
No |
Integer |
Start time if the sampling type is TIME. This parameter is used together with time. Default value: 0 Unit: second |
|
duration |
No |
Integer |
Duration if the sampling type is TIME. This parameter is used together with time and start_time. Snapshots are captured every time. ToEND indicates that sampling lasts until the end of the video. Default value: ToEND Unit: second It must be greater than or equal to 0. If this is 0, snapshots are captured from start_time to the video end time. |
|
dots |
No |
Array of integers |
Array of time points when a snapshot is taken. A maximum of 10 time points are supported. |
|
output_filename |
No |
String |
Name of a snapshot file.
|
|
format |
No |
Integer |
Snapshot file format. The value is: 1: jpg |
|
aspect_ratio |
No |
Integer |
Aspect ratio. |
|
width |
No |
Integer |
Snapshot width |
|
height |
No |
Integer |
Snapshot height |
|
max_length |
No |
Integer |
The longest side of a snapshot. The other side of the snapshot is scaled proportionally with the longest side and input video pixel. Value range: 240 to 3,840 Default value: 480 Unit: pixel
NOTE:
If this parameter and width/height are both set, the width/height is used. If both the width and height are not 0, the longest side is the width/height. Otherwise, the longest side is the value of max_length. If this parameter and width/height are not set, max_length is 480 by default. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
input |
No |
ObsObjInfo object |
Storage location of an SRT file |
|
inputs |
No |
Array of MulInputFileInfo objects |
Storage location of SRT files |
|
subtitle_type |
No |
Integer |
Subtitle file type. Possible values:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
language |
No |
String |
Language label |
|
input |
No |
ObsObjInfo object |
Storage location of a subtitle file |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
hls_encrypt |
No |
HlsEncrypt object |
Encryption parameters for HLS videos |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
key |
Yes |
String |
Content encryption key, which is in base64Binary format |
|
url |
Yes |
String |
Address of Key Management Service (KMS) used by the tenant |
|
iv |
No |
String |
Initial vector, which is a random number in base64Binary format |
|
algorithm |
No |
String |
Encryption algorithm. Possible values are:
Default value: AES-128-CTR |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
duration |
No |
Integer |
Duration of a captured video, starting from 0 seconds. Default value: 10 Unit: s |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
type |
No |
Integer |
Audio track selection method. Possible values are:
|
|
left |
No |
Integer |
ID of the audio track where the left audio channel is |
|
right |
No |
Integer |
ID of the audio track where the right audio channel is |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
tracks_info |
No |
Array of TracksInfo objects |
Audio track information |
|
audio_files |
No |
Array of AudioFile objects |
Parameters about a single audio file |
|
default_language |
No |
String |
Default track language. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
tracks_info |
No |
Array of TracksInfo objects |
Audio track information |
|
input |
No |
ObsObjInfo object |
Storage location of an input file |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
channel_layout |
No |
String |
Audio channel layout of the audio track |
|
language |
No |
String |
Language description of the audio track |
|
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 |
File path.
|
|
file_name |
No |
String |
Name of an output file. This parameter is valid only for packaging tasks.
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
rotate |
No |
Integer |
Clockwise rotation angle of a video. Possible values are:
|
|
adaptation |
No |
String |
Adaptive resolution. Possible values are:
|
|
upsample |
No |
Integer |
Whether to enable low resolution-to-high resolution, for example, 480p to 720p. Possible values are:
|
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
volume |
No |
String |
Volume adjustment method. In this case, the volume adjustment amplitude needs to set. Possible values are:
|
|
volume_expr |
No |
Integer |
Volume adjustment amplitude. This parameter is used only when volume is set to dynamic. The value ranges from -15 to 15. Unit: dB |
Response Parameters
Status code: 202
|
Parameter |
Type |
Description |
|---|---|---|
|
task_id |
Integer |
Task ID. If the returned status code is 200 OK, the value is the task ID generated after the task is accepted. |
Status code: 403
|
Parameter |
Type |
Description |
|---|---|---|
|
error_code |
String |
Error code |
|
error_msg |
String |
Error description |
Example Requests
POST https://{endpoint}/v1/{project_id}/transcodings
{
"input": {
"bucket": "example-bucket",
"location": "region1",
"object": "/VOD/input/sample.MP4"
},
"output": {
"bucket": "example-bucket",
"location": "region1",
"object": "/VOD/output/"
},
"trans_template_id": [1002, 1003, 1004, 1005],
"priority": "9",
"subtitle": {
"subtitle_type": 1,
"input": {
"bucket": "bucket",
"location": "region1",
"object": "subtitle.srt"
}
},
"encryption": {
"multidrm": {
"content_id": "123456789",
"streaming_mode": "HLS ",
"encrypt_audio": 0,
"emi": 16420,
"drm_list": ["PLAYREADY"]
}
},
"thumbnail": {
"out": {
"bucket": "example-bucket",
"location": "region1",
"object": "/VOD/output/"
},
"tar": 1,
"params": {
"time": 2,
"format": 1,
"aspect_ratio": 1,
"max_length": 480
}
}
}
Example Responses
Status code: 202
Transcoding task created successfully.
{
"task_id" : 100211
}
Status code: 403
Failed to create a transcoding task.
{
"error_code" : "MPC.10202",
"error_msg" : "Invalid request parameter"
}
Status Codes
|
Status Code |
Description |
|---|---|
|
202 |
Transcoding task created successfully. |
|
403 |
Failed to create a transcoding task. |
Error Codes
See Error Codes.
Last Article: Transcoding APIs
Next Article: Canceling a Transcoding Task
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.