Creates a custom template that includes container information, video stream settings, and audio stream settings.
Operation description
The request parameters of this operation include container information, video stream settings, and audio stream settings. If you do not configure a specific part, the corresponding information is not included in the output stream transcoded by using the template.
QPS limit
The QPS limit for a single user is 100 calls per second. If the limit is exceeded, API calls are throttled, which may affect your business. Make API calls at a reasonable rate. For more information, see QPS limits.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
mts:AddTemplate |
create |
*All Resource
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| Name |
string |
Yes |
The name of the template. The maximum length is 128 bytes. |
mps-example |
| Container |
string |
No |
The container. The value is a JSON object that contains the Format parameter, which specifies the container format. If you do not configure the Container parameter, the default output format is MP4. To use other formats, you must configure this parameter. For more information, see Container details.
Note
If the container format is FLV, the video codec cannot be set to H.265.
Note
If the container format is GIF, the video codec can only be set to GIF. If the container format is WebP, the video codec can only be set to WebP. |
{"Format":"mp4"} |
| Video |
string |
No |
The video stream configurations. The value is a JSON object. For more information, see Video details. Note
If you do not configure the Video parameter, the transcoded output does not include the video stream. To retain the video stream, you must configure this parameter. |
{"Codec":"H.264","Profile":"high","Bitrate":"500","Crf":"15","Width":"256","Height":"800","Fps":"25","Gop":"10s"} |
| Audio |
string |
No |
The audio stream configurations. The value is a JSON object. For more information, see Audio details. Note
If you do not configure the Audio parameter, the transcoded output does not include the audio stream. To retain the audio stream, you must configure this parameter. |
{"Codec":"H.264","Samplerate":"44100","Bitrate":"500","Channels":"2"} |
| TransConfig |
string |
No |
The general transcoding configurations. The value is a JSON object. For more information, see TransConfig details. If you do not configure the TransConfig parameter, all transcoding configurations use default values. If the default values do not meet your transcoding requirements, you must configure this parameter as needed. |
{"TransMode":"onepass"} |
| MuxConfig |
string |
No |
The segment configurations. The value is a JSON object. For more information, see MuxConfig details. If you do not configure the MuxConfig parameter, the transcoded output is not segmented. To segment the output, you must configure this parameter. |
{"Segment":{"Duration":"10"}} |
Details of the Container JSON object
| Parameter | Type | Required | Description |
| Format | String | No | Default value: mp4. Video transcoding supports flv, mp4, HLS (m3u8+ts), and MPEG-DASH (MPD+fMP4). Audio transcoding supports mp3, mp4, ogg, flac, and m4a. Images support gif and WEBP. If the container format is gif, the Video Codec parameter must be set to GIF. If the container format is webp, the Video Codec parameter must be set to WEBP. If the container format is flv, the Video Codec parameter cannot be set to H.265. |
Details of the Video JSON object
| Parameter | Type | Required | Description |
| Codec | String | No | The codec format. Valid values: H.264, H.265, GIF, and WEBP. Default value: H.264. |
| Profile | String | No | The encoding profile. Valid values: baseline (suitable for mobile devices), main (suitable for standard-definition devices), and high (suitable for high resolution devices). Default value: high. Best Practices: If you have multiple resolutions, set the lowest resolution to baseline to ensure playback on low-end devices. Set other resolutions to main or high. This parameter is supported only by H.264. |
| Bitrate | String | No | Valid values: 10 to 50000. Unit: Kbps. |
| Crf | String | No | The constant rate factor (CRF) for bitrate and quality control. Valid values: 0 to 51. Default value: 26. If Crf is set, the Bitrate Settings become invalid. |
| Width | String | No | The video width. Default value: the original video width. Valid values: 128 to 4096. Unit: pixels. |
| Height | String | No | The video height. Default value: the original video height. Valid values: 128 to 4096. Unit: pixels. |
| Fps | String | No | The frame rate. Default value: the frame rate of the input file. If the frame rate of the input file exceeds 60, the value 60 is used. Valid values: 0 to 60. Unit: FPS. |
| Gop | String | No | The maximum time interval or maximum number of frames between keyframes. When specifying the maximum time interval, the unit must be seconds. Default value: 10s. When specifying the maximum number of frames, no unit is required. Valid values: 1 to 100000. |
| Preset | String | No | The video algorithm preset. Valid values: veryfast (ultra-fast), fast (fast), medium (medium), slow (slow), and slower (ultra-slow). Default value: medium. This parameter is supported only by H.264. |
| ScanMode | String | No | The scan pattern. Valid values: interlaced and progressive. |
| Bufsize | String | No | The buffer size. Valid values: [1000, 128000]. Default value: 6000. Unit: KB. |
| Maxrate | String | No | The peak video bitrate. Valid values: [10, 50000]. Unit: Kbps. |
| PixFmt | String | No | The video pixel format. Valid values include standard pixel formats such as yuv420p and yuvj420p. Default value: yuv420p or the original pixel format. |
| Remove | String | No | Specifies whether to delete the video stream. A value of true indicates that the video stream is deleted. A value of false indicates that the video stream is retained. Default value: false. |
| Crop | String | No | The video cropping configuration. Two methods are supported: automatic detection and cropping of black bars, where the value is set to border. Custom cropping uses the parameter format width:height:left:top. Example: 1280:800:0:140. |
| Pad | String | No | The video padding configuration. Parameter format: width:height:left:top. Example: 1280:800:0:140. |
| LongShortMode | String | No | Specifies whether to enable adaptive landscape and portrait pattern (long and short side pattern). The width of the transcoded output corresponds to the long side of the input video (the height for portrait videos), and the height corresponds to the short side of the input video (the width for portrait videos). A value of true indicates that the feature is enabled. A value of false indicates that the feature is shutdown. Default value: false. |
The following table shows the supported combinations of video transcoding codecs and container formats:
| Container | Audio Codecs | Video Codecs |
| flv | AAC, MP3 | H.264 |
| mp4 | AAC, MP3 | H.264, H.265 |
| ts | AAC, MP3 | H.264, H.265 |
| m3u8 | AAC, MP3 | H.264, H.265 |
| gif | Not supported | GIF |
The following table shows the supported combinations of video codecs and video stream configuration parameters:
| Video/Codec | H.264 | H.265 | GIF |
| Profile | Y | N | N |
| Bitrate | Y | Y | N |
| Crf | Y | Y | N |
| Width | Y | Y | Y |
| Height | Y | Y | Y |
| Fps | Y | Y | Y |
| Gop | Y | Y | N |
| Preset | Y | N | N |
| ScanMode | Y | Y | Y |
| Bufsize | Y | Y | N |
| Maxrate | Y | Y | N |
| PixFmt | Y | Y | bgr8 |
Details of the Audio JSON object
| Parameter | Type | Required | Description |
| Codec | String | No | The audio codec. Valid values: AAC, MP3, VORBIS, and FLAC. Default value: AAC. |
| Profile | String | No | The audio encoding profile. When Codec is set to AAC, valid values are aac_low, aac_he, aac_he_v2, aac_ld, and aac_eld. |
| Samplerate | String | No | The sampling rate. Default value: 44100. Valid values: 22050, 32000, 44100, 48000, and 96000. Unit: Hz. If the video container format is flv and the audio codec is mp3, the sampling rates 32000, 48000, and 96000 are not supported. If the audio codec is mp3, the sampling rate 96000 is not supported. |
| Bitrate | String | No | The audio bitrate of the output file. Valid values: 8 to 1000. Unit: Kbps. Default value: 128. |
| Channels | String | No | The number of audio channels. Default value: 2. When Codec is set to mp3, only 1 and 2 are supported. When Codec is set to aac, only 1, 2, 4, 5, 6, and 8 are supported. |
| Remove | String | No | Specifies whether to delete the audio stream. A value of true indicates that the audio stream is deleted. A value of false indicates that the audio stream is retained. Default value: false. |
The following table shows the supported combinations of audio transcoding codecs and container formats:
| Container | Audio Codecs |
| mp3 | MP3 |
| mp4 | AAC |
| ogg | VORBIS, FLAC |
| flac | FLAC |
Details of the TransConfig JSON object
| Parameter | Type | Required | Description |
| TransMode | String | No | The transcoding mode. Default value: onepass. Valid values: onepass, twopass, and CBR. |
| AdjDarMethod | String | No | The resolution adjustment method. Default value: none. Valid values: rescale, crop, pad, and none. |
| IsCheckReso | String | No | Specifies whether to check the resolution. If audio output resolution is greater than the input resolution in width or height, audio output resolution is set to the input resolution. A value of true indicates that the resolution is checked. A value of false indicates that the resolution is not checked. Default value: false. |
| IsCheckResoFail | String | No | Specifies whether to check the resolution. If audio output resolution is greater than the input resolution in width or height, the transcoding fails. A value of true indicates that the resolution is checked. A value of false indicates that the resolution is not checked. Default value: false. |
| IsCheckVideoBitrate | String | No | Specifies whether to check the video bitrate. If audio output video bitrate is greater than the input video bitrate, audio output video bitrate is set to the input video bitrate. A value of true indicates that the video bitrate is checked. A value of false indicates that the video bitrate is not checked. Default value: false. |
| IsCheckAudioBitrate | String | No | Specifies whether to check the audio bitrate. If audio output audio bitrate is greater than the input audio bitrate, audio output audio bitrate is set to the input audio bitrate. A value of true indicates that the audio bitrate is checked. A value of false indicates that the audio bitrate is not checked. Default value: false. |
| IsCheckAudioBitrateFail | String | No | Specifies whether to fail the transcoding when audio output audio bitrate is greater than the source audio bitrate. A value of true indicates that the transcoding is not performed. A value of false indicates that no check is performed. Default value: false. This parameter takes precedence over IsCheckAudioBitrate. |
| IsCheckVideoBitrateFail | String | No | Specifies whether to fail the transcoding when audio output video bitrate is greater than the source video bitrate. A value of true indicates that the transcoding is not performed. A value of false indicates that no check is performed. Default value: false. This parameter takes precedence over IsCheckVideoBitrate. |
Details of the MuxConfig JSON object
| Parameter | Type | Required | Description |
| Segment | String | No | The segment configuration. The value is a JSON object. For more information, see Segment details. |
Segment details
| Parameter | Type | Required | Description |
| Duration | String | No | The segment duration. The value must be an integer. Unit: seconds. Valid values: 1 to 60. Default value: 10. |
| ForceSegTime | String | No | The list of specified segment times. Separate multiple values with commas (,). You can specify up to 10 segment times. The value must be a decimal number with up to three decimal places. Unit: seconds. Example: 23, 55, 60, which indicates that segments are created at 23, 55, and 60 seconds. |
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The response parameters. |
||
| RequestId |
string |
The request ID. |
FA258E67-09B8-4EAA-8F33-BA567834A2C3 |
| Template |
object |
The details of the transcoding template. |
|
| Video |
object |
The video codec configuration. |
|
| Bufsize |
string |
The buffer size.
|
6000 |
| LongShortMode |
string |
Specifies whether to enable adaptive landscape and portrait mode (long and short side mode). Default value: false. Valid values:
Note
The width of the transcoded output corresponds to the long side of the input video (the height for portrait videos), and the height corresponds to the short side of the input video (the width for portrait videos). |
false |
| Degrain |
string |
The video quality control level. |
10 |
| BitrateBnd |
object |
The video bitrate range. |
|
| Max |
string |
The maximum bitrate. |
1500 |
| Min |
string |
The minimum bitrate. |
800 |
| PixFmt |
string |
The video pixel format. Valid values include standard pixel formats such as yuv420p and yuvj420p. Default value: yuv420p or the original pixel format. |
yuv420p |
| Pad |
string |
The video padding configuration. Parameter format: width:height:left:top. |
1280:800:0:140 |
| Codec |
string |
The codec format. Valid values: H.264, H.265, GIF, and WEBP. Default value: H.264. |
H.264 |
| Height |
string |
The video height.
|
800 |
| Qscale |
string |
The strength of the independent denoising algorithm. |
1 |
| Crop |
string |
The video cropping configuration. Two methods are supported:
|
border |
| Bitrate |
string |
The bitrate of the output file. Unit: Kbps. |
500 |
| Maxrate |
string |
The peak video bitrate. Unit: Kbps. |
500 |
| MaxFps |
string |
The maximum frame rate. |
60 |
| Profile |
string |
The encoding profile.
Best Practices: If you have multiple resolutions, set the lowest resolution to baseline to ensure playback on low-end devices. Set other resolutions to main or high. Note
This parameter is supported only by H.264. |
high |
| Crf |
string |
The constant rate factor (CRF) for bitrate and quality control. Default value: When the encoding format is H.264, the default value is 23. When the encoding format is H.265, the default value is 26. Note
If Crf is set, the Bitrate Settings become invalid. |
15 |
| Remove |
string |
Specifies whether to remove the video stream.
|
false |
| Gop |
string |
The maximum time interval or maximum number of frames between keyframes. When specifying the maximum time interval, the unit must be seconds. When specifying the maximum number of frames, no unit is required. Default value: 10s. |
10s |
| Width |
string |
The video width.
|
256 |
| Fps |
string |
The frame rate. Default value: the frame rate of the input file. If the frame rate of the input file exceeds 60, the value 60 is used. Unit: FPS. |
25 |
| Preset |
string |
The video algorithm preset. Default value: medium. Valid values:
Note
This parameter is supported only by H.264. |
fast |
| ScanMode |
string |
The scan mode. Valid values:
|
interlaced |
| ResoPriority |
string |
The priority of resolution adjustment. |
0 |
| Hdr2sdr |
string |
Specifies whether to enable the HDR to SDR conversion feature. When enabled, HDR videos are converted to SDR. |
true |
| NarrowBand |
object |
The Narrowband HD configuration parameters. |
|
| Version |
string |
The Narrowband HD version. Valid value: 1.0. |
1.0 |
| Abrmax |
number |
The upper limit of the dynamic bitrate. After this parameter is set, the average bitrate falls within the range of (0, 1000000]. |
3000 |
| MaxAbrRatio |
number |
The maximum multiplier for the upper bitrate limit. After this parameter is set, abrmax does not exceed x times the bitrate of the source video. Valid values: (0, 1.0]. |
1.0 |
| TransConfig |
object |
The general transcoding configuration. |
|
| IsCheckAudioBitrate |
string |
Specifies whether to check the audio bitrate. If the output audio bitrate is greater than the source audio bitrate, the output audio bitrate is considered equal to the source audio bitrate, and the specified audio bitrate parameter does not take effect. The priority of this parameter is lower than that of IsCheckAudioBitrateFail.
|
true |
| TransMode |
string |
The transcoding mode. Valid values:
|
onepass |
| IsCheckReso |
string |
Specifies whether to check the resolution. If the output resolution is greater than the input resolution in width or height, the output resolution is set to the input resolution.
|
true |
| IsCheckVideoBitrateFail |
string |
Specifies whether to check the video bitrate. If the output video bitrate is greater than the source video bitrate, the priority of this parameter is higher than that of IsCheckVideoBitrate.
|
true |
| AdjDarMethod |
string |
The resolution adjustment method. Default value: none. Valid values:
|
rescale |
| IsCheckVideoBitrate |
string |
Specifies whether to check the video bitrate. If the output video bitrate is greater than the input video bitrate, the output video bitrate is set to the input video bitrate.
|
true |
| IsCheckResoFail |
string |
Specifies whether to check the resolution. If the output resolution is greater than the input resolution in width or height, a transcoding failure is returned.
|
true |
| IsCheckAudioBitrateFail |
string |
Specifies whether to check the audio bitrate. If the output audio bitrate is greater than the source audio bitrate, the priority of this parameter is higher than that of IsCheckAudioBitrate.
|
true |
| State |
string |
The status of the template.
|
Normal |
| MuxConfig |
object |
The transcoding muxing configuration. |
|
| Webp |
object |
The muxing configuration for WebP. |
|
| Loop |
string |
The number of loops. |
0 |
| Gif |
object |
The muxing configuration for GIF. |
|
| FinalDelay |
string |
The pause duration of the last frame. Unit: centiseconds. |
0 |
| DitherMode |
string |
The color dithering method for the palette. Valid values: sierra and bayer. |
sierra |
| Loop |
string |
The number of loops. |
0 |
| IsCustomPalette |
string |
Specifies whether to use a custom palette. |
false |
| Segment |
object |
The segment configuration. |
|
| Duration |
string |
The segment duration. Unit: seconds. |
10 |
| Name |
string |
The name of the template. |
mps-example |
| Audio |
object |
The audio codec configuration. |
|
| Profile |
string |
The audio encoding profile. When Codec is set to aac, valid values are:
|
aac_low |
| Remove |
string |
Specifies whether to remove the audio stream.
|
true |
| Codec |
string |
The audio codec format. Default value: aac. Valid values:
|
aac |
| Samplerate |
string |
The sampling rate.
|
44100 |
| Qscale |
string |
The strength of the independent denoising algorithm. |
5 |
| Channels |
string |
The number of audio channels. Default value: 2. |
2 |
| Volume |
object |
The volume details. |
|
| Method |
string |
The volume adjustment method. Valid values:
|
auto |
| Level |
string |
The volume adjustment level.
|
-20 |
| IntegratedLoudnessTarget |
string |
The target volume. This parameter takes effect only when Method is set to dynamic. Unit: dB. Valid values: [-70, -5]. Default value: -6. |
-6 |
| TruePeak |
string |
The Peak Volume. This parameter takes effect only when Method is set to dynamic. Unit: dB. Valid values: [-9, 0]. Default value: -1. |
-1 |
| LoudnessRangeTarget |
string |
The fluctuation range relative to the target volume. This parameter takes effect only when Method is set to dynamic. Unit: dB. Valid values: [1, 20]. Default value: 8. |
8 |
| PeakLevel |
string |
The volume adjustment coefficient. This parameter takes effect only when Method is set to adaptive. Valid values: [0, 1]. Default value: 0.9. |
0.9 |
| Bitrate |
string |
The audio bitrate of the output file.
|
500 |
| Id |
string |
The ID of the transcoding template. Save this ID for subsequent calls to other related API operations. |
16f01ad6175e4230ac42bb5182cd**** |
| Container |
object |
The container. |
|
| Format |
string |
The container format. |
mp4 |
Examples
Success response
JSON format
{
"RequestId": "FA258E67-09B8-4EAA-8F33-BA567834A2C3",
"Template": {
"Video": {
"Bufsize": "6000",
"LongShortMode": "false",
"Degrain": "10",
"BitrateBnd": {
"Max": "1500",
"Min": "800"
},
"PixFmt": "yuv420p",
"Pad": "1280:800:0:140",
"Codec": "H.264",
"Height": "800",
"Qscale": "1",
"Crop": "border",
"Bitrate": "500",
"Maxrate": "500",
"MaxFps": "60",
"Profile": "high",
"Crf": "15",
"Remove": "false",
"Gop": "10s",
"Width": "256",
"Fps": "25",
"Preset": "fast",
"ScanMode": "interlaced",
"ResoPriority": "0",
"Hdr2sdr": "true",
"NarrowBand": {
"Version": "1.0",
"Abrmax": 3000,
"MaxAbrRatio": 1
}
},
"TransConfig": {
"IsCheckAudioBitrate": "true",
"TransMode": "onepass",
"IsCheckReso": "true",
"IsCheckVideoBitrateFail": "true",
"AdjDarMethod": "rescale",
"IsCheckVideoBitrate": "true",
"IsCheckResoFail": "true",
"IsCheckAudioBitrateFail": "true"
},
"State": "Normal",
"MuxConfig": {
"Webp": {
"Loop": "0"
},
"Gif": {
"FinalDelay": "0",
"DitherMode": "sierra",
"Loop": "0",
"IsCustomPalette": "false"
},
"Segment": {
"Duration": "10"
}
},
"Name": "mps-example",
"Audio": {
"Profile": "aac_low",
"Remove": "true",
"Codec": "aac",
"Samplerate": "44100",
"Qscale": "5",
"Channels": "2",
"Volume": {
"Method": "auto",
"Level": "-20",
"IntegratedLoudnessTarget": "-6",
"TruePeak": "-1",
"LoudnessRangeTarget": "8",
"PeakLevel": "0.9"
},
"Bitrate": "500"
},
"Id": "16f01ad6175e4230ac42bb5182cd****",
"Container": {
"Format": "mp4"
}
}
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.