Convert a Video Segment to a GIF with ffmpeg
The two-pass palettegen/paletteuse filter chain produces GIFs with accurate colors instead of the usual banding.
Use -vf with fps, scale, and the split/palettegen/paletteuse chain to convert a trimmed segment to a high-quality GIF.
01Command
Command
$ ffmpeg -i input.mp4 -ss 5 -t 3 -vf "fps=12,scale=480:-1:flags=lanczos,split[a][b];[a]palettegen[p];[b][p]paletteuse" output.gif02What it does
GIF supports only 256 colors, so ffmpeg's default conversion produces ugly banding; palettegen builds an optimal palette from your frames and paletteuse applies it, which is why the filter uses split to feed the frames through both. fps=12 and scale=480 keep the file small — GIFs balloon fast at 30fps and full resolution. Use -ss and -t to pick the segment, or run palettegen in two separate passes on the exact frames for maximum accuracy.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- FFmpeg Wiki: SeekingEvidence: Explains input seeking (-ss) and duration limiting (-t) used to select the segment that becomes the GIF.
- FFmpeg DocumentationEvidence: Documents the -vf filterchain, fps and scale filters, and the palettegen/paletteuse filters for GIF palette optimization.
Last verified: 2026-09-17 · Category: Media