GIFs are limited to 256 colors. palettegen builds the best 256-color palette for these exact frames and paletteuse maps the frames onto it, which avoids the banding of ffmpeg's default palette. At 0.5 fps this makes a slideshow-style GIF: one frame every 2 seconds of a 20 s span.

The command

ffmpeg -ss 5 -t 20 -i input.mp4 \
  -filter_complex "fps=0.5,split[a][b];[a]palettegen[p];[b][p]paletteuse" \
  output.gif

What each part does

-ss 5 -t 20            use 0:05–0:25 of the source
fps=0.5                one frame every 2 seconds (raise for motion)
split[a][b]            send the frames to two places
[a]palettegen[p]       build the palette from one copy
[b][p]paletteuse       render the other copy using that palette

When to use it

Use this when you want a GIF from part of a video and care about colour quality. It builds a palette from the exact frames it renders, so gradients and skin tones band far less than with ffmpeg's default palette. The header explains each flag. As written, it makes a slideshow-style GIF of about 10 frames from 0:05 to 0:25 of the source.

For a single still, use extract-frame-jpg.sh instead. GIF also carries no audio.

To adapt it, change the -ss and -t values to pick a different span. Raise fps=0.5 for real motion, but expect a larger file. The GIF keeps the source's frame size, so a large source gives a large file.

If the output looks wrong:

  • Banding or off colours: make sure both palettegen and paletteuse are still in the filtergraph. Also remember that every frame shares one 256-colour palette, so a span with very different scenes will look worse than a single scene.
  • Too few frames or a short GIF: check that -ss plus -t fits inside the source's length.
  • Choppy motion: raise the fps.

Notes

Source
ffmpeg-utilities/short-gif.sh (also vector-gif.sh, vector-gif 2.sh)
Changed
the original made the palette from the whole clip in a separate pass (palette.png), then rendered 0:05–0:25. Doing both in one filtergraph builds the palette from the frames actually used and leaves no temporary file behind.