Encode VP9 Profile 2 10-Bit Video in FFmpeg
This guide provides a straightforward, step-by-step tutorial on how to encode video using the Google VP9 Profile 2 (10-bit color) codec in FFmpeg. You will learn the exact command-line arguments required to target 10-bit color depth, set the appropriate pixel format, and configure your encoding settings for optimal quality and compatibility.
Understanding VP9 Profile 2
The VP9 codec is divided into different profiles based on color depth and chroma subsampling. To achieve 10-bit color depth with standard 4:2:0 chroma subsampling, you must target Profile 2. Encoding in 10-bit is highly beneficial for high-dynamic-range (HDR) content and for reducing color banding in gradients.
To trigger VP9 Profile 2 in FFmpeg, you must use the
libvpx-vp9 encoder and specify a 10-bit pixel format, such
as yuv420p10le.
The Standard FFmpeg Command
The most effective way to encode to VP9 Profile 2 is by using the Constrained Quality (CQ) mode. This mode guarantees a consistent level of quality throughout the video.
Here is the recommended command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -profile:v 2 -crf 30 -b:v 0 -c:a libopus output.webmCommand Breakdown
-i input.mp4: Specifies your source input file.-c:v libvpx-vp9: Selects the Google VP9 video encoder.-pix_fmt yuv420p10le: Sets the pixel format to 10-bit YUV 4:2:0. This is the crucial setting that forces FFmpeg to use 10-bit color.-profile:v 2: Explicitly instructs the encoder to use VP9 Profile 2.-crf 30: Sets the Constant Rate Factor. Lower values mean better quality but larger file sizes. For 10-bit VP9, a CRF range of 15 to 35 is recommended, with 30 being a good balance for 1080p content.-b:v 0: Must be set to0when using CRF mode to enable true constant quality encoding.-c:a libopus: Encodes the audio to Opus, which is the standard high-quality audio pair for WebM and VP9.
Recommended: 2-Pass Encoding for Best Quality
For the highest quality results, especially if you have a target file size or bitrate in mind, a 2-pass encoding method is recommended.
Pass 1:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -profile:v 2 -b:v 2M -speed 4 -pass 1 -an -f null /dev/null(On Windows, replace /dev/null with
NUL)
Pass 2:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -pix_fmt yuv420p10le -profile:v 2 -b:v 2M -speed 1 -pass 2 -c:a libopus -b:a 128k output.webmKey Parameters for 2-Pass:
-b:v 2M: Sets the target bitrate to 2 Megabits per second. Adjust this based on your resolution (e.g., use higher bitrates like 5M–10M for 4K).-speed: Controls the encoding speed vs. quality tradeoff. Value4is used in pass 1 for fast analysis, while1or2is used in pass 2 for high-quality final compression.-an: Disables audio during the first pass to speed up processing.