Convert video to GIF with optimized palette
gif & images
// what it does
The quality-focused two-pass GIF workflow. The first command runs palettegen over the (scaled, lanczos-filtered) frames to compute an optimal 256-color palette.png tuned to this specific video. The second command feeds the scaled video and that palette as a second input into paletteuse, which maps each frame to the custom palette with dithering. This yields noticeably better color and often a smaller file than the single-pass approach.
// shell
$ ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,palettegen" palette.png$ ffmpeg -i input.mp4 -i palette.png -lavfi "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif// gotcha
Keep fps and scale identical in both passes — the palette is optimized for those exact frames, so mismatched filters map frames against a palette built for different pixels and colors degrade. The palette.png is a tiny 16x16 swatch (256 colors) — that's expected, not a bug.