What are the best FFmpeg settings for WebM?
Optimizing WebM video generation requires a careful balance between file size, visual quality, and encoding speed. This guide details the ideal command-line configurations for FFmpeg using the modern VP9 video codec and Opus audio codec. By utilizing two-pass constrained quality encoding, creators can achieve highly efficient files optimized specifically for web delivery and browser compatibility without suffering massive quality drops.
The Optimal Two-Pass Commmand Line
The recommended approach for encoding web-ready WebM videos is to use a two-pass Constrained Quality (CQ) configuration. This method guarantees excellent visual preservation during high-motion scenes while keeping the file size compact for simpler scenes.
Run the following two commands sequentially in your terminal:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -crf 28 -quality good -speed 4 -tile-columns 2 -row-mt 1 -an -f null /dev/null && \
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -crf 28 -quality good -speed 1 -tile-columns 2 -row-mt 1 -c:a libopus -b:a 128k output.webmBreakdown of Core Settings
Understanding the individual arguments helps in customizing the output to suit specific file requirements:
-c:v libvpx-vp9: Specifies the VP9 video codec, which is the standard choice for modern WebM files, offering significantly superior compression over the legacy VP8 encoder.-crf 28: Sets the Constant Rate Factor. For VP9, the scale ranges from 0 (lossless) to 63 (worst quality). A value between 25 and 35 provides an ideal balance for web deployment.-b:v 2M: Defines the maximum allowed target bitrate (e.g., 2 Megabits per second). In Constrained Quality mode, this acts as a hard ceiling so complex scenes do not bloat the file size.-quality good: Balances overall processing efficiency against encoding precision. The alternative parameter-quality bestmaximizes compression but results in exponentially slower processing times.
Maximizing Multi-Core CPU Performance
The native libvpx-vp9 encoder does not automatically
utilize all available processor cores efficiently. The inclusion of
multi-threading flags avoids bottlenecking the system CPU:
-row-mt 1: Enables row-based multi-threading, which dramatically speeds up encoding on multi-core processors.-tile-columns 2: Splits the video frames into vertical columns to allow parallel processing. Use a value of1for 720p content,2for 1080p content, and3for 4K video.-speed 4(Pass 1) &-speed 1(Pass 2): Speeds up the initial analytical pass without affecting final fidelity. The second pass drops the speed value down to1to focus heavily on precision rendering.
Audio Optimization
-c:a libopus: Selects the Opus audio codec, which is the preferred native pairing for WebM containers due to its stellar audio quality at low bitrates.-b:a 128k: Allocates 128 kbps for standard stereo streams, which is more than sufficient for high-fidelity web playback. For pure speech content, this can safely be lowered to64k.