All Products
Search
Document Center

ApsaraVideo Live:Live Stream Encapsulation

Last Updated:Feb 12, 2025

ApsaraVideo Live offers live stream encapsulation services, supporting playback protocols such as HLS, DASH, and LL-HLS (low latency HLS), and accommodating TS and CMAF segment formats. This topic details the live stream encapsulation feature.

Introduction

ApsaraVideo Live supports streaming protocols including Real-Time Messaging Protocol (RTMP), HTTP-FLV, and HTTP Live Streaming (HLS). For scenarios requiring reduced latency, ApsaraVideo Live has added support for CMAF and LL-HLS through its live stream encapsulation feature. This allows for the use of LL-HLS - TS, LL-HLS - CMAF, HLS - CMAF, Dynamic Adaptive Streaming over HTTP (DASH) - CMAF, or HLS & DASH - CMAF for live stream encapsulation based on segment type, as illustrated in the table below:

Segment Type

Supported Encapsulation Protocols

Supported Encoding Formats

TS

LL-HLS - TS

  • Audio encoding formats: AAC, OPUS, AC3, EAC3, and MP3

  • Video encoding formats: H.264 and H.265

CMAF

  • LL-HLS - CMAF

  • HLS - CMAF

  • DASH - CMAF

  • HLS & DASH - CMAF

  • Audio encoding format: AAC

  • Video encoding formats: H.264 and H.265

Note

LL-HLS - TS encapsulates the low-latency HLS protocol in TS Format, while LL-HLS - CMAF does so in CMAF Format, among others.

Features and Advantages

  • Once live stream encapsulation is enabled, the live video stream is segmented into TS or CMAF segments and distributed via HLS or LL-HLS protocols. The M3U8 playlist requested by users is continuously updated with new segment URLs.

  • LL-HLS can segment streams into smaller parts (0.2 to 1 second) and supports blocking loading to achieve latencies of 3 to 5 seconds. CMAF format offers broader device and browser support and newer codecs like H.265, compared to the TS format.

  • The live stream encapsulation service, when used alongside live stream transcoding (including multi-bitrate transcoding) and time shifting, offers versatile and comprehensive functionalities.

Scenarios

Low Latency Live Streaming: Our live streaming service offers HLS playback URLs. To achieve lower latency in your business scenarios while maintaining HLS protocol compatibility, consider encapsulating the HLS protocol with the LL-HLS (low latency HLS) protocol.

Multi-device Browser Support: By default, the HLS playback URLs offered by the live streaming service are encapsulated in the TS segment format. Should you require a different format to meet your business needs, the encapsulation feature allows you to package the content in CMAF format, ensuring compatibility across a wider range of devices and browsers.

Precautions

For smooth playback of CMAF and LL-HLS, the GOP size of the stream ingest must be consistent, and the segment length for live stream encapsulation should be an integer multiple of the GOP length. If transcoded streams are included in the encapsulation settings, their GOP size must also be stable.

For the LL-HLS protocol, consider the following:

  • The stuttering rate may increase under poor network conditions. It's recommended to use live stream encapsulation with multi-bitrate transcoding, allowing the bitrate to adjust automatically and reduce stuttering.

  • Ensure the GOP size of the live stream is fixed at 1 or 2 seconds to prevent stuttering or playback failure.

  • You need to use a player compatible with LL-HLS, such as AliPlayer, hls.js, or ExoPlayer.

  • The same host stream domain name can support up to 100,000 viewers. To support additional viewers, please or submit a ticket for support.

  • When you configure encapsulation for a domain name for the first time, domain acceleration is automatically configured and takes effect within 3 to 5 minutes.

Function Usage

Configure Live Stream Encapsulation

ApsaraVideo Live currently supports two methods for configuring the live stream encapsulation feature.

