All Products
Search
Document Center

ApsaraVideo Media Processing:AddTemplate

Last Updated:Oct 13, 2026

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

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

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.

  • Default value: MP4.

  • Video transcoding supports FLV, MP4, HLS (M3U8+TS), and MPEG-DASH (MPD+fMP4).

Note

If the container format is FLV, the video codec cannot be set to H.265.

  • Audio transcoding supports MP3, MP4, OGG, FLAC, and M4A.

  • Images support GIF and WebP.

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

ParameterTypeRequiredDescription
FormatStringNoDefault 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

ParameterTypeRequiredDescription
CodecStringNoThe codec format. Valid values: H.264, H.265, GIF, and WEBP. Default value: H.264.
ProfileStringNoThe 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.
BitrateStringNoValid values: 10 to 50000. Unit: Kbps.
CrfStringNoThe 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.
WidthStringNoThe video width. Default value: the original video width. Valid values: 128 to 4096. Unit: pixels.
HeightStringNoThe video height. Default value: the original video height. Valid values: 128 to 4096. Unit: pixels.
FpsStringNoThe 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.
GopStringNoThe 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.
PresetStringNoThe 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.
ScanModeStringNoThe scan pattern. Valid values: interlaced and progressive.
BufsizeStringNoThe buffer size. Valid values: [1000, 128000]. Default value: 6000. Unit: KB.
MaxrateStringNoThe peak video bitrate. Valid values: [10, 50000]. Unit: Kbps.
PixFmtStringNoThe video pixel format. Valid values include standard pixel formats such as yuv420p and yuvj420p. Default value: yuv420p or the original pixel format.
RemoveStringNoSpecifies 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.
CropStringNoThe 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.
PadStringNoThe video padding configuration. Parameter format: width:height:left:top. Example: 1280:800:0:140.
LongShortModeStringNoSpecifies 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:

ContainerAudio CodecsVideo Codecs
flvAAC, MP3H.264
mp4AAC, MP3H.264, H.265
tsAAC, MP3H.264, H.265
m3u8AAC, MP3H.264, H.265
gifNot supportedGIF

The following table shows the supported combinations of video codecs and video stream configuration parameters:

Video/CodecH.264H.265GIF
ProfileYNN
BitrateYYN
CrfYYN
WidthYYY
HeightYYY
FpsYYY
GopYYN
PresetYNN
ScanModeYYY
BufsizeYYN
MaxrateYYN
PixFmtYYbgr8

Details of the Audio JSON object

ParameterTypeRequiredDescription
CodecStringNoThe audio codec. Valid values: AAC, MP3, VORBIS, and FLAC. Default value: AAC.
ProfileStringNoThe audio encoding profile. When Codec is set to AAC, valid values are aac_low, aac_he, aac_he_v2, aac_ld, and aac_eld.
SamplerateStringNoThe 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.
BitrateStringNoThe audio bitrate of the output file. Valid values: 8 to 1000. Unit: Kbps. Default value: 128.
ChannelsStringNoThe 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.
RemoveStringNoSpecifies 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:

ContainerAudio Codecs
mp3MP3
mp4AAC
oggVORBIS, FLAC
flacFLAC

Details of the TransConfig JSON object

ParameterTypeRequiredDescription
TransModeStringNoThe transcoding mode. Default value: onepass. Valid values: onepass, twopass, and CBR.
AdjDarMethodStringNoThe resolution adjustment method. Default value: none. Valid values: rescale, crop, pad, and none.
IsCheckResoStringNoSpecifies 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.
IsCheckResoFailStringNoSpecifies 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.
IsCheckVideoBitrateStringNoSpecifies 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.
IsCheckAudioBitrateStringNoSpecifies 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.
IsCheckAudioBitrateFailStringNoSpecifies 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.
IsCheckVideoBitrateFailStringNoSpecifies 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

ParameterTypeRequiredDescription
SegmentStringNoThe segment configuration. The value is a JSON object. For more information, see Segment details.

Segment details

ParameterTypeRequiredDescription
DurationStringNoThe segment duration. The value must be an integer. Unit: seconds. Valid values: 1 to 60. Default value: 10.
ForceSegTimeStringNoThe 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.

  • Default value: 6000.

  • Unit: KB.

6000

LongShortMode

string

Specifies whether to enable adaptive landscape and portrait mode (long and short side mode). Default value: false. Valid values:

  • true: enables adaptive landscape and portrait mode.

  • false: disables adaptive landscape and portrait mode.

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.

  • Unit: pixels.

  • Default value: the original video height.

800

Qscale

string

The strength of the independent denoising algorithm.

1

Crop

string

The video cropping configuration. Two methods are supported:

  • Automatic detection and cropping of black bars: Set the value to border.

  • Custom cropping: Specify custom parameters for cropping. Parameter format: width:height:left:top. Example: 1280:800:0:140.

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.

  • baseline: suitable for mobile devices.

  • main: suitable for standard-definition devices.

  • 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.

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.

  • true: removes the video stream.

  • false: retains the video stream.

  • Default value: false.

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.

  • Default value: the original video width.

  • Unit: pixels.

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:

  • veryfast: ultra-fast

  • fast: fast

  • medium: medium

  • slow: slow

  • slower: ultra-slow

Note

This parameter is supported only by H.264.

fast

ScanMode

string

The scan mode. Valid values:

  • interlaced: interlaced scanning

  • progressive: progressive scanning

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: checks the audio bitrate.

  • false: does not check the audio bitrate.

  • Default value:
    • false if the parameter is empty and the codec is different from that of the input source.

    • true if the parameter is empty and the codec is the same as that of the input source.

true

TransMode

string

The transcoding mode. Valid values:

  • onepass

  • twopass

  • CBR

  • Default value: onepass

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: checks the resolution.

  • false: does not check the resolution.

  • Default value: false.

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: skips transcoding.

  • false: does not check the video bitrate.

  • Default value: false.

true

AdjDarMethod

string

The resolution adjustment method. Default value: none. Valid values:

  • rescale: stretches the video to fit the resolution.

  • crop: crops the video in batches.

  • none: makes no changes.

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: checks the video bitrate.

  • false: does not check the video bitrate.

  • Default value: false.

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: checks the resolution.

  • false: does not check the resolution.

  • Default value: false.

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: skips transcoding.

  • false: does not check the audio bitrate.

  • Default value: false.

true

State

string

The status of the template.

  • Normal: The template is normal.

  • Deleted: The template is deleted.

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

  • aac_he

  • aac_he_v2

  • aac_ld

  • aac_eld

aac_low

Remove

string

Specifies whether to remove the audio stream.

  • true: removes the audio stream.

  • false: retains the audio stream.

  • Default value: false.

true

Codec

string

The audio codec format. Default value: aac. Valid values:

  • aac

  • mp3

  • vorbis

  • flac

aac

Samplerate

string

The sampling rate.

  • Unit: Hz.

  • Default value: 44100.

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: automatic adjustment

  • dynamic: dynamic adjustment

  • linear: linear adjustment

auto

Level

string

The volume adjustment level.

  • Default value: -20.

  • Unit: dB.

-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.

  • Unit: Kbps.

  • Default value: 128.

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.