This topic describes how to transcode videos by using the CreateMediaConvertTask operation of Intelligent Media Management (IMM).
Feature description
Video transcoding is the process of converting a video stream from one compressed and encoded format to another. This involves adjusting parameters, such as the video format, container, resolution, and bitrate, to ensure the video compatibility with different devices and platforms, and reducing the file size to accelerate transmission.

Scenarios
Multi-device compatibility: To ensure smooth playbacks on different devices, such as mobile phones, tablets, computers, and smart TVs, you can use video transcoding to convert videos to device-specific formats.
Streaming media playback: Streaming media services need to transcode videos to multiple formats and bitrates for dynamic adjustment based on your network conditions to improve viewing experience.
Video compression: You can transcode a video to reduce its file size without affecting its quality. This facilitates storage and transmission, especially when your network bandwidth is limited.
Supported audio and video formats
Category | Format |
Audio | Mainstream audio formats, such as AAC, MP3, WAV, FLAC, WMA, AC3, and Opus. |
Video | Mainstream video formats, such as MP4, MPEG-TS, MKV, MOV, AVI, FLV, M3U8, WebM, WMV, RM, and VOB. |
Procedure
Prerequisites
An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.
Object Storage Service (OSS) is activated and a bucket is created. For more information, see Create a bucket.
IMM is activated. For more information, see Activate IMM.
A project is created in the IMM console. For more information, see Create a project.
NoteYou can call the CreateProject operation to create a project. For more information, see CreateProject.
You can call the ListProjects operation to list information of all projects in a region.
Step 1: Upload a file
Use the OSS console to upload a media file to a bucket that resides in the same region as your IMM project.

Step 2: Use IMM to transcode a video
Call the CreateMediaConvertTask operation to create a media transcoding task.
Parameter description
In the following examples, an IMM project named test-project is used, and a video whose file name is oss://test-bucket/video-demo/Shushan Commercial Building.mov is transcoded.
For more information about media processing features and usage methods, see Media transcoding.
You can process the video file by calling the CreateMediaConvertTask operation and referencing the SDK code in OpenAPI Explorer.
To achieve the best playback compatibility, we recommend that you transcode the video to the MP4 or HTTP Live Streaming (HLS) format and set the video's Codec parameter to h264, the PixelFormat parameter to yuv420p, the audio's Codec parameter to aac, and the Channel parameter to 2.
The transcoding process degrades the video image quality. You can use the Bitrate and CRF parameters to adjust the image quality of the transcoded video. In general, higher image quality means a larger file size.
H.265 provides higher compression efficiency than H.264. With the same video image quality, H.265 typically saves over 30% of storage space and bandwidth costs compared with H.264. The disadvantage of H.265 is that it must be used with compatible players.
If you leave the Codec parameter empty, the default value "copy" is used. This value specifies that the video stream to be processed is directly copied to the output file. If you set the Codec parameter to "copy", the remaining parameters in TranscodeVideo become invalid. You cannot use "copy" in video transcoding. Typically, it is used in container format conversion.
We recommend that you use variables to configure an output file path in the value of the URI parameter in Targets. For more information, see TargetURI template.
Transcode a video to the MP4 format
The following section provides an example on how to convert a video to the MP4 format without changing specific input video parameters, such as the resolution and frame rate.

Transcoding information
Video format: from MOV to MP4.
Video configurations: 24 Constant Rate Factor (CRF) value, and specific input video parameters retained, such as the resolution and frame rate.
Audio configurations: Advanced Audio Coding (AAC) format, 96 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building.mp4.Transcoding completion notification: a Simple Message Queue (formerly MNS) (SMQ) message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 96000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "mp4",
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mp4",
"Video": {
"TranscodeVideo": {
"CRF": 24,
"Codec": "h264",
"PixelFormat": "yuv420p"
}
}
}
]
}Transcode a video to the HLS format with a 1920 × 1080 resolution at 30 FPS
This section provides an example on how to transcode a video to an H.265 video in a 1920 × 1080 resolution at 30 frames per second (FPS) and use HLS to break the input video into segments. If the resolution and frame rate of the input video are insufficient, the relevant input video parameters are used.

