How to Encode Lossless VP9 Video with FFmpeg

This guide explains how to configure the libvpx-vp9 encoder in FFmpeg for mathematically lossless video compression. You will learn the specific command-line parameters required to activate lossless mode, understand how pixel formats affect the output, and see practical command examples to implement this in your video processing workflows.

To achieve true lossless compression with the VP9 encoder (libvpx-vp9) in FFmpeg, you must explicitly set two key parameters: -lossless 1 and -crf 0.

The Lossless Command Syntax

The basic command structure for encoding a lossless VP9 video is as follows:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -crf 0 output.webm

Parameter Breakdown

Controlling Encoding Speed and Compression

Lossless encoding produces large file sizes. You can optimize the compression efficiency (file size vs. encoding time) using the -cpu-used parameter:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -crf 0 -cpu-used 1 output.webm

Pixel Format Considerations

By default, FFmpeg will attempt to match the input’s pixel format. However, for maximum compatibility and to avoid quality loss during color space conversion, you should explicitly define the pixel format using the -pix_fmt flag.

For Standard YUV 4:2:0 Video:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -crf 0 -pix_fmt yuv420p output.webm

For RGB Source Material (e.g., Screen Recordings):

VP9 supports lossless RGB encoding, which is ideal for screencasts to prevent color bleeding:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 -crf 0 -pix_fmt gbrp output.webm