How to reduce latency

更新时间:
复制 MD 格式

This topic describes the causes of high live streaming latency and explains how to reduce it.

Causes of live streaming latency

Stream ingest client

  • A Group of Pictures (GOP) is the fundamental unit for video encoding and decoding, and it starts with a keyframe. A large GOP size increases live streaming latency because the playback client must buffer more data before playback can start.

  • Many third-party stream ingest tools increase the encoding buffer to prevent stuttering. However, a large encoding buffer can cause high live streaming latency.

  • If hardware is underpowered, it may struggle to meet the target bitrate, frame rate, or encoding profile settings. This causes encoding delays, which increase overall live streaming latency.

Server-side

To ensure a fast startup and reduce stuttering, the server caches some stream data before playback. This caching introduces some live streaming latency. During playback, network jitter can prevent data from reaching the client, which can add a further 2 to 3 seconds of latency.

Playback client

Most playback clients that do not support fast-forwarding start decoding only after their receive buffer is full. The time it takes to fill this buffer adds to the live streaming latency.

Reduce live streaming latency

To reduce live streaming latency, adjust the following settings:

  • Stream ingest client configuration

    • Set the GOP size to 1 to 2 seconds. This reduces the time that the player needs to load frames and lowers live streaming latency. For information about how to set the GOP size in the console, see Custom transcoding. To configure the GOP size by using an API, see AddCustomLiveStreamTranscode.

    • If an oversized encoding buffer causes high live streaming latency, use the Alibaba Cloud Push SDK to reduce the latency.

    • On iOS, use hardware encoding for its high efficiency and low power consumption. On Android, use software encoding. Due to the wide variety of Android models and CPU types, hardware encoding may cause compatibility issues.

  • Select a streaming protocol

    ApsaraVideo Live supports three streaming protocols: HTTP-FLV, HLS, and RTMP.

    • HTTP-FLV and RTMP offer lower latency and are suitable for real-time playback. HLS has higher latency but offers better compatibility, which makes it a good choice for scenarios that are not sensitive to latency but require playback on a wide range of devices.

    • HTTP-FLV and RTMP require a Flash player. HLS is natively supported by most modern web browsers.

    • To watch live streams in a mobile browser, you must use the HLS streaming protocol.

    Note

    If your playback client uses the HLS protocol, a latency of 10 to 30 seconds is normal. If the latency is unacceptable, you can adjust the server-side settings. For even lower latency, consider switching from HLS to the FLV protocol.

    The following table compares the HTTP-FLV, HLS, and RTMP protocols.

    Protocol

    Description

    Transport protocol

    Container format

    Use case

    HTTP-FLV

    Developed by Adobe. Encapsulates streaming data in FLV format and delivers it over HTTP to clients, with about 2 seconds of latency. Supports encrypted delivery over HTTPS and supports Android.

    HTTP

    FLV, TAG

    Low-latency streaming

    HLS

    Developed by Apple. An HTTP-based streaming protocol. It segments streams into consecutive TS segments. Each segment is longer than 5 seconds, and the stream typically uses 3 to 4 segments, so total latency is about 10 to 30 seconds, with smooth playback. It is mainly used on iOS devices and provides live audio/video streaming and recorded content.

    HTTP

    M3U8, TS

    Cross-platform compatibility

    RTMP

    Developed by Adobe. During transmission, messages are split into smaller chunks and sent over TCP. The receiver reassembles the chunks back into streaming data. This complexity can cause stream instability. On iOS, playback requires a third-party decoder.

    TCP

    FLV, TAG

    Interactive streaming

  • Server-side configuration

    Reduce the server-side cache to decrease live streaming latency. You can configure the latency level in the console for different streaming protocols. A lower latency setting corresponds to a smaller server-side cache.

    1. Log on to the ApsaraVideo Live console.

    2. In the left-side navigation pane, click Domain Names to open the Domain Management page.

    3. Find the streaming domain that you want to configure and click Domain Settings in the Actions column.

    4. Click Streaming Management > Latency Settings.

    The page displays latency level settings for the RTMP, FLV, and HLS protocols. You can click Modify Configuration to adjust them. We recommend that you set the GOP size to 1 to 2 seconds. The actual latency depends on both the latency setting and the GOP size of the ingest stream.

    Note

    A smaller cache can cause stuttering on unstable networks because data cannot be downloaded in time. For more information, see Latency Settings.

Real-Time Streaming (RTS)

If the methods above do not sufficiently reduce latency, consider using Real-time Streaming (RTS). RTS provides millisecond-level latency for tens of millions of concurrent viewers and is ideal for large-scale interactive live streaming. It overcomes the 3- to 6-second delay of standard live streaming and delivers an ultra-low-latency, low-stutter, and fast-startup viewing experience.

  • RTS billing

    RTS is billed differently from standard live streaming. For detailed pricing, see the Alibaba Cloud Pricing page.

  • Activate the RTS service

    To learn how to activate and use the RTS service, see RTS overview.