Convert MP4 to GIF with ffmpeg using different dither algorithms

Below are practical ffmpeg commands and explanations for converting an MP4 to an animated GIF while trying different dither algorithms. GIF is limited (palette of 256 colors), so good results depend on palette creation and dithering. The general recommended workflow is: 1) generate an optimized 256-color palette from the source, 2) apply that palette when converting to GIF and select a dither algorithm.

Basics

  • Palette generation step uses the filter palettegen.
  • Conversion step uses paletteuse with a chosen dither option.
  • For better color capture, run palettegen on a scaled/filtered copy (or at full resolution if you want the full size).
  • If you want a smaller file / fewer frames, you may scale and/or reduce frame rate (fps).

Common options and their meanings

  • palettegen: use max_colors=256 (default) and optionally reserve_transparent=1 if transparency matters.
  • paletteuse dither options:
    • bayer: ordered (pattern) dithering (values: 0–5 — higher = bigger matrix)
    • floyd_steinberg: standard error-diffusion dithering
    • sierra2_4a / sierra2 / sierra3: Sierra-family error diffusion variants
    • none: no dithering
  • paletteuse also supports "ordered" and "error_diffusion" in some builds; the shorthand above is most common.

Example commands Change input.mp4 and output.gif and adjust scale and fps as needed.

  1. Default good-quality workflow (palette gen + floyd_steinberg) ffmpeg -i input.mp4 -vf "fps=15,scale=720:-1:flags=lanczos,palettegen" -y palette.png ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=15,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse=dither=floyd_steinberg" -y output_floyd.gif

  2. Using ordered Bayer dither (smaller-looking grainy pattern) ffmpeg -i input.mp4 -vf "fps=15,scale=720:-1:flags=lanczos,palettegen" -y palette.png ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=15,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse=dither=bayer:bayer_scale=5" -y output_bayer.gif

Notes:

  • bayer_scale is an integer controlling strength (1..5 commonly). Higher values produce stronger ordered dither.
  • Some ffmpeg builds accept dither=bayer and an extra parameter bayer_scale; others accept dither=bayerX where X is matrix size—if a command fails, try removing/adjusting bayer_scale.
  1. Using Sierra family (softer error diffusion) ffmpeg -i input.mp4 -vf "fps=15,scale=720:-1:flags=lanczos,palettegen" -y palette.png ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=15,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse=dither=sierra2_4a" -y output_sierra.gif

  2. No dithering (fast, can look posterized) ffmpeg -i input.mp4 -vf "fps=15,scale=720:-1:flags=lanczos,palettegen" -y palette.png ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=15,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse=dither=none" -y output_none.gif

  3. Single-line (one-liner using stream copy of palette step) ffmpeg -i input.mp4 -filter_complex
    "[0:v]fps=15,scale=720:-1:flags=lanczos,palettegen=stats_mode=diff[p];[0:v]fps=15,scale=720:-1:flags=lanczos[x];[x][p]paletteuse=dither=floyd_steinberg"
    -y output_floyd.gif

Tweaks and tips

  • fps=10..20 is common for GIFs; lower fps reduces size. Use fps=... in both palettegen and paletteuse steps or in the combined filter_complex as shown.
  • scale=720:-1 keeps aspect ratio. For small GIFs, scale to 480 or 360 width.
  • Use flags=lanczos for better resizing quality.
  • Use palettegen=stats_mode=diff for a palette that better matches motion/temporal changes.
  • For sources with transparency (PNG-like), add palettegen=reserve_transparent=1 and paletteuse has additional transparency handling.
  • If you get fewer than expected colors or odd artifacts, try increasing visual quality (larger scale, different palettegen stats_mode, different dither) or use GIF alternatives (APNG, WebP) for better color if supported.

Compatibility note Different ffmpeg versions may accept slightly different dither names/parameters. If a dither name is rejected, run ffmpeg -filters to see paletteuse options or check the build’s documentation.

If you want, tell me:

  • an example file duration, resolution and desired output width/fps, and I can provide a tuned command and expected file-size tradeoffs.

Have your own question?

Ask the AI now

Free · no account needed · answer in seconds