D E A D L I G H T

Converting MP4 to a High-Quality Transparent GIF with FFmpeg

By thatch | 11/13/2025
2

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.png

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

Higher 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.gif

Troubleshooting


Example Result

You’ll get a large, smooth, and (if your source had alpha) transparent GIF:

video.mp4 → output.gif

Perfect for blog posts, UI demos, and animated screenshots.

Previous: ¯\_(ツ)_/¯ Next: Building an Internet Gateway Over LoRa Mesh

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

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