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 -deadline is set to good: Values range from 0 to 5 (and up to 8 in newer versions).
    • 0 is the slowest with the highest quality.
    • 5 or higher is the fastest, resulting in lower quality.
    • Recommended sweet spot: 1 or 2 offers the best quality-to-time ratio for standard encodes.
  • When -deadline is set to realtime: Values range from 5 to 8 (and up to 11 on newer CPU architectures). Higher numbers drastically increase encoding speed at the cost of visual fidelity.

For VP8 Encoding (libvpx):

  • Values range from -16 to 16.
  • Lower values increase quality but take significantly longer.
  • Higher values speed up the process. A setting of 0 is the default.

Command Examples

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.webm

Example 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.webm

Example 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