FFmpeg paletteuse Dither Options Guide
This guide explains how to configure dithering settings using
FFmpeg's paletteuse filter to improve the visual quality
and file size of limited-color outputs like animated GIFs. You will
learn about the available dithering algorithms, how to adjust Bayer
scale settings, and how to apply these options in standard FFmpeg
conversion commands.
The dither Parameter
The dither parameter in the paletteuse
filter controls the algorithm used to diffuse color quantization errors
across neighboring pixels. You set it using the syntax
paletteuse=dither=<algorithm>.
The supported dithering algorithms are:
bayer: Ordered dithering using a cross-hatch matrix pattern. It produces predictable patterns and avoids pixel shimmering in animated content.floyd_steinberg: Classic error diffusion. It spreads quantization errors to neighbor pixels, producing smooth gradients, though it may introduce visual noise across frames in animations.sierra2: A two-line error diffusion algorithm, slightly faster and less noisy than Floyd-Steinberg.sierra2_4a: A simplified version ofsierra2. It often yields the best balance between speed, gradient smoothness, and reduced temporal noise in GIFs.heckbert: An error-diffusion algorithm based on Paul Heckbert's paper.none: Disables dithering entirely. This creates solid bands of color (posterization) but significantly reduces file size and eliminates cross-frame noise.
Configuring Bayer Scale
(bayer_scale)
When using dither=bayer, you can control the intensity
of the pattern using the bayer_scale option. It accepts
integer values from 0 to 5 (default is
2):
- Lower values (0–1): Reduce the visibility of the cross-hatch pattern, resulting in a cleaner look that behaves closer to no dithering.
- Higher values (3–5): Increase the spread and visibility of the pattern, allowing for smoother perceived color transitions at the cost of obvious grid artifacts.
Example syntax:
paletteuse=dither=bayer:bayer_scale=1Frame Differences
and Dither Noise (diff_mode)
Error diffusion algorithms (floyd_steinberg,
sierra2, etc.) can cause static backgrounds to flicker
between frames. You can mitigate this by enabling
diff_mode=rectangle. This restricts the palette application
and dithering only to the bounding box of pixels that changed from the
previous frame:
paletteuse=dither=sierra2_4a:diff_mode=rectanglePractical FFmpeg Examples
A complete palette-based conversion uses both palettegen
and paletteuse. Below are practical implementations showing
different dithering configurations.
1. High-Quality Animated GIF (Sierra2_4a with Rectangle Mode)
ffmpeg -i input.mp4 -filter_complex "[0:v] fps=15,scale=480:-1:flags=lanczos,split [a][b]; [a] palettegen [p]; [b][p] paletteuse=dither=sierra2_4a:diff_mode=rectangle" output.gif2. Patterned, Flicker-Free GIF (Bayer Dither)
ffmpeg -i input.mp4 -filter_complex "[0:v] fps=15,scale=480:-1:flags=lanczos,split [a][b]; [a] palettegen [p]; [b][p] paletteuse=dither=bayer:bayer_scale=2" output.gif3. Minimal File Size (No Dithering)
ffmpeg -i input.mp4 -filter_complex "[0:v] fps=15,scale=480:-1:flags=lanczos,split [a][b]; [a] palettegen [p]; [b][p] paletteuse=dither=none" output.gif