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.

WindowsvideoffmpeggifLow risk
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.gif

02What 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

RiskLow risk
Requirementsffmpeg must be installed (winget install Gyan.FFmpeg)

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • FFmpeg Wiki: Seeking
    FFmpeg · technical · 2026-09-17
    Evidence: Explains input seeking (-ss) and duration limiting (-t) used to select the segment that becomes the GIF.
  • FFmpeg Documentation
    FFmpeg · vendor-doc · 2026-09-17
    Evidence: Documents the -vf filterchain, fps and scale filters, and the palettegen/paletteuse filters for GIF palette optimization.

Last verified: 2026-09-17 · Category: Media