If your MP4 contains transparency (for example, from a screen capture or animation exported with an alpha channel), you can preserve that transparency when converting it to a GIF using FFmpeg.
Step 1 — Generate a Palette
FFmpeg needs a color palette to make a high-quality GIF.
This first command creates that palette:
ffmpeg -y -i video.mp4 \
-vf "fps=10,scale=960:-1:flags=lanczos,palettegen" palette.pngfps=10→ Sets the frame rate for smoother playback (adjust as needed)scale=960:-1→ Larger resolution (height auto-adjusts to maintain aspect)flags=lanczos→ High-quality resampling filterpalettegen→ Creates the optimal 256-color palette for your GIF
Step 2 — Generate the Transparent GIF
Now combine your video and palette using a complex filter, which supports multiple inputs and preserves transparency.
ffmpeg -i video.mp4 -i palette.png \
-filter_complex "fps=10,scale=960:-1:flags=lanczos,paletteuse=dither=bayer" \
output.gifoutput.gif→ Your final transparent GIF
Note: GIFs can only have one transparent color, not full alpha gradients like PNGs.
FFmpeg will approximate transparency by mapping it to the nearest palette color.
Optional Improvements
Loop Forever
Add -loop 0 to make your GIF repeat endlessly:
ffmpeg -i video.mp4 -i palette.png \
-filter_complex "fps=10,scale=960:-1:flags=lanczos,split[s0][s1];[s0][1:v]paletteuse=dither=bayer" \
-loop 0 output.gifHigher Frame Rate
For smoother animation:
ffmpeg -i assets/proxy_make_to_shut_cli_ui.mp4 -i palette.png \
-filter_complex "fps=15,scale=960:-1:flags=lanczos[x];[x][1:v]paletteuse=dither=floyd_steinberg" \
-loop 0 output.gifTroubleshooting
- If you get “Simple filtergraph was expected to have exactly 1 input and 1 output”,
you forgot to use-filter_complexinstead of-vf. - If you see “Unable to choose an output format”,
make sure your output filename has a proper extension (e.g.output.gif).
Example Result
You’ll get a large, smooth, and (if your source had alpha) transparent GIF:
video.mp4 → output.gifPerfect for blog posts, UI demos, and animated screenshots.
Comments
ffmpeg -i vid.mp4 -filter_complex "[0:v]fps=10,scale=960:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" output.gif
By sandman | 3/8/2026
ffmpeg -i vid.mp4 -filter_complex "[0:v]fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" output.gif
By admin | 6/4/2026