Use Alibaba Cloud Intelligent Media Services (IMS) to transcode and package audio and video files with multiple subtitles, and generate multi-subtitle media that plays on multiple types of devices.
Transcoding and packaging workflow
To generate multi-subtitle media with IMS, you complete the following steps:
Prepare the environment. Activate IMS, bind an OSS bucket, configure callbacks, and upload the source files. See Prerequisites and Preparation.
Create transcoding templates for the video and audio streams. See Transcoding template configuration.
Submit a multi-bitrate transcoding and packaging job. See Submit a multi-bitrate job.
Query the job result and verify the packaged output. See Query the job result and Verify the packaged output.
The following flowchart shows the transcoding and packaging workflow.
Example of the packaged file structure
The following example shows the playlist structure of a packaged output:
#EXTM3U
# Audio stream definitions (multi-language)
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Chinese-Audio",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="zh",URI="audio/chinese/chinese.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="English-Audio",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="audio/english/english.m3u8"
# Video stream definitions (multi-bitrate)
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=900000,CODECS="avc1.640020",RESOLUTION=720x1280,AUDIO="audio",SUBTITLES="subtitle"
video/720p/720p.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=400000,CODECS="avc1.640020",RESOLUTION=360x640,AUDIO="audio",SUBTITLES="subtitle"
video/360p/360p.m3u8
# Subtitle stream definitions (multi-language)
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="Chinese-Subtitle",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="zh",URI="subtitle/chinese/chinese.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitle",NAME="English-Subtitle",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="subtitle/english/english.m3u8"Prerequisites
Intelligent Media Services is activated. For more information, see Activate IMS.
Preparation
IMS basic configuration
Storage configuration — Bind an OSS bucket to IMS. For more information, see Configure a storage address.
Callback configuration — Configure an HTTP callback or an MNS callback to receive job status notifications. For basic information about callback methods and callback events, see Callback events overview.
Source files — Upload the source video, audio, and subtitle files to the OSS bucket that is bound to IMS. The job example in this topic references these files by their OSS URLs.
Transcoding template configuration
Configuration workflow
The following flowchart shows the configuration workflow for transcoding templates.
Sample requirements
This example uses the following requirements:
Encoding protocol — H264 or H265
Video resolution — 360P, 540P, 720P, or 1080P
Audio — HE-AAC at 64 Kbps. Other audio parameters use default values.
Subtitles — M3U8 (VTT)
Configuration example
This example uses four video quality levels. Create the video transcoding templates as described in the following tables. For more information, see Create a transcoding template.
The job example in this topic also references an audio transcoding template named Audio-64Kbps for the HE-AAC audio outputs. Make sure that this template is created before you submit the packaging job.
To use Narrowband HD transcoding, create the corresponding templates as described in the tables, and then submit a ticket. Alibaba Cloud then upgrades the configuration in the backend.
The following tables describe the templates for the H264 and H265 encoding protocols. If you use H265, review the following container format considerations:
Preferred option — Use the fmp4 container format. It is the Apple standard protocol and works well with the Safari browser.
Alternative — The ts container format also works, but it is not compatible with Safari.
Console limitation — You cannot create the fmp4 container format in the console. Create the template with the m3u8(ts) container format first. Alibaba Cloud then upgrades the configuration in the backend.
H264
Transcoding template | Encoding protocol | Container format | Other settings |
Video-360P | H264 | m3u8(.ts) | Resolution: 640 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-540P | H264 | m3u8(.ts) | Resolution: 960 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-720P | H264 | m3u8(.ts) | Resolution: 1280 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-1080P | H264 | m3u8(.ts) | Resolution: 1920 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
H265
Transcoding template | Encoding protocol | Container format | Other settings |
Video-360P | H265 | m3u8(.fmp4) | Resolution: 640 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-540P | H265 | m3u8(.fmp4) | Resolution: 960 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-720P | H265 | m3u8(.fmp4) | Resolution: 1280 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Video-1080P | H265 | m3u8(.fmp4) | Resolution: 1920 pixels on the long side (the short side is adaptive). Segment duration: 5 seconds. Configure other settings as needed. |
Multi-bitrate transcoding and packaging job
After you complete the preparation, submit a multi-bitrate transcoding and packaging job, and then query the job result.
Submit a multi-bitrate job
Call the SubmitMediaConvertJob operation to submit a transcoding job for a video or audio file to Intelligent Media Services.
Use OverrideParams to set subtitle streams
You cannot customize subtitle information in a transcoding template. To configure subtitle streams, explicitly set the subtitle information with OverrideParams when you submit the job. The following tables describe the subtitle stream settings.
Subtitles
Parameter | Type | Description |
Subtitles | Array of Subtitle | The subtitle stream settings. |
Subtitle
Parameter | Type | Description |
Codec | String | The encoding format of the subtitle stream. HLS supports only the vtt format. |
Config description (HlsGroupConfig)
Each output in the job example contains an HlsGroupConfig object that describes the output stream in the HLS manifest. The following table describes the parameters.
Parameter | Type | Description |
Type | string | Specifies the data stream type. Valid values: Video, Audio, Subtitle, and Hybrid. During processing, only the settings that correspond to the stream type are retained: video-related settings for Video, audio-related settings for Audio, and both audio-related and video-related settings for Hybrid. |
Bandwidth | string | The bandwidth. This parameter is optional. The bitrate (bps) is used by default. This parameter takes effect when Type is Video or Hybrid. |
AudioGroup | string | The audio group that this video stream references. This parameter takes effect when Type is Video. |
SubtitleGroup | string | The subtitle group that this video stream references. This parameter takes effect when Type is Video or Hybrid. |
Name | string | The NAME attribute of this output stream in the HLS manifest. This parameter is required when Type is Audio or Subtitle. |
Group | string | The GROUP_ID attribute of this output stream in the HLS manifest. This parameter takes effect when Type is Audio or Subtitle. Default value: the same as the value of Type. |
Language | string | The LANGUAGE attribute of this output stream in the HLS manifest. This parameter takes effect when Type is Audio or Subtitle. The value must comply with the RFC 5646 standard. |
Default | boolean | Specifies whether to set the stream as the default stream. This parameter takes effect when Type is Audio or Subtitle. |
AutoSelect | boolean | Specifies whether to select the stream automatically. This parameter takes effect when Type is Audio or Subtitle. |
Forced | boolean | Specifies whether to force the stream to display. This parameter takes effect when Type is Audio or Subtitle. |
Example: transcode and generate multi-bitrate packaged files
The following example defines four inputs: a video (video), an English audio track (EnglishAudio), a Chinese subtitle track (ChineseSubtitle), and an English subtitle track (EnglishSubtitle). The outputs include two video quality levels (720P and 360P), two audio tracks, and two subtitle tracks. This example uses two of the four video templates that you created. You can add or remove video outputs as needed.
Each output, including each subtitle output, requires a TemplateId. For a subtitle output, specify the ID of any transcoding template in the packaging job. In the following example, replace <TemplateId> with an existing template ID, such as Video-360P.
The following JSON corresponds to the Config parameter of the SubmitMediaConvertJob request. Replace the angle-bracket placeholders with your actual values.
{
"Config": {
"Inputs": [
{
"Name": "video",
"InputFile": {
"Type": "OSS",
"Url": "https://<Bucket>.<OSSPublicEndpoint>/<Video1Chinese>"
}
},
{
"Name": "EnglishAudio",
"InputFile": {
"Type": "OSS",
"Url": "https://<Bucket>.<OSSPublicEndpoint>/<Audio1English>"
}
},
{
"Name": "ChineseSubtitle",
"InputFile": {
"Type": "OSS",
"Url": "https://<Bucket>.<OSSPublicEndpoint>/<Subtitle1Chinese>"
}
},
{
"Name": "EnglishSubtitle",
"InputFile": {
"Type": "OSS",
"Url": "https://<Bucket>.<OSSPublicEndpoint>/<Subtitle1English>"
}
}
],
"OutputGroups": [
{
"Name": "Hls",
"GroupConfig": {
"Type": "Hls",
"OutputFileBase": {
"Type": "OSS",
"Url": "https://<Bucket>.<PublicEndpoint>/<URI>/"
},
"ManifestName": "<m3u8filename>"
},
"Outputs": [
{
"Name": "720P",
"OutputFileName": "video/720p/720p",
"TemplateId": "Video-720P",
"HlsGroupConfig": {
"Type": "Video"
}
},
{
"Name": "360P",
"OutputFileName": "video/360p/360p",
"TemplateId": "Video-360P",
"HlsGroupConfig": {
"Type": "Video"
}
},
{
"OutputFileName": "audio/chinese/chinese",
"TemplateId": "Audio-64Kbps",
"HlsGroupConfig": {
"Type": "Audio",
"Name": "ChineseAudio",
"Language": "zh",
"Autoselect": "TRUE",
"Default": "TRUE"
}
},
{
"InputRef": "ChineseSubtitle",
"OutputFileName": "subtitle/chinese/chinese",
"TemplateId": "<TemplateId>",
"OverrideParams": {
"Subtitles": [
{
"Codec": "vtt"
}
]
},
"HlsGroupConfig": {
"Type": "Subtitle",
"Name": "ChineseSubtitle",
"Language": "zh",
"Autoselect": "TRUE",
"Default": "TRUE"
}
},
{
"InputRef": "EnglishAudio",
"OutputFileName": "audio/english/english",
"TemplateId": "Audio-64Kbps",
"HlsGroupConfig": {
"Type": "Audio",
"Name": "EnglishAudio",
"Language": "en",
"Autoselect": "TRUE",
"Default": "FALSE"
}
},
{
"InputRef": "EnglishSubtitle",
"OutputFileName": "subtitle/english/english",
"TemplateId": "<TemplateId>",
"OverrideParams": {
"Subtitles": [
{
"Codec": "vtt"
}
]
},
"HlsGroupConfig": {
"Type": "Subtitle",
"Name": "EnglishSubtitle",
"Language": "en",
"Autoselect": "TRUE",
"Default": "FALSE"
}
}
]
}
]
}
}Query the job result
Call the GetMediaConvertJob operation to get the details of the transcoding job.
Callback event
When a packaging job completes, IMS sends a callback event. The event type (EventType) is MediaConvertComplete. The console does not yet support selecting this event. To configure it, call the SetEventCallback operation.
Key field description
The following table describes the key fields of the callback event.
Parameter | Type | Required | Description |
Name | String | Yes | The name of the primary job. |
JobId | String | Yes | The job ID. |
Status | String | Yes | The job status. The value |
TriggerSource | String | No | The trigger source. The value |
FinishTime | String | No | The time when the job completed. The format must be the same as that of EventTime. |
UserData | string | No | The custom data that you passed when you submitted the job. |
The following example shows a callback event:
{
"FinishTime": "2025-05-09T08:03:21Z",
"JobId": "your-job-id",
"Status": "Success",
"TriggerSource": "IceWorkflow",
"UserData": "{\"ImsSrc\":\"Workflow\",\"TaskId\":\"e89a955d88ca47f0b9b79c562e5c622f\"}"
}Verify the packaged output
A Status value of Success indicates that the job succeeded. To confirm that the packaged files are complete, compare the output files in your OSS bucket with the structure shown in Example of the packaged file structure. Verify that the video, audio, and subtitle playlists are all generated as expected.