Menu

1 / 2

How to Convert a GIF to MP4 (ffmpeg, Clipchamp, or in Your Browser)

DEV Community: webdev·Cuelark·13 days ago
#m8f1DfJt
#devtowebdev#devto#dev#ffmpeg#browser
Long article (1193 words) — no AI summary yet.
Reading 0:00
15s threshold

To convert a GIF to MP4, run it through a video encoder: ffmpeg on the command line, a free editor like Clipchamp, or a browser-based converter. With ffmpeg, the one command most people need is ffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4 , and the MP4 is usually a fraction of the GIF's size.

Below is each method, what we measured on test files, and where things break.

Why MP4 is smaller, and why sites ask for it

A GIF stores every frame as 8-bit indexed color, with at most 256 colors per palette, compressed losslessly with LZW ( MDN image format guide ). H.264 video is lossy, and video compression works by comparing frames and storing only what changed from the previous one ( MDN video codec guide ). An animation where most of the picture stays still is close to the best case for video.

Here's what we measured. We made a 4-second, 480×270 animated GIF with 80 frames and converted it with ffmpeg 7.1:

Sizes measured on our test file.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.