This topic describes the causes that lead to live streaming latency and how to reduce the latency.

Causes that lead to live streaming latency

Stream ingest
  • A Group of Pictures (GOP) is a collection of keyframes in a video stream and is the basic unit for video encoding and decoding. During live streaming, each frame of data is timestamped and transmitted over networks. A large number of keyframes in a video stream causes live streaming latency.
  • Most third-party stream ingest software increases the encoding cache size to prevent playback stuttering. However, a large encoding cache size causes live streaming latency.
  • The encoding hardware may not meet the requirements of the specified bitrate, frame rate, or encoding profile. This causes encoding latency and impedes smooth streaming.

Server

Before the delivery of a live stream, the server caches a specific amount of streaming data so that the live stream can be instantly loaded and stuttering can be reduced. This ensures the smoothness of live streaming. However, caching data leads to live streaming latency to some extent. During the delivery of a live stream, the data may not be transmitted to the client in real time due to network jitters. This also causes a latency of 2 to 3 seconds.

Streaming

Most streaming clients that do not support fast forwarding decode and play a live stream only when the cache is full. The caching process causes live streaming latency.

Reduce live streaming latency

You can reduce live streaming latency by using the following methods:

  • Stream ingest configuration
    • Set the GOP size to 1 to 2 seconds to reduce the time required by a player to load a GOP. This reduces live streaming latency. For more information about how to set the GOP size in the ApsaraVideo Live console, see Configure custom transcoding. For more information about how to set the GOP size by calling an API operation, see AddCustomLiveStreamTranscode.
    • To reduce live streaming latency that is caused by a large encoding cache size, we recommend that you use Alibaba Cloud Push SDK.
    • On iOS devices that are used for stream ingest, we recommend that you use hardware encoding because it is efficient and power-saving. The performance of Android devices that are used for stream ingest varies with the device type and CPU type, and hardware coding may cause compatibility issues. Therefore, we recommend that you use software encoding on Android devices.
  • Server configuration
    Decrease the cache size to reduce live streaming latency. You can decrease the cache size by specifying lower live streaming latencies for different streaming protocols in the ApsaraVideo Live console.
    1. Log on to the ApsaraVideo Live console.
    2. In the left-side navigation pane of the ApsaraVideo Live console, click Domains. The Domain Management page appears.
    3. Find the streaming domain that you want to configure and click Domain Settings.
    4. Choose Templates > Latency Settings.
    1
    Note After the cache size is decreased, data may fail to be downloaded in a timely manner if the network connection is unstable. In this case, stuttering occurs during live streaming.
  • Streaming protocol
    ApsaraVideo Live supports the following streaming protocols: HTTP Flash Video (HTTP-FLV), HTTP Live Streaming (HLS), and Real-Time Messaging Protocol (RTMP). You can select the appropriate protocol based on your live streaming scenario.
    • HTTP-FLV and RTMP have low latency and are suitable for live streaming scenarios that require low latency. HLS has relatively high latency but is compatible with a wide range of devices. It is suitable for live streaming scenarios that are not sensitive to latency and in which a large number of devices are playing the live stream.
    • HTTP-FLV and RTMP require Flash Player, whereas HLS video streams can be directly played in a browser.
    • You must use HLS if users play your live stream in mobile browsers.
    Note If your streaming client uses HLS, a latency of 10 to 30 seconds is normal. To reduce the latency, you can change HLS to HTTP-FLV.

    The following table describes the differences among HTTP-FLV, HLS, and RTMP.

    Streaming protocolDescriptionTransmission protocolContainer formatApplicable live streaming scenario
    HTTP-FLVIntroduced by Adobe, HTTP-FLV encapsulates streaming data into the FLV format and transmits the data to clients by using the HTTP protocol. The latency is about 2 seconds. HTTP-FLV supports encrypted transmission by using HTTPS. HTTP-FLV is supported on both Android and iOS devices. HTTPFLV and TAGLive streaming with a reduced latency
    HLSIntroduced by Apple, HLS is a media streaming protocol based on HTTP. HLS divides a live stream into consecutive TS segments. The length of each segment is more than 5 seconds. Typically, the playback starts after three to four segments are cached. Therefore, the total latency of HLS live streaming is about 10 to 30 seconds while keeping smooth playback. The HLS protocol applies to iOS devices and is used to provide services such as audio and video streaming and recording. HTTPM3U8 and TSLive streaming across multiple devices
    RTMPIntroduced by Adobe, RTMP splits messages to small chunks during transmission. RTMP transmits the chunks to the receiver by using Transmission Control Protocol (TCP). Then, the receiver decodes the chunks to obtain the streaming data. Splitting a large file is complex, which may lead to instability. For iOS, a third-party decoder is required to play an RTMP stream. HTTPFLV and TAGInteractive live streaming

Real-Time Streaming (RTS)

If you still feel unsatisfied about the latency after you take the preceding measures, you can use Real-Time Streaming (RTS). Compared with conventional live streaming that has a latency of 3 to 6 seconds, RTS supports tens of millions of concurrent playbacks at a latency of milliseconds. RTS is suitable for large-scale interactive live streaming events. You can use RTS to provide live streaming experience that features low latency, stuttering-free, and instant loading.

  • RTS pricing

    The pricing of RTS is different from that of standard streaming. For more information, see Pricing.

  • Enable RTS

    For information about how to enable and use RTS, see Overview.