Live transcoding generates a standard HTTP Live Streaming (HLS) m3u8 playlist for a video stored in OSS. The video is transcoded dynamically during playback, so no pre-generated Transport Stream (TS) files are needed. Compared to offline transcoding, this approach eliminates wait times and reduces both transcoding and storage costs by processing content on demand.
How it works
With offline video transcoding, the entire video must finish transcoding before playback can start. Live transcoding works differently: playback begins immediately after the source video is uploaded. Only the segments being watched are transcoded in real time.
Transcode during playback. No waiting. Playback starts as soon as the playlist is generated.
Fast startup and seeking. Optimized transcoding delivers a playback experience similar to local playback.
On-demand processing. Segments that are never played are never transcoded. Transcoded TS files can be deleted and regenerated on demand, which reduces storage costs.
Broad format support. Over 300 audio and video input formats are supported.
Customizable output. Transcoding parameters control video codec, resolution, bitrate, audio, and more.
Use cases
Network drives: After a user uploads a video, the client selects the optimal resolution based on network conditions, ensuring real-time playback and device compatibility. Videos that are not frequently accessed are never transcoded, reducing storage costs.
Video previews in chat applications: In messaging or social media apps, a video is playable immediately after it is sent. Videos in chat history can be periodically deleted and remain playable on demand.
Online forums and blogs: Shared videos play without waiting for transcoding, delivering smooth playback at the selected resolution.
Supported formats
Live transcoding supports over 300 audio and video formats. The following table lists common supported formats.
| Direction | Supported formats |
|---|---|
| Input video | AVI, MOV, FLV, MKV, WebM, MPEG, WMV, RM, VOB, TS, and all other mainstream formats |
| Input audio | MP3, WAV, AAC, FLAC, WMA, and all other mainstream formats |
| Output container | TS |
Prerequisites
Before you begin, make sure that you have:
Activated the Intelligent Media Management (IMM) service. For details, see Activate products
Attached an IMM project to your OSS bucket. For console instructions, see Quick Start. For the API approach, see AttachOSSBucket
The required permissions for IMM processing. For details, see Permissions
Usage notes
Anonymous access will be denied.
For additional details, see Live transcoding and GenerateVideoPlaylist API.
Parameters
Operation: hls/m3u8
Time parameters
| Parameter | Type | Required | Default | Valid values | Description |
|---|---|---|---|---|---|
ss | int | No | 0 | >= 0 | Start time in milliseconds. 0 or empty starts from the beginning. Use with t to generate a playlist for a specific segment. |
t | int | No | 0 | >= 0 | Transcoding duration in milliseconds. 0 or empty continues to the end. If the specified time exceeds the video length, the default value is used. |
st | int | No | 10000 | [5000, 15000] | Duration of each TS segment in milliseconds. |
initd | int | No | 30000 | - | Duration of initial pre-transcoding in milliseconds. 0 disables pre-transcoding. A negative value or a value exceeding the video duration transcodes the entire video. If the duration falls in the middle of a TS segment, transcoding continues to the end of that segment. Use this to reduce first-playback latency. To replace a traditional Video on Demand (VOD) service, set this to transcode the entire video initially. |
ta | int | No | Pre-transcodes a 2-minute segment | [10, 30] | Number of TS files to pre-transcode when live transcoding starts. Example: if st is 10000, the default ta is 12. |
Video parameters
| Parameter | Type | Required | Default | Valid values | Description |
|---|---|---|---|---|---|
vcodec | string | No | h264 | h264, h265 | Video codec. |
fps | float | No | Same as source | - | Video frame rate. |
fpsopt | int | No | 1 | 0, 1, 2 | Frame rate option. 0: always use target frame rate. 1: use source frame rate if lower than fps. 2: return an error if source frame rate is lower than fps. Must be set with fps. |
pixfmt | string | No | Same as source | yuv420p, yuv422p, yuv444p, yuv420p10le, yuv422p10le, yuv444p10le | Pixel format. |
s | string | No | Same as source | w x h, multiples of 2, range 64-4096 | Output resolution in width x height format. Example: 1280x720, 4096x4096, 64x64. |
sopt | string | No | 1 | 0, 1, 2 | Resolution option. 0: always use target resolution. 1: use source resolution if its area is smaller than the target. 2: return an error if source resolution area is smaller than the target. |
scaletype | string | No | stretch | stretch, crop, fill, fit | Scaling mode. stretch: force-scale to fill the target dimensions. crop: scale proportionally to minimum size beyond target, then crop from center. fill: scale proportionally to maximum size within target, then fill blank space with black. fit: scale proportionally to maximum size within target. Must be set with s. |
arotate | int | No | 0 | 0, 1 | Adaptive resolution orientation. 0: disabled. 1: enabled. |
vb | int | No | - | bit/s | Video bitrate. If neither crf nor vb is set, crf defaults to 23. Required when vbopt is set. |
vbopt | int | No | 1 | 0, 1, 2 | Video bitrate option. 0: always use target bitrate. 1: use source video bitrate if lower than target. 2: return an error if source video bitrate is lower than target. |
crf | float | No | 23 (when neither crf nor vb is set) | [0, 51]; recommended [18, 38] | Constant quality mode. Mutually exclusive with vb. Higher values produce lower quality. |
maxrate | int | No | - | bit/s | Maximum bitrate for dynamic bitrate mode. Must be set with bufsize. Valid only with crf. |
bufsize | int | No | - | bit/s | Decoder buffer size for dynamic bitrate mode. Valid only with crf. |
Audio parameters
| Parameter | Type | Required | Default | Valid values | Description |
|---|---|---|---|---|---|
an | int | No | 0 | 0, 1 | Disable audio. 0: audio enabled. 1: audio disabled. |
acodec | string | No | aac | aac | Audio codec. |
ar | int | No | Same as source | 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000 | Audio sample rate in Hz. |
ac | int | No | Same as source | [1, 8] | Number of audio channels. |
aq | int | No | - | [0, 100] | Audio quality. Mutually exclusive with ab. Higher values produce higher quality. |
ab | int | No | - | [1000, 10000000] bit/s | Audio bitrate. Mutually exclusive with aq. |
abopt | int | No | 1 | 0, 1, 2 | Audio bitrate option. 0: always use target bitrate. 1: use source audio bitrate if lower than ab. 2: return an error if source audio bitrate is lower than ab. |
The sys/saveas parameter is also used when generating a live transcoding playlist. For details, see Save as.
Generate a playlist and sign the stream
Live transcoding involves two steps: generating the m3u8 playlist, then signing the stream URL for playback.
After generating a playlist, see the Live transcoding topic in the IMM documentation for playback instructions.
Step 1: Generate the playlist
The following example generates an HLS playlist with these settings:
Source video:
Format: AVI
Object path:
oss://video-demo/example.aviStart position: 15 seconds from the beginning
Transcoding duration: 1800 seconds
Output settings:
TS segment duration: 10 seconds
Pre-transcoding duration: 30 seconds
Video codec: H.264, resolution 1280 x 720, frame rate 25 fps, bitrate 2 Mbps
Audio codec: AAC, bitrate 128 Kbps
Output path prefix:
oss://outbucket/outobjprefix/media
Request
POST /example.avi?x-oss-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-process=hls/m3u8,ss_15000,t_1800000,vcodec_h264,fps_25,fpsopt_1,s_1280x720,sopt_1,scaletype_fit,arotate_1,vb_2000000,vbopt_1,acodec_aac,ar_44100,ac_2,ab_128000,abopt_1,st_10000,initd_30000|sys/saveas,o_b3V0b2JqcHJlZml4L21lZGlh,b_b3V0YnVja2V0Response
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Wed, 25 May 2022 12:43:57 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 161
Connection: keep-alive
x-oss-request-id: 628E2481184E20F26C000009
x-oss-server-time: 12437
{"Duration":1800,"RequestId":"********-37E6-5996-8425-********","VideoPlaylist":[{"FrameRate":"25","Resolution":"1280x720","Token":"f93c43079**********1269608ebc86e","URI":"oss://outbucket/outobjprefix/media.m3u8"}]}Step 2: Sign the stream with hls/sign
OSS provides a dynamic signature mechanism for accessing live-transcoded audio and video data. When accessing the m3u8 file, add x-oss-process=hls/sign,live_1 to the URL. OSS then automatically signs all TS addresses in the returned playlist using the same signing method as the m3u8 request.
Python signing example
# -*- coding: utf-8 -*-
import os
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Specify the endpoint of the region where the bucket is located.
endpoint = 'yourEndpoint'
# Obtain access credentials from environment variables.
# Make sure OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET are set.
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# The name of the destination bucket.
bucket_name = 'your-oss-bucket-name'
# Set key to the name of the generated playlist, for example, output/media.m3u8.
key = 'output/media.m3u8'
# Specify the bucket instance.
# Use the oss2.AuthV2 signing method.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', bucket_name)
# Set x-oss-process to hls/sign,live_1.
params = {}
params.update({oss2.Bucket.PROCESS: 'hls/sign,live_1'})
# Generate the signed URL.
# Set slash_safe to True so that OSS does not escape forward slashes (/)
# in the object path. Without this, the signed URL is unusable.
url = bucket.sign_url('GET', key, 7200, params=params, slash_safe=True)
# The generated URL can be played directly in any HLS player.
print(url)Original m3u8 content
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.0,
media-c14709808479b31566b50f2f8b93fe1a-0.ts
#EXTINF:10.0,
media-c14709808479b31566b50f2f8b93fe1a-1.ts
#EXTINF:10.0,
media-c14709808479b31566b50f2f8b93fe1a-2.ts
#EXTINF:10.0,
media-c14709808479b31566b50f2f8b93fe1a-3.ts
#EXT-X-ENDLISTSigned m3u8 content (after hls/sign)
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:10.000,
media-c14709808479b31566b50f2f8b93fe1a-0.ts?x-oss-process=if_status_eq_404{hls/ts,from_b3V0cHV0L21lZGlhLm0zdTg}&x-oss-expires=1710457284&x-oss-signature-version=OSS2&x-oss-access-key-id=****fEAub****&x-oss-signature=****VR3gy****
#EXTINF:10.000,
media-c14709808479b31566b50f2f8b93fe1a-1.ts?x-oss-process=if_status_eq_404{hls/ts,from_b3V0cHV0L21lZGlhLm0zdTg}&x-oss-expires=1710457284&x-oss-signature-version=OSS2&x-oss-access-key-id=****fEAub****&x-oss-signature=****VR3gy****
#EXTINF:10.000,
media-c14709808479b31566b50f2f8b93fe1a-2.ts?x-oss-process=if_status_eq_404{hls/ts,from_b3V0cHV0L21lZGlhLm0zdTg}&x-oss-expires=1710457284&x-oss-signature-version=OSS2&x-oss-access-key-id=****fEAub****&x-oss-signature=****VR3gy****
#EXTINF:10.000,
media-c14709808479b31566b50f2f8b93fe1a-3.ts?x-oss-process=if_status_eq_404{hls/ts,from_b3V0cHV0L21lZGlhLm0zdTg}&x-oss-expires=1710457284&x-oss-signature-version=OSS2&x-oss-access-key-id=****fEAub****&x-oss-signature=****VR3gy****
#EXT-X-ENDLISTUse an SDK
Generating a live transcoding playlist is a synchronous process. For SDK usage details, see Use an SDK.
Output files
When a playlist is generated, the system creates an m3u8 file and TS files at the specified output path prefix. The m3u8 file is created immediately. If a pre-transcoding duration is specified, TS files for that duration are generated asynchronously.
For example, with a 30-second pre-transcoding duration and 10-second segment duration, three TS files are created:
.
├── outobjprefix.m3u8
├── outobjprefix-92376fbb-171f-4259-913f-705f7ee02f2s-0.ts
├── outobjprefix-92376fbb-171f-4259-913f-705f7ee02f2s-1.ts
├── outobjprefix-92376fbb-171f-4259-913f-705f7ee02f2s-2.ts
├── outobjprefix-92376fbb-171f-4259-913f-705f7ee02f2s-3.tsSegments that are not pre-transcoded are transcoded on demand during playback. If a video is never played, no additional TS files are generated. If playback starts at the 15-minute mark, transcoding begins from that point.
Feature details
| Feature | Description |
|---|---|
| Standardization | Supports the standard HLS protocol, media playlists, and master playlist generation. Supports playback of multiple video, audio, and subtitle streams. Compatible with mainstream HLS players. Supports over 300 audio and video input formats. |
| Cost efficiency | Segments that are not played are not transcoded. Transcoded TS files can be deleted to save storage. When the video is played again, new TS files are generated automatically. |
| Performance | Large-scale cluster supports real-time transcoding. Provides multiple resolutions and bitrates for different network conditions. Playback starts as soon as the playlist is generated. Adaptive video header segment sizing for faster loading. Supports intelligent pre-transcoding. |
FAQ
Can a video still play after TS files are manually deleted?
Yes. As long as the source video and the m3u8 playlist exist, the video remains playable. When the m3u8 playlist is requested again, the TS files are regenerated. Delete TS files to reduce storage costs without affecting playback.
Can an m3u8 file from a different source be used for live transcoding?
No. Only m3u8 files generated by the live transcoding feature can be used for live transcoding playback.