How to Encode VP9 Video Using FFmpeg
This article provides a straightforward guide on how to encode video files into the VP9 format using FFmpeg. You will learn the basic command structure, key parameters for controlling quality and speed, and the recommended two-pass encoding method for achieving optimal compression.
To encode a video to VP9 (using the libvpx-vp9 library),
FFmpeg uses a specific command structure. Below are the standard methods
for encoding, ranging from simple single-pass to high-quality two-pass
workflows.
Constant Quality (Recommended)
For most general purposes, the Constant Quality (CRF) mode is
recommended. Unlike other encoders, VP9 requires you to set the video
bitrate limit to 0 (-b:v 0) to enable pure CRF
mode.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webmKey Parameters Explained: *
-c:v libvpx-vp9: Specifies the VP9 video encoder. *
-crf 30: Sets the Constant Rate Factor. The range is 0 to
63. Lower values mean better quality (recommended range is 15–35; 31 is
the default). * -b:v 0: Must be set to 0 to
allow the CRF value to solely determine the quality. *
-c:a libopus: Encodes the audio to Opus, the standard
companion audio codec for VP9/WebM.
Two-Pass Encoding (Best Compression)
For the best possible video quality at a targeted file size or bitrate, two-pass encoding is highly recommended.
Pass 1:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -speed 4 -pass 1 -an -f null /dev/null(Note: On Windows, replace /dev/null with
NUL)
Pass 2:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -speed 1 -pass 2 -c:a libopus output.webmKey Parameters for Two-Pass: * -b:v 2M:
Target video bitrate (e.g., 2 Megabits per second). *
-speed: Adjusts encoding speed from 0 (slowest/best
quality) to 5 (fastest). Use a higher speed (like 4) for the first pass
to save time, and a lower speed (like 1 or 2) for the second pass to
maximize quality. * -an: Disables audio during the first
pass to speed up processing. * -pass 1 /
-pass 2: Tells FFmpeg which pass of the analysis it is
executing.