Configure Dither Filter and Range in FFmpeg zscale

The FFmpeg zscale filter, which leverages the high-performance zimg library, is an advanced alternative to the default scale filter. It offers superior quality for image resizing, bit depth conversion, and color space transformations. This article provides a direct, practical guide on how to configure the dither, scaling filter, and color range parameters within zscale to achieve optimal video encoding results.

The Basic Syntax

The zscale filter uses a key=value format, with parameters separated by colons. The basic syntax for configuring dither, scaling filter, and range looks like this:

zscale=dither=dither_type:filter=filter_type:range=range_type:in_range=input_range_type

1. Configuring Dither

Dithering is crucial when reducing bit depth (for example, converting 10-bit HDR video to 8-bit SDR) because it prevents color banding. You can configure this using the dither (or d) parameter.

Available Dither Types:

Example:

zscale=dither=error_diffusion

2. Configuring the Resampling Filter

The scaling filter determines the mathematical algorithm used to resize the video frame. You can configure this using the filter (or f) parameter.

Available Filter Types:

Example:

zscale=filter=lanczos

3. Configuring Color Range

Color range defines the luminance levels of the video. It is critical to set this correctly to avoid washed-out blacks or crushed highlights. Use the range (or r) parameter for output, and in_range for input.

Available Range Types:

Example:

To convert a limited-range input to a full-range output:

zscale=in_range=limited:range=full

Complete Command Example

To tie these configurations together, the following command rescales an input video to 1080p, applies a sharp Lanczos filter, uses ordered dithering, and ensures the output is set to limited (TV) range:

ffmpeg -i input.mp4 -vf "zscale=width=1920:height=1080:filter=lanczos:dither=ordered:range=limited" -c:v libx264 -crf 18 output.mp4