Configure Wavelet and Block Size in FFmpeg Snow
This article provides a quick guide on how to configure the discrete wavelet transform (DWT) type and the motion estimation block size when encoding video with the experimental Snow codec in FFmpeg. By customizing these two key parameters, you can fine-tune the encoder for either high-efficiency lossy compression or mathematically lossless archival.
Configuring the Wavelet Type
The Snow encoder utilizes wavelet transform instead of the
traditional Discrete Cosine Transform (DCT) found in codecs like H.264.
You can select the wavelet transform type using the -pred
option. Snow supports two primary wavelet types:
- 5/3 Lifting Wavelet (
-pred 0): This is an integer-based wavelet transform. It is the required setting if you want to perform lossless compression. It is computationally faster but slightly less efficient for lossy compression. - 9/7 Lifting Wavelet (
-pred 1): This is a floating-point-based wavelet transform. It offers superior compression efficiency and better visual quality for lossy compression at lower bitrates, but it cannot be used for strictly lossless encoding.
Example command for 9/7 lossy compression:
ffmpeg -i input.mp4 -c:v snow -pred 1 output.mkvConfiguring the Block Size
Snow relies on Overlapping Block Motion Compensation (OBMC) for
motion estimation. You can control the size of the blocks used for this
process with the -block option. Adjusting the block size
allows you to balance encoding speed, file size, and motion
accuracy:
- Large Blocks (
-block 0): Uses larger 16x16 blocks. This setting is faster to encode and works well for videos with low motion or flat backgrounds, but it may introduce artifacts around complex moving edges. - Small Blocks (
-block 1): Uses smaller 8x8 blocks. This setting provides much better tracking of complex, fast-moving objects and reduces motion artifacts, though it increases encoding time and computational overhead.
Example command for 8x8 block size:
ffmpeg -i input.mp4 -c:v snow -block 1 output.mkvCombining Settings for Optimal Encoding
To achieve the best results, you should configure both settings in a
single command line alongside a quality-scale factor
(-qscale or -q:v) to control the output
bitrate.
For High-Quality Lossy Video (using 9/7 wavelet and 8x8 blocks):
ffmpeg -i input.mp4 -c:v snow -pred 1 -block 1 -q:v 3 output.mkvFor Lossless Video (using 5/3 wavelet and 8x8 blocks):
ffmpeg -i input.mp4 -c:v snow -pred 0 -block 1 -q:v 0 output.mkv