How to Enable Lossless VP9 Encoding in FFmpeg
This article provides a straightforward guide on how to configure the
FFmpeg command line to achieve true lossless video encoding using the
VP9 codec (libvpx-vp9). You will learn the specific
parameters required to activate this mode, disable lossy compression
algorithms, and preserve maximum color fidelity.
To invoke true lossless encoding in VP9, you must use the
-lossless 1 flag. When this parameter is enabled, the
encoder bypasses standard quantization, rendering quality target
settings (like -crf) and bitrate limits (-b:v)
obsolete.
Here is the standard command line structure for true lossless VP9 encoding:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 output.webmPreserving Color Fidelity (Chroma Subsampling)
By default, video encoders often compress color information using
4:2:0 chroma subsampling. To ensure your output is mathematically
lossless not just in compression, but also in color representation, you
should specify the yuv444p pixel format. This is especially
important for screen recordings, animations, or graphics containing
sharp text.
Use the following command to enforce lossless color representation:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -pix_fmt yuv444p output.webmControlling Encoding Speed
Lossless encoding is highly CPU-intensive. You can control the
encoding speed and efficiency trade-off using the -cpu-used
parameter. This parameter accepts values from 0 to
5: * Lower values (e.g., -cpu-used 0) offer
the best compression ratio (smallest file size) but take the longest
time to encode. * Higher values (e.g., -cpu-used 5) encode
much faster but result in slightly larger file sizes.
Example with speed optimization:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -pix_fmt yuv444p -cpu-used 2 output.webm