Transcoding information
Video format: from MOV to M3U8.
Segmentation: HLS segments, each of which has a duration of 10 seconds.
Video configurations: H.265 encoding format, 24 CRF value, 1920 × 1080 resolution, and 30 FPS.
Audio configurations: AAC format, 128 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output paths:
oss://test-bucket/video-demo/Shushan Commercial Building.m3u8andoss://test-bucket/video-demo/Shushan Commercial Building-%d.ts.Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 128000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "ts",
"Segment": {
"Duration": 10,
"Format": "hls"
},
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.{autoext}",
"Video": {
"TranscodeVideo": {
"AdaptiveResolutionDirection": true,
"CRF": 24,
"Codec": "h265",
"FrameRate": 30,
"FrameRateOption": "adaptive",
"PixelFormat": "yuv420p",
"Resolution": "1920x1080",
"ResolutionOption": "adaptive",
"ScaleType": "fit"
}
}
}
]
}Transcode a video to three HLS videos in 1080p, 720p, and 480p resolutions
This section provides an example on how to transcode an input video to three output videos separately in a 1080p, 720p, or 480p resolution and use HLS to break the input video into segments.

Transcoding information
Before the transcoding
Format: MOV.
Video encoding format: H.264.
Resolution: 3840 × 2160.
Frame rate: 30.
After the transcoding
Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
Video 1
Video format: M3U8.
Segmentation: HLS segments, each of which has a duration of 10 seconds.
Video configurations: H.264 encoding format, 25 CRF value, 1920 × 1080 resolution, and 30 FPS.
Audio configurations: AAC format, 256 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output paths:
oss://test-bucket/video-demo/Shushan Commercial Building-x1080.m3u8andoss://test-bucket/video-demo/Shushan Commercial Building-x1080-%d.ts.
Video 2
Video format: M3U8.
Segmentation: HLS segments, each of which has a duration of 10 seconds.
Video configurations: H.264 encoding format, 26 CRF value, 1280 × 720 resolution, and 30 FPS.
Audio configurations: AAC format, 128 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output paths:
oss://test-bucket/video-demo/Shushan Commercial Building-x720.m3u8andoss://test-bucket/video-demo/Shushan Commercial Building-x720-%d.ts.
Video 3
Video format: M3U8.
Segmentation: HLS segments, each of which has a duration of 10 seconds.
Video configurations: H.264 encoding format, 28 CRF value, 854 × 480 resolution, and 25 FPS.
Audio configurations: AAC format, 96 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output paths:
oss://test-bucket/video-demo/Shushan Commercial Building-x480.m3u8andoss://test-bucket/video-demo/Shushan Commercial Building-x480-%d.ts.
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 256000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "ts",
"Segment": {
"Duration": 10,
"Format": "hls"
},
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building-{resolution}.{autoext}",
"Video": {
"TranscodeVideo": {
"AdaptiveResolutionDirection": true,
"CRF": 25,
"Codec": "h264",
"FrameRate": 30,
"FrameRateOption": "adaptive",
"PixelFormat": "yuv420p",
"Resolution": "x1080",
"ResolutionOption": "adaptive",
"ScaleType": "fit"
}
}
},
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 128000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "ts",
"Segment": {
"Duration": 10,
"Format": "hls"
},
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building-{resolution}.{autoext}",
"Video": {
"TranscodeVideo": {
"AdaptiveResolutionDirection": true,
"CRF": 26,
"Codec": "h264",
"FrameRate": 30,
"FrameRateOption": "adaptive",
"PixelFormat": "yuv420p",
"Resolution": "x720",
"ResolutionOption": "adaptive",
"ScaleType": "fit"
}
}
},
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 96000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "ts",
"Segment": {
"Duration": 10,
"Format": "hls"
},
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building-{resolution}.{autoext}",
"Video": {
"TranscodeVideo": {
"AdaptiveResolutionDirection": true,
"CRF": 28,
"Codec": "h264",
"FrameRate": 25,
"FrameRateOption": "adaptive",
"PixelFormat": "yuv420p",
"Resolution": "x480",
"ResolutionOption": "adaptive",
"ScaleType": "fit"
}
}
}
]
}Transcode a video to the MP4 format and add watermarks
This section provides an example on how to transcode a video to the MP4 format, add a watermark logo to the upper-left corner of the video, and add a watermark text to the lower-right corner of the video.

