10/10/2025

Convert MP4 to a high-quality GIF with FFmpeg. Includes palette-based commands, clip extraction, FPS and width settings, and common file size fixes.

How to Convert MP4 to GIF with FFmpeg

The best FFmpeg GIF command uses a generated color palette. GIF files are limited to 256 colors, so a palette helps prevent banding, muddy gradients, and rough edges.

If you prefer a form-based command builder, use the MP4 to GIF tool. If you want the command directly, start with the palette method below.

Best Quality Command

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

This one-line command:

  • Sets the GIF to 12 frames per second.
  • Scales the width to 480 pixels while preserving aspect ratio.
  • Uses Lanczos scaling for sharper resizing.
  • Generates and applies a palette in the same filter graph.

Extract a Short Clip as GIF

Most GIFs should be short. Use -ss for the start time and -t for the duration:

ffmpeg -ss 00:00:05 -t 00:00:03 -i input.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif

This creates a 3-second GIF starting at 5 seconds.

Two-Step Palette Method

If you want the clearest workflow, generate the palette first:

ffmpeg -i input.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,palettegen" palette.png

Then use it:

ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=12,scale=480:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif

The one-line command and the two-step method can both produce good results. The two-step method is easier to debug.

What the Options Mean

Option Meaning
fps=12 Sets the GIF frame rate. Higher FPS is smoother but larger.
scale=480:-1 Sets width to 480 pixels and keeps the original aspect ratio.
flags=lanczos Uses a sharp resize algorithm.
split[s0][s1] Creates one stream for palette generation and one for final output.
palettegen Builds a 256-color palette from the source video.
paletteuse Applies the palette to the GIF.

Choosing Width and FPS

Goal Width FPS
Small file 320 8-10
Balanced quality 480 10-12
Smoother preview 640 12-15

GIF is not efficient for large, long, or high-frame-rate video. If the output is too big, reduce duration first, then width, then FPS.

Faster but Lower Quality Command

For a quick preview, you can skip the palette:

ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1" output.gif

This is simpler, but colors often look worse than the palette-based command.

Common Problems

The GIF file is too large.
Shorten the duration with -t, reduce width from 640 to 480 or 320, and lower FPS.

The GIF looks blurry.
Increase the width or use flags=lanczos. Avoid upscaling small source videos.

The colors look bad.
Use the palette method instead of direct conversion.

FFmpeg says the output dimensions are invalid.
Use scale=480:-1 for GIF. If you are encoding video formats instead of GIF, -2 is often safer for encoder compatibility.

Related FFmpeg Pages

Related tool

MP4 to GIF with FFmpeg

Create high-quality GIF commands from MP4 using palette generation.

Open the command generator