If the preset templates in ApsaraVideo Media Processing (MPS) do not meet your needs, create a custom transcoding template to configure parameters such as encoding format, frame rate, and resolution.
Limitations
By default, you can create up to 10 transcoding templates per Alibaba Cloud account in each region. This quota applies to custom templates. To increase this limit, contact Alibaba Cloud support.
Use the console
Log on to the ApsaraVideo Media Processing (MPS) console and select a region in the top navigation bar.
In the left-side navigation pane, choose Template management > Transcoding templates. Then, click the Customize Template tab.
Click Add template.
Configure the transcoding template parameters in the Basic Parameters, Video Parameters, and Audio Parameters sections.
Basic Parameters
Parameter
Description
Template Name
Enter a name for the transcoding template. The name can contain Chinese characters, letters, digits, and hyphens (-). It cannot start with a special character and must be no more than 128 bytes in length.
Transcoding type
Select the transcoding type.
NoteThis is useful for extracting an audio track from a video or transcoding an audio file.
Encapsulation Format
Select the container format for the output file.
Video Parameters
NoteIf your input file is in High Dynamic Range (HDR) and you want to convert it to Standard Dynamic Range (SDR), contact Alibaba Cloud support to configure adaptive tone mapping. This prevents overexposure or underexposure in the output.
Parameter
Description
Encoding Format
Select the video encoding format.
Bitrate control
Select a mode to control the video bitrate. Supported modes: Same as Source, Fixed Bitrate, Average Bitrate, and CRF.
NoteBitrate control determines how the output bitrate is managed during the encoding process:
Same as Source: The output bitrate matches the input bitrate.
Fixed bitrate: Uses a constant bitrate for the entire file, regardless of scene complexity. This mode may result in larger file sizes.
Average bitrate: The output maintains a specified average bitrate over the duration of the file. The encoder allocates more bits to complex scenes and fewer to simple scenes. This mode balances quality and file size predictability.
CRF: This mode targets a constant video quality level. You specify this level with a Constant Rate Factor (CRF) value from 0 (lossless) to 51 (worst quality). The output bitrate fluctuates based on scene complexity and is not predictable.
Configure the related bitrate parameters.
(Optional) Peak Bit Rate
The maximum instantaneous bitrate in Kbps. The value must be an integer in the range [10, 50,000].
(Optional) Bitrate check
The action to take if the input video bitrate is lower than the target bitrate.
Supported modes: Transcode at source bitrate, Transcode at specified bitrate (upsampling), and Do not transcode.
Resolution
Select a mode to set the output resolution. Supported modes: Same as source, Set by long and short sides, and Set by width and height.
Specify the video dimensions. The values must be even integers in the range [128, 4,096].
(Optional) Resolution check
The action to take if the input resolution is lower than the target resolution.
Supported modes: Transcode at source resolution, Transcode at specified resolution, and Do not transcode.
Frame Rate
Select whether to use the input video's frame rate or specify a custom frame rate.
If you select a custom frame rate, enter a value in the range of (0, 60]. Unit: fps. Common values include 23.976, 24, 25, and 30.
NoteIf the input frame rate is higher than 60 fps, the output is capped at 60 fps.
(Optional) Fragment Length
The duration of each segment. The value must be an integer in the range of [1, 60]. Unit: seconds. If left empty, the default value is 10.
NoteA segment must contain at least one keyframe. For best results, set the segment duration to a multiple of the GOP duration. If the duration is shorter than the GOP duration or not a multiple, the service automatically adjusts the keyframe interval.
(Optional) GOP
The Group of Pictures (GOP) size. You can define the size by setting either the maximum time interval or the maximum number of frames between keyframes.
The value must be an integer in the range [1, 100,000]. For streaming, a value in the range of 2 to 7 seconds is recommended.
NoteA larger GOP size increases the compression ratio but also increases encoding time, segment duration, and seek response time in players.
(Optional) Encoding Level
This parameter is available only for the H.264 codec. Supported profiles: high, main, and baseline.
When creating multiple outputs for adaptive bitrate streaming, use the baseline profile for the lowest resolution to ensure compatibility with older devices. For other resolutions, use the main or high profile.
(Optional) Buffer
The size of the video buffer in kb. The value must be in the range [1,000, 128,000], and the default is 6,000.
NoteThe buffer size (also known as
bufsize) controls bitrate fluctuation. A larger buffer size allows for greater bitrate variation, which can improve quality.(Optional) Scan Mode
The scan mode for the output. Supported modes are Same as source, Deinterlace, Interlaced, and Progressive. The default is Same as source.
(Optional) Color format
Select the color format. By default, the input video's format is used.
Audio Parameters
Parameter
Description
(Optional) Disable audio
If you select Disable audio, the audio parameters below become unavailable.
The output file will not contain an audio stream or related media information. This is useful when you need to extract only the video stream.
Encoding Format
Select the audio encoding format. The default is AAC.
NoteIf the container format is HLS and the video encoding format is H.264, you must select AAC as the audio encoding format to ensure playback compatibility.
Encoding Level
This parameter is available when the audio encoding format is AAC.
For multi-channel audio sources, such as 5.1 or 7.1 surround sound, set this parameter to aac_low.
For playback on general-purpose devices, use aac_he. It can reduce the audio bitrate by up to 50% compared to aac_low while maintaining similar audio quality. A typical low bitrate is 64 Kbps.
For high-end playback devices, use aac_he_v2. It offers better quality at smaller file sizes. Typical low bitrates range from 32 Kbps to 48 Kbps.
Sample Rate
Select the sample rate in Hz. The default is 44,100.
The supported sample rates vary depending on the container format and encoding format. For more information, see Supported sample rates.
Audio bitrate
Select whether to use the input video's audio bitrate or specify an average bitrate.
If you select average bitrate, enter an integer from 8 to 1,000 Kbps. The default value is 128. Common values are 64, 128, and 256.
Audio Channels
Select the number of audio channels. You can choose to keep the original number of channels. The default value is 2.
Volume normalization
When enabled, this feature adjusts the volume of the output file to a consistent level. This avoids significant volume differences between files. This setting is only available for single-stream audio outputs.
Click Submit to create the transcoding template.
Use SDKs
SDK | References |
Java SDK | |
Go SDK |
Use the API
For API instructions, see AddTemplate - Add a custom transcoding template.
Next steps
Manage transcoding templates: You can query, modify, delete, and copy your transcoding templates. For more information, see Manage transcoding templates.
Use the transcoding template: When you create a transcoding job or create a workflow, you can select the custom template you created.