Console Configuration for Live Stream Encapsulation

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, click Feature Management > Live Stream Encapsulation .

  3. Click on the streaming domain name you want to configure, then select Add.

    image

    The table below describes the parameters you can configure.

    Parameter

    Description

    AppName

    • The name must be the same as the application name that is specified in the ingest URL. Otherwise, the encapsulation settings do not take effect.

    • The name can be up to 256 characters in length and can contain digits, letters, hyphens (-), and underscores (_).

    • You can also set this parameter to an asterisk (*) to specify any string, including an empty string.

    StreamName

    • The name must be the same as the stream name that is specified in the ingest URL. Otherwise, the encapsulation settings do not take effect.

    • The name can be up to 256 characters in length and can contain digits, letters, hyphens (-), and underscores (_).

    • You can also set this parameter to an asterisk (*), which indicates any string, including an empty string.

    Protocol Configuration

    Select the protocol for encapsulation. Valid values:

    • HLS - CMAF

    • LL-HLS - CMAF

    • LL-HLS - TS

    • DASH - CMAF

      Note

      Only DASH is supported

    • HLS & DASH - CMAF

      Note

      Both DASH and HLS are supported

    Number of Segments

    Specify the number of segments. You can enter an integer from 3 to 5.

    Segment Length

    • Valid values if you set the Protocol parameter to HLS - CMAF, DASH - CMAF, or HLS & DASH - CMAF: integers from 1 to 10. Unit: seconds. Make sure that the segment length is an integer multiple of the GOP length. The GOP length must be a fixed value. We recommend that you set the GOP length to 5 seconds.

    • Valid values if you set the Protocol parameter to LL-HLS - CMAF or LL-HLS - TS: integers from 1 to 2. Unit: seconds. Make sure that the segment length is an integer multiple of the GOP length. The GOP length must be a fixed value. We recommend that you set the GOP length to 1 second.

    Part Segment Length

    This parameter is required only if you set the Protocol parameter to LL-HLS - CMAF or LL-HLS - TS. Valid values: integers from 200 to 1000. Unit: milliseconds. We recommend that you specify a value that is slightly larger than one-third of the segment length.

    Transcoded Stream

    Valid values: Source Stream Only and Transcoded Stream Included.

    Note
    • If the time shifting feature is configured for a matched stream, the segment length and format set in the encapsulation settings will apply during time shifting of the stream.

    • If multi-bitrate transcoding is configured for a matched stream, the segment length and format set in the encapsulation settings will apply during multi-bitrate transcoding of the stream.

    • If the playback domain name's region is outside China (Singapore, Germany, Japan, or Indonesia), there may be a significant delay. After completing the configuration, it's recommended to test and verify if the results meet your expectations.

  4. After configuring the parameters, click OK.

API Configuration for Live Stream Encapsulation

//Replace <> with actual values
DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
IAcsClient client = new DefaultAcsClient(profile);
AddLivePackageConfigRequest addLivePackageConfigRequest = new AddLivePackageConfigRequest();
addLivePackageConfigRequest.setDomainName("<DomainName>");
//The name can be up to 256 characters in length and can contain digits, letters, hyphens (-), and underscores (_).
//You can also set this parameter to an asterisk (*) to specify any string, including an empty string.
addLivePackageConfigRequest.setAppName("<AppName>");
//The name can be up to 256 characters in length and can contain digits, letters, hyphens (-), and underscores (_).
//You can also set this parameter to an asterisk (*) to specify any string, including an empty string.
addLivePackageConfigRequest.setStreamName("<StreamName>");
//Live stream protocol and encapsulation format.
addLivePackageConfigRequest.setBizProtocol("<Protocol>");
//The number of M3U8 segments. You can enter an integer from 3 to 5.
addLivePackageConfigRequest.setSegmentNum(<3>);
//Segment length. Unit: seconds.
//Valid values if you set the Protocol parameter to LL-HLS: integers from 1 to 2. Unit: seconds. Make sure that the segment length is an integer multiple of the GOP length. The GOP length must be a fixed value. We recommend that you set the GOP length to 1 second.
//Valid values if you set the Protocol parameter to HLS or DASH: integers from 1 to 10. Unit: seconds. Make sure that the segment length is an integer multiple of the GOP length. The GOP length must be a fixed value. We recommend that you set the GOP length to 5 seconds.
addLivePackageConfigRequest.setSegmentDuration(<5>);
//Part segment length. This parameter takes effect only when you set the Protocol parameter to LL-HLS. Valid values: integers from 200 to 1000. Unit: milliseconds. We recommend that you specify a part length that is slightly more than one third of the segment length.
addLivePackageConfigRequest.setPartDuration(<350>);
//Whether to ignore transcoded streams. Default value: true.
addLivePackageConfigRequest.setIgnoreTranscode(<true>);
try {
      AddLivePackageConfigResponse addLivePackageConfigResponse = client.getAcsResponse(addLivePackageConfigRequest);
      System.out.println(new Gson().toJson(addLivePackageConfigResponse));
       // todo something.
 } catch (ServerException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
 } catch (ClientException e) {
      // TODO Auto-generated catch block
       e.printStackTrace();
 }
