Best Practices for VP9 Lossless Video Archiving
This article outlines the essential best practices for preserving
high-quality master video files using the libvpx-vp9
lossless encoder. You will learn the correct FFmpeg command-line
parameters, pixel format configurations, and compression settings
required to maintain pixel-perfect accuracy while maximizing storage
efficiency.
Enable True Lossless Mode
Unlike other encoders that achieve losslessness through a constant
rate factor (CRF) of 0, the VP9 encoder requires an explicit flag. To
activate lossless compression in FFmpeg, you must set the
-lossless 1 parameter. When this flag is enabled, the
encoder bypasses quantization, ensuring the output video is
mathematically identical to the source.
Maintain Correct Pixel Formats
To prevent color degradation and quality loss during transcoding, you
must match the output pixel format to your master source. If your source
video uses high-chroma or high-bit-depth color, specify the correct
-pix_fmt flag.
- For 8-bit YUV 4:2:0: Use
-pix_fmt yuv420p - For 10-bit YUV 4:2:2: Use
-pix_fmt yuv422p10le - For 10-bit YUV 4:4:4: Use
-pix_fmt yuv444p10le - For RGB/GBR sources: Use
-pix_fmt gbrp(VP9 maps RGB to the GBR planar format natively)
Failing to define the correct pixel format can cause FFmpeg to default to a lower chroma subsampling (like 4:2:0), resulting in lossy color conversion before the encoding even begins.
Optimize Compression with CPU-Used Settings
Lossless encoding is mathematically heavy. You can control the
trade-off between encoding speed and file size using the
-cpu-used parameter (also referred to as the speed
setting).
For archiving purposes, file size reduction is usually more important
than encoding speed. Setting -cpu-used 0 or
-cpu-used 1 forces the encoder to use its most advanced
compression algorithms, resulting in the smallest possible lossless file
size. If you need to process large batches of archives quickly, you can
increase this up to -cpu-used 4, though this will result in
slightly larger file sizes.
Choose the Right Container
While VP9 is commonly associated with the WebM (.webm)
container, the Matroska (.mkv) container is highly
recommended for master file archiving. Matroska supports a wider variety
of professional lossless audio codecs (such as FLAC and PCM), possesses
robust metadata capabilities, and features superior error recovery
properties.
Select a Lossless Audio Codec
A true master archive requires lossless audio to accompany the
lossless video. Avoid compressing your audio to lossy formats like AAC
or Opus. Instead, use -c:a copy to copy the original PCM
audio stream without re-encoding, or use -c:a flac to
compress the audio losslessly and save additional storage space.
Recommended Command Template
The following FFmpeg command combines these best practices into a single execution line for archiving a 10-bit YUV 4:2:2 master file with FLAC audio:
ffmpeg -i input_master.mov -c:v libvpx-vp9 -lossless 1 -pix_fmt yuv422p10le -cpu-used 0 -c:a flac output_archive.mkv