Live transcoding allows videos to be dynamically transcoded and instantly played by creating M3U8 playlists for HTTP live Streaming (HLS), without the need to create transport stream (TS) objects in advance. Compared with traditional transcoding, live transcoding considerably shortens the time required to begin transcoding videos, and greatly reduces transcoding and storage overheads due to the on-demand capabilities.
Overview
Unlike Video transcoding, which requires the entire video to be transcoded before playback can begin, live transcoding processes only the necessary video segments and allows playback to start immediately after the original video file is uploaded. Live transcoding offers the following benefits:
Instant playback during transcoding and no buffering.
Optimized transcoding and smooth playback with scrubbing completed in seconds
On-demand transcoding, re-transcoding in case of deletion of transcoded files, and reduced transcoding and storage costs.
Custom transcoding with dozens of custom transcoding parameters.
Good compatibility with more than 300 audio and video formats.
Scenarios
Play videos stored in network drives: Live transcoding allows videos in network drives to be instantly played upon request on clients at resolutions that best suit actual network conditions. This ensures real-time playback and provides good video compatibility across devices. Live transcoding also reduces storage costs because videos in network drives are not transcoded if the videos are not requested.
Videos stored in network drives: When users upload videos to a network drive, the optimal playback resolution is automatically selects by the client based on real-time network conditions, ensuring both real-time playback and multi-device compatibility. Cold Archive videos are not transcoded if not played, effectively reducing storage costs.
Preview and play videos on social media platforms: Live transcoding allows users on instant messaging and social media platforms to immediately play received videos. This improves the timeliness of communications. In addition, when users play videos in chat history that remain unwatched for an extended period of time, they can still be played instantly even if TS objects generated for the videos are regularly cleared to reduce storage usage.
Preview of the videos on social media platforms: Videos shared via instant messaging or social meida platforms become playable immediately upon delivery, eliminating wait times. Unwatched videos in chat history remain instantly accessible even after periodic cleanup of TS segments (used to optimize storage utilization).
Share video content on forums and blogging platforms: Live transcoding provides users on forums and blogging platforms with a smooth, device-compatible video viewing experience. It allows users to immediately play shared videos at the resolution that best suits their network conditions, without the need to wait for video transcoding.
Videos shared on forums & blogs : Live transcoding technology, enables users to start playback without waiting for full transcoding. This ensures smooth and clear playback.
Features
The following table describes the benefits of live transcoding in detail.
Feature | Description |
Standardization |
|
Cost-efficiency |
|
High efficiency |
|
Supported audio and video formats
The live transcoding feature supports virtually all audio and video formats, encompassing over 300 different types. The following table describes some common audio and video formats supported by live transcoding.
Input video formats | AVI, MOV, FLV, MKV, WebM, MPEG, WMV, RM, VOB, and TS, all mainstream video formats |
Input audio formats | MP3, WAV, AAC, FLAC, and WMA, all mainstream video formats |
Output container format | TS |
Prerequisites
IMM is activated. For more information, see Activate IMM.
Before proceeding, make sure that an IMM Project is mapped to your bucket. For more information about how to map an IMM Project, see Get started and AttachOSSBucket. For more information about how to map an IMM Project in the OSS console, see Get started. For more information about how to map an IMM Project by calling an API operation, see AttachOSSBucket.
IMM is granted the permissions that are required to perform the operation. For more information, see Permissions.
Usage notes
Anonymous access will be denied.
For more usage notes about live transcoding, see Live transcoding and GenerateVideoPlaylist.
Parameters
Action: hls/m3u8
The following table describes the parameters that you can configure to generate live transcoding playlists.
Parameter | Type | Required | Description |
ss | int | No | The point in time at which the playlist generation begins in the source video. Unit: milliseconds. Valid values:
Note You can use this parameter together with the t parameter to generate a playlist that covers only a portion of the video content. |
t | int | No | The duration of the content in the source video covered by the playlist. Unit: milliseconds. Valid values:
Note If you set this parameter to a value that exceeds the total duration of the source video, the playlist extends only to the end of source video. |
ta | int | No | The number of TS objects to be pre-transcoded when live transcoding is triggered. By default, a 2-minute segment is pre-transcoded. For example, if you set the st parameter to 10000, the default value of the ta parameter is 12. Valid values: 10 to 30. |
st | int | No | The duration of a TS object. Unit: milliseconds. Default value: 10000. Valid values: 5000 to 15000. |
initd | int | No | The duration covered by initial transcoding. Unit: milliseconds. Default value: 30000.
Note This parameter reduces the time required to start the first playback, which enhances the viewing experience. If you want to use live transcoding in traditional video-on-demand scenarios, you can initially transcode entire videos. |
vcodec | string | No | The coding format of the output video. Valid values:
|
fps | float | No | The target frame rate. By default, the target frame rate is the same as the source frame rate. |
fpsopt | int | No | The frame rate option. Valid values:
Note This parameter must be used together with the fps parameter. |
pixfmt | string | No | The pixel format. By default, the pixel format matches that of the source video. Valid values:
|
s | string | No | The target resolution in the
|
sopt | string | No | The resolution option. Valid values:
|
scaletype | string | No | The resizing mode. Valid values:
Note This parameter must be used together with the s parameter. |
arotate | int | No | Specifies whether to enable adaptive resolution orientation. Valid values:
|
vb | int | No | The target video bitrate. Unit: bit/s. If you leave both the crf and vb parameters empty, the crf parameter is set to 23 by default. If you specify the vbopt parameter, you must also specify the vb parameter. |
vbopt | int | No | The video bitrate option. Valid values:
|
crf | float | No | The constant rate factor (CRF). The value of this parameter falls within the [0,51] range. A greater value indicates lower quality. We recommend that you specify a value within the [18,38] range. This parameter and the vb parameter are mutually exclusive. If you leave both the crf and vb parameters empty, the crf parameter is set to 23 by default. |
maxrate | int | No | The maximum bitrate if the dynamic bitrate is used. If you specify this parameter, you must also specify the bufsize parameter. Note This parameter must be used together with the crf parameter. |
bufsize | int | No | The size of the buffer in dynamic bitrate mode. Unit: bit/s. Note This parameter must be used together with the crf parameter. |
an | int | No | Specifies whether to disable audio stream generation. Valid values:
|
acodec | string | No | The audio coding format. Valid value: acc. |
ar | int | No | The sampling rate of the output audio. Unit: Hz. By default, the sampling rate of the source audio is retained. Valid values:
|
ac | int | No | The number of sound channels. By default, the output audio has the same number of sound channels as the source audio. Valid values: [1,8]. |
aq | int | No | The audio quality. The value of this parameter falls within the range of 0 to 100. A greater value indicates higher audio quality. This parameter and the ab parameter are mutually exclusive. |
ab | int | No | The target audio bitrate. Unit: bit/s. This parameter and the aq parameter are mutually exclusive. Valid values: 1000 to 10000000. |
abopt | int | No | The audio bitrate option. Valid values:
|
You may also need to use the sys/saveas parameter when you generate a playlist. For more information, see sys/saveas.
Use the RESTful API
To use live transcoding, perform the following steps:
After a playlist is generated, you can also follow the instructions in the Live transcoding topic of the IMM documentation to play the video.
1. Generate a playlist
Transcoding task information
Before transcoding
Video format: AVI
Video name: oss://video-demo/example.avi
Starting position for transcoding: the 15th second of the video
Duration to be transcoded: 1,800 seconds
Processing method: Generate a playlist.
After transcoding
Segment duration: 10 seconds
Pre-transcoded video duration: 30 seconds
Video information
Video stream format: H.264
Video resolution: 1280 × 720
Frame rate: 25 fps
Video bitrate: 2 Mbit/s
Audio information
Audio stream format: AAC
Audio bitrate: 128 Kbit/s
Path prefix: oss://outbucket/outobjprefix/media
Sample 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_b3V0YnVja2V0Sample response
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-transfer-acc-type: acc-none
x-oss-data-location: oss-cn-hangzhou-a
ETag: "D0F162350DA037F4DC2A142B2E116BD0"
Last-Modified: Wed, 25 May 2022 12:20:34 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 2040549661341440100
x-oss-storage-class: Standard
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"}]}2. Use hls/sign to sign TS objects
OSS provides a dynamic signature mechanism for accessing audio and video data. You must add the x-oss-process=hls/sign,live_1 parameter to the URL of an M3U8 playlist the first time you access the M3U8 playlist. Then, OSS automatically signs the URLs of all TS objects in the M3U8 playlist by using the same signing method that is used to sign the M3U8 playlist.
The following sample code provides an example on how to sign an M3U8 playlist by using hls/sign:
# -*- coding: utf-8 -*-
import os
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Specify the endpoint for the region in which the bucket is located.
endpoint = 'yourEndpoint'
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# Specify the name of the bucket in which the generated playlist is stored.
bucket_name = 'your-oss-bucket-name'
# Specify the name of the playlist.
key = 'output/media.m3u8'
# Specify the bucket instance. You must use the bucket instance to call all object-related methods.
# The oss2.AuthV2 signature method must be used.
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', bucket_name)
# Specify hls/sign,live_1 in the x-oss-process operation.
params = {}
params.update({oss2.Bucket.PROCESS: 'hls/sign,live_1'})
# Sign the URL.
# By default, OSS identifies forward slashes (/) in the full path of an object as escape characters in the signing process. Therefore, the signed URL cannot be directly used.
# Set the slash_safe parameter to True. This way, OSS does not identify the forward slashes (/) in the full path of the object as escape characters, and the signed URL can be directly used.
url = bucket.sign_url('GET', key, 7200, params=params, slash_safe=True)
# The generated URL can be directly used in an HLS player for playback.
print(url)
The following content provides an example of an original M3U8 object:
#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-ENDLISTThe following content provides an example of a signed version of the M3U8 object:
#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 OSS SDKs
Playlist generation is a synchronous operation. For more information about how to generate a playlist by using OSS SDKs, see Use OSS SDKs.
FAQ
What are the output objects of a playlist generation operation?
The output objects of a playlist generation operation include M3U8 and TS objects. M3U8 objects are immediately generated. The specified number of pre-transcoded TS objects are asynchronously generated. The portion of the video that is not pre-transcoded is asynchronously transcoded only if a playback of the portion is requested. For example, if a video was not played, no TS objects are generated for the portion that is not included within the range of pre-transcoding. If pre-transcoding does not cover the 15th minute of a video, and you play the video from the 15th minute, transcoding starts from the 15th minute. The following content provides sample output objects of a playlist generation operation:
.
├── 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.ts
Can I play a video whose TS objects are deleted?
Yes, you can play the video even if some or all TS objects are deleted. However, make sure that the video and M3U8 object are not deleted. This is because a request for the M3U8 playlist triggers the regeneration of TS objects. This mechanism allows you to delete TS objects generated for videos that remain unwatched for an extended period of time to reduce storage costs without affecting future playback performance.
Does live transcoding support M3U8 playlists that are not created from live transcoding?
No, live transcoding does not support M3U8 playlists that are not created from live transcoding.