Transcoding information
Video format: from MOV to MP4.
Video configurations: H.264 encoding format, 25 CRF value, and specific input video parameters retained, such as the resolution and frame rate. Add Alibaba Cloud as a watermark logo to the upper-left corner of the video and add IMM as a watermark text to the lower-right corner of the video.
Audio configurations: AAC format, 256 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building.mp4.Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 256000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "mp4",
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.{autoext}",
"Video": {
"FilterVideo": {
"Delogos": [],
"Watermarks": [
{
"Dx": 0.05,
"Dy": 0.1,
"ReferPos": "topleft",
"Type": "file",
"URI": "oss://test-bucket/video-demo/aliyun.png",
"Width": 0.1
},
{
"Content": "IMM",
"Dx": 0.05,
"Dy": 0.1,
"FontColor": "#FFFFFF",
"FontSize": 100,
"ReferPos": "bottomright",
"Type": "text"
}
]
},
"TranscodeVideo": {
"CRF": 25,
"Codec": "h264",
"PixelFormat": "yuv420p"
}
}
}
]
}Capture a clip from a video and transcode the clip to the FLV format
This section provides an example on how to capture a clip from a video, transcode the clip to the Flash Video (FLV) format, and adjust the bitrate to 1 Mbit/s.

Transcoding information
Video format: from MOV to FLV.
Clip start time: fifth second of the input video.
Clip duration: 10 seconds.
Video configurations: 1 Mbit/s bitrate, and specific input video parameters retained, such as the resolution and frame rate.
Audio configurations: AAC format, 96 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building.flv.Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"Duration": 10,
"StartTime": 5,
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 96000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "flv",
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.{autoext}",
"Video": {
"TranscodeVideo": {
"Bitrate": 1000000,
"Codec": "h264",
"PixelFormat": "yuv420p"
}
}
}
]
}Convert a video's container format to MP4
This section provides an example on how to convert a video's container format to MP4 without changing the audio and video content. This may cause playback compatibility issues.
Transcoding information
Video format: from MOV to MP4.
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building.mp4.Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mov"
}
],
"Targets": [
{
"Container": "mp4",
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.{autoext}"
}
]
}Mosaic watermarks in a video
This section provides an example on how to separately mosaic watermarks in the upper-left and the lower-right corners of a video.

Transcoding information
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building.mp4.Video configurations: H.264 encoding format, 24 CRF value, and specific input video parameters retained, such as the resolution and frame rate. Mosaic the watermark logo in the upper-left corner and the watermark text in the lower-right corner of the video.
Audio configurations: AAC format, 96 Kbit/s bitrate, 44.1 kHz sampling rate, and binaural sound channels.
Video output path:
oss://test-bucket/video-demo/Shushan Commercial Building-mosaic.mp4.Transcoding completion notification: an SMQ message, which is sent to an SMQ topic named "test-mns-topic".
For more information about the sample SDK, go to the SDK Sample Code tab in OpenAPI Explorer. The parameters in the example are automatically configured in OpenAPI Explorer. Before you debug the code, modify the parameters as needed.
Request parameters
{
"ProjectName": "test-project",
"Notification": {
"MNS": {
"TopicName": "test-mns-topic"
}
},
"Sources": [
{
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building.mp4"
}
],
"Targets": [
{
"Audio": {
"TranscodeAudio": {
"Bitrate": 96000,
"Channel": 2,
"Codec": "aac",
"SampleRate": 44100
}
},
"Container": "mp4",
"URI": "oss://test-bucket/video-demo/Shushan Commercial Building-mosaic.{autoext}",
"Video": {
"FilterVideo": {
"Delogos": [
{
"Dx": 0.05,
"Dy": 0.1,
"Height": 0.1,
"ReferPos": "topleft",
"Width": 0.1
},
{
"Dx": 0.05,
"Dy": 0.1,
"Height": 100,
"ReferPos": "bottomright",
"Width": 600
}
],
},
"TranscodeVideo": {
"CRF": 24,
"Codec": "h264",
"PixelFormat": "yuv420p"
}
}
}
]
}