Configure libvpx Speed Parameter in FFmpeg
This article explains how to configure the speed and quality
trade-offs in FFmpeg when encoding video with the libvpx
(VP8) and libvpx-vp9 (VP9) encoders. You will learn how to
use the key parameters -deadline and -cpu-used
to balance encoding times and output file quality, along with practical
command-line examples.
Understanding the Speed Parameters
To control encoding speed in the libvpx library, FFmpeg relies on two
primary parameters that work together:
-deadline (also referred to as
-speed in newer FFmpeg versions) and
-cpu-used.
1. The -deadline /
-speed Parameter
This parameter sets the overarching quality-to-speed guideline. It accepts three main string arguments:
best: Prioritizes quality above all else. This mode is extremely slow and generally not recommended for everyday use.good: The default and recommended setting for most use cases. It offers an optimal balance of quality and encoding speed.realtime: Prioritizes speed. This is designed for live-streaming and rapid processing where low latency is critical.
2. The -cpu-used
Parameter
Once the deadline is set, -cpu-used fine-tunes the speed
within that mode. The behavior of this parameter depends on whether you
are using VP8 (libvpx) or VP9
(libvpx-vp9).
For VP9 Encoding
(libvpx-vp9):
- When
-deadlineis set togood: Values range from0to5(and up to8in newer versions).0is the slowest with the highest quality.5or higher is the fastest, resulting in lower quality.- Recommended sweet spot:
1or2offers the best quality-to-time ratio for standard encodes.
- When
-deadlineis set torealtime: Values range from5to8(and up to11on newer CPU architectures). Higher numbers drastically increase encoding speed at the cost of visual fidelity.
For VP8 Encoding
(libvpx):
- Values range from
-16to16. - Lower values increase quality but take significantly longer.
- Higher values speed up the process. A setting of
0is the default.
Command Examples
Example 1: High-Quality VP9 Encoding (Recommended)
This command uses the standard good deadline with a
-cpu-used value of 2, which provides excellent
visual quality without taking an unreasonable amount of time.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -deadline good -cpu-used 2 -c:a libopus output.webmExample 2: Fast / Real-time VP9 Encoding
If you need to process a video quickly or are setting up a live
stream, change the deadline to realtime and increase the
-cpu-used value.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -deadline realtime -cpu-used 5 -c:a libopus output.webmExample 3: Standard VP8 Encoding
For legacy compatibility using the VP8 codec, use the following configuration:
ffmpeg -i input.mp4 -c:v libvpx -b:v 2M -metadata:s:v:0 alpha_mode=1 -cpu-used 0 -c:a libvorbis output.webm