Configure libvpx Threads in FFmpeg
Optimizing video encoding speed and CPU utilization in FFmpeg
requires properly configuring the threads parameter when
using the VP8 (libvpx) or VP9 (libvpx-vp9)
encoders. This article provides a straightforward guide on how to set
the -threads parameter, use companion settings like
row-based multithreading, and configure tile columns to maximize
encoding performance across your CPU cores.
The Basic Threads Parameter
To limit or assign the number of CPU threads the libvpx
encoder can use, pass the -threads option to your FFmpeg
command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -threads 8 output.webmIn this command: * -c:v libvpx-vp9 specifies the VP9
encoder. * -threads 8 instructs the encoder to use up to 8
threads.
Why
-threads Alone Is Not Enough for VP9
Unlike other encoders like libx264, simply increasing
the thread count in libvpx-vp9 will not automatically
utilize all your CPU cores. The VP9 encoder processes videos by
splitting frames into vertical columns called tiles. To
utilize multiple threads, you must also define these tiles using the
-tile-columns parameter.
1. Setting Tile Columns
The value for -tile-columns is represented as a power of
2 (\(2^N\)).
-tile-columns 1= 2 tiles (uses up to 2 threads)-tile-columns 2= 4 tiles (uses up to 4 threads)-tile-columns 3= 8 tiles (uses up to 8 threads)-tile-columns 4= 16 tiles (uses up to 16 threads)
Note: The maximum number of tile columns is constrained by the
resolution of your source video. For example, 1080p video supports up to
4 tile columns (-tile-columns 2).
2. Enabling Row-Based Multithreading
To significantly improve thread utilization without sacrificing video
quality, you should enable row-based multithreading
(-row-mt 1). This allows the encoder to run threading
across rows within the tiles.
Recommended Multi-Threaded FFmpeg Command
To fully utilize a modern multi-core processor (for example, an 8-core CPU) when encoding to VP9, use the following command structure:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -threads 8 -tile-columns 2 -row-mt 1 output.webmParameter Breakdown:
-threads 8: Sets the maximum thread limit to 8.-tile-columns 2: Splits the video into 4 tile columns, allowing parallel processing.-row-mt 1: Enables row-based multi-threading to distribute the workload efficiently across all 8 designated threads.