CommandFFmpeg

Convert a video to GIF

Turns any video into a high-quality animated GIF in one ffmpeg pass, generating a custom color palette instead of the default dither.

Last updated

Commandffmpeg
ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

How it works

GIF is limited to 256 colors total, and ffmpeg's default conversion uses a generic palette that causes visible banding and dithering on anything but flat cartoon colors. The split filter duplicates the scaled video stream into two copies: one feeds palettegen, which builds an optimal 256-color palette from the ACTUAL frames of this clip, and the other feeds paletteuse, which re-encodes the video against that palette — all in a single ffmpeg invocation instead of writing a palette.png file and running ffmpeg twice.

fps=10 drops the frame rate before anything else runs, since GIFs rarely need film frame rates and every extra frame inflates file size; scale=480:-1:flags=lanczos resizes to a manageable width (auto height, keeping aspect) using the Lanczos algorithm, which holds up much better than the default bilinear scaler when the source shrinks a lot.

Watch out for

  • Even with an optimized palette, GIF is still capped at 256 colors per frame — smooth gradients and photographic content will still show some banding compared to the source video; that's a format limit, not a settings problem.
  • Long or high-resolution source clips produce huge GIFs fast. Trim the input first with -ss/-t, or drop fps further (e.g. fps=8) before reaching for a different container like WebP or a short muted MP4.
  • -1 for the height leaves ffmpeg to compute an even number automatically; hardcoding both width and height risks an odd value that some filters reject.

Related in Commands