Libvpx-VP9 Deadline Setting for Low Latency Live Streaming
To achieve ultra-low latency in live streaming using the
libvpx-vp9 codec, configuring the correct encoder deadline
is essential. This article explains why the realtime
deadline setting is the definitive choice for minimizing encoding delay,
how it compares to other modes, and the optimal FFmpeg parameters to
pair with it for high-performance live broadcasts.
The Optimal Deadline
Setting: realtime
When streaming live video using the libvpx-vp9 encoder
in FFmpeg, you must set the -deadline parameter to
realtime (also configurable as
-quality realtime in modern versions of FFmpeg).
The libvpx-vp9 library offers three primary deadline
modes that dictate the trade-off between encoding speed and compression
efficiency: * best: Prioritizes quality
and compression ratio, resulting in extremely slow encoding speeds. This
is unsuitable for live streaming. * good:
The default mode, balanced for standard file-based transcoding. *
realtime: Forcefully prioritizes
processing speed to ensure the encoder processes frames at or faster
than the input frame rate, which is mandatory to prevent latency
build-ups during a live stream.
Critical Companion Settings for Low Latency
Simply setting -deadline realtime is often not enough to
achieve true low-latency VP9 streaming. You must pair it with the
following configuration options in your FFmpeg command:
1. The -cpu-used
Parameter
In realtime mode, the -cpu-used parameter
acts as a speed modifier. It accepts integer values from 0
to 8 (and up to 9 or 11 on newer
library versions). * For live streaming, use a value between
5 and 8. * Higher numbers
(e.g., -cpu-used 8) significantly increase encoding speed
and lower latency at the cost of a minor reduction in compression
efficiency.
2. Threading Options
Enable multi-threading to distribute the encoding workload across
your CPU cores. Use the following flags: * -tile-columns 2
or 3 (enables multi-threaded tile encoding) *
-frame-parallel 1 (allows parallel frame processing) *
-threads [number of CPU threads]
Recommended FFmpeg Command Example
To stream live with VP9 at minimum latency, your FFmpeg command should look similar to this:
ffmpeg -i input_stream -c:v libvpx-vp9 -deadline realtime -cpu-used 8 -tile-columns 2 -frame-parallel 1 -threads 8 -f flv rtmp://live-endpointBy combining -deadline realtime with an aggressive
-cpu-used value, you ensure that the VP9 encoder operates
fast enough to maintain a continuous, low-latency live broadcast.