All Products
Search
Document Center

ApsaraVideo Live:Live stream encapsulation

Last Updated:Jul 23, 2024

ApsaraVideo Live provides the live stream encapsulation feature that supports segment formats such as Common Media Application Format (CMAF) and streaming protocols such as Low-Latency HTTP Live Streaming (LL-HLS), which can effectively reduce the live streaming latency. This topic describes the details of the live stream encapsulation feature.

Overview

ApsaraVideo Live supports streaming protocols such as Real-Time Messaging Protocol (RTMP), HTTP-FLV, and HTTP Live Streaming (HLS). To improve user experience in scenarios that require lower latency, ApsaraVideo Live adds support for CMAF and LL-HLS by using the live stream encapsulation feature. This way, you can use LL-HLS - TS, LL-HLS - CMAF, HLS - CMAF, Dynamic Adaptive Streaming over HTTP (DASH) - CMAF, or HLS & DASH - CMAF to encapsulate live streams based on the type of segments, as shown in the following table:

Segment type

Supported encapsulation protocol

Supported encoding format

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

Functions and benefits

  • After you enable the live stream encapsulation feature, a live stream is sliced into Transport Stream (TS) or CMAF segments. These segments are distributed to viewers over the HLS or LL-HLS protocol, and the corresponding URLs in the M3U8 playlist are constantly updated.

  • Compared with HLS, LL-HLS can further divide these segments into smaller parts (with a duration of 200 milliseconds to 1 second) and block playlist reloads, which reduces the end-to-end latency to 3 to 5 seconds. Compared with TS, CMAF is compatible with a broader range of devices and browsers and supports newer codecs such as H.265.

  • You can use live stream encapsulation together with other features such as transcoding (including multi-bitrate transcoding) and time shifting to enjoy richer and more flexible capabilities.

Usage notes

Make sure that the group of pictures (GOP) size of the live stream is stable and that the segment length is equal to or an integer multiple of the GOP size. If you specify that the encapsulation settings take effect for the transcoded stream, you must also ensure that the GOP size of the transcoded stream is stable.

If you use LL-HLS, take note of the following points:

  • We recommend that you use live stream encapsulation together with multi-bitrate transcoding. This way, the bitrate can be automatically adjusted in poor network conditions to reduce stuttering.

  • Make sure that the GOP size of the live stream is fixed at 1 second or 2 seconds. Otherwise, stuttering occurs or playback fails.

  • You must use a player that supports LL-HLS, such as ApsaraVideo Player, HLS.js, or ExoPlayer. We recommend that you use ApsaraVideo Player.

  • A main streaming domain supports up to 100,000 viewers. If you want to increase the quota, submit a ticket. For more information, see Contact us.

Use the feature

  1. Configure live stream encapsulation settings by using the ApsaraVideo Live console or by calling the AddLivePackageConfig operation.

    The following sample code provides an example on how to configure live stream encapsulation settings in Java:

    // Replace the parameters in <> 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>");
    addLivePackageConfigRequest.setAppName("<AppName>");
    addLivePackageConfigRequest.setStreamName("<StreamName>");
    addLivePackageConfigRequest.setBizProtocol("<Protocol>");
    
    //
    // Other business code
    //
    
    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();
     }
  2. Start stream ingest. Make sure that the ingest domain, application name, and stream name are the same as those specified in the encapsulation settings, and that the GOP size of the live stream is stable.

    In this example, Open Broadcaster Software (OBS) is used to ingest the stream. The following figure shows the recommended parameter settings.

    image.png

    For more information about how to use OBS, see OBS.

  3. Obtain the streaming URL of the corresponding protocol and use a player that supports LL-HLS to play the stream. We recommend that you use ApsaraVideo Player.

    In this example, ApsaraVideo Player is used to play the stream. The following figure shows the recommended parameter settings.image.png

    1. Set Video Type to Broadcast.

    2. Enter the streaming URL.

      Important

      If you require cross-origin playback in your browser, you must configure the Access-Control-Allow-Origin header. For more information, see Configure HTTP headers.

      • A streaming URL for encapsulation is similar to a regular URL in the HLS format. The following sample code provides an example:

        HLS:
        http://example.com/AppName/StreamName.m3u8?aliyunols=on
        
        LL-HLS:
        http://example.com/AppName/StreamName-llhls.m3u8?aliyunols=on
        Note
        • aliyunols=on is required. If this field is not specified, the regular HLS stream is played.

        • When LL-HLS is specified in the encapsulation settings, the streaming URL in the HLS format is also provided.

        • If URL signing is enabled, you need to add the auth_key=<Encryption key> field to the URL.

      • You can use live stream encapsulation together with multi-bitrate transcoding. When multi-bitrate transcoding is enabled, the segment format specified by the encapsulation settings is used in the encapsulation.

        HLS:
        http://example.com/AppName/StreamName_MBRGroupId.m3u8?aliyunols=on
        
        LL-HLS:
        http://example.com/AppName/StreamName_MBRGroupId-llhls.m3u8?aliyunols=on
        Note

        MBRGroupId is the ID of the template group for multi-bitrate transcoding.

      • You can use live stream encapsulation together with time shifting. When time shifting is enabled, the segment length and format specified by the encapsulation settings are used in the encapsulation. If HLS - CMAF or LL-HLS - CMAF is specified, the encapsulated segment format for time shifting is CMAF. If LL-HLS - TS is specified, the encapsulated segment format for time shifting is TS.

    3. Click the Preview tab.

API references

Live stream encapsulation