Note
  • For a list of valid <Protocol> values and additional details on the API, refer to AddLivePackageConfig.

  • For more information on how to use the Java SDK, see Java SDK Instructions.

  • The configuration will only take effect after you re-push the stream.

  • Once the protocol encapsulation is configured, the original quality streaming URL can still be used normally.

Use Live Stream Encapsulation

Stream Ingest

To ensure smooth playback of CMAF and LL-HLS when using live stream encapsulation, maintain a stable GOP size for the stream ingest.

You can configure OBS Stream Ingest as follows (for additional details on OBS, refer to OBS Streaming Tool):

image.png

Playback

Different encapsulation protocols necessitate different playback URLs. Below are examples of playback URLs corresponding to each encapsulation protocol:

Encapsulation Protocol

URL Example

HLS

http://<DomainName>/<AppName>/<StreamName>.m3u8?aliyunols=on&auth_key=1725503*****

DASH

http://<DomainName>/<AppName>/<StreamName>.mpd?aliyunols=on&auth_key=17255038******

Low Latency HLS

http://<DomainName>/<AppName>/<StreamName>-llhls.m3u8?aliyunols=on&auth_key=1725503******
Note
  • When playing encapsulated streams, the aliyunols=on parameter is mandatory.

  • The protocol URLs provided by each encapsulation format are as follows:

    • LL-HLS - TS: This refers to the low-latency HLS URL and the standard HLS URL.

    • LL-HLS - CMAF: This refers to the low-latency HLS URL and the standard HLS URL.

    • HLS - CMAF: This refers to the HLS URL.

    • DASH - CMAF: This is the DASH URL.

    • HLS & DASH - CMAF: URLs for HLS and DASH.

  • We recommend using ApsaraVideo Player. For more details on ApsaraVideo Player, see Player SDK.

  • When using ApsaraVideo Player's web version or playing content directly through the console, you must set up HTTPS certificates and enable cross-domain access. For details on HTTPS certificate configuration, see Configure HTTPS Secure Acceleration. For cross-domain access settings, refer to Configure HTTP Headers.

Use the following example to play with the web version of ApsaraVideoPlayer:

image

  1. Choose the playback type as Live.

  2. Enter the streaming URL.

  3. Click Play Preview to start playback.

Important
  • To enable cross-domain playback in browsers, configure the HTTP header Access-Control-Allow-Origin. For more information, see Configure HTTP Headers.

Advanced Usage

Encapsulate Transcoded Streams

Combine the live stream encapsulation feature with transcoding to encapsulate transcoded streams.

Before encapsulating transcoded streams, you must configure the live stream transcoding feature. For more information, see Live Stream Transcoding.

This section assumes you have already configured the transcoding feature.

When configuring encapsulation, ensure to also encapsulate the Transcoded Stream.

//Whether to ignore transcoded streams. Valid values: true/false. Default value: true
addLivePackageConfigRequest.setIgnoreTranscode(<false>);

To play encapsulated transcoded streams, simply replace the StreamName in the encapsulation protocol URL with StreamName followed by _Transcoding Template ID.

For instance, to play a Low Latency HLS transcoded stream, the sample URL would be:

http://<DomainName>/<AppName>/<StreamName_Transcoding Template ID>-llhls.m3u8?aliyunols=on&auth_key=1725503******
Note
  • We recommend using the encapsulation feature alongside the Multi-bitrate Transcoding feature to automatically optimize bitrate for playback under poor network conditions.

  • To play streams using Multi-bitrate Transcoding, simply replace the StreamName with StreamName followed by _Transcoding Template Group ID.

Important
  • When using Multi-bitrate Transcoding for stream encapsulation, the resulting transcoded stream URLs will vary based on the chosen protocol and segment format. For instance, if the encapsulation format is set to DASH - CMAF, only DASH transcoded stream URLs will be generated, while HLS URLs will not be available.

  • When using default or custom transcoding, the URLs of the transcoded streams remain unchanged, and an additional Encapsulation URL for the transcoded stream is provided.

  • For more information on encapsulation URLs, refer to the Playback section of this document.

Time-shifted Playback of Encapsulated Streams

The time shifting feature enables viewers to replay live content during a broadcast. You can use the Live Stream Encapsulation in conjunction with the Time Shifting feature. For more information, see Time Shifting.

Note

When time shifting is enabled, the time-shifted content will adopt the segment length and format defined by the live stream encapsulation. For HLS or LL-HLS - CMAF formats, the segments for time shifting will be in CMAF format. In the case of LL-HLS - TS format, the segments will maintain the TS format.

References

APIs Related to Live Stream Encapsulation