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. CRF is ffmpeg's quality setting for H.264: lower means better quality and a bigger file.
The GIF was 515.5 KB. The default MP4 was 25.2 KB, about 95% smaller. A real-world GIF shrank less but still a lot: the rotating Earth animation on Wikimedia Commons (400×400, 44 frames, CC BY-SA 3.0) went from 1,001.7 KB to 136.7 KB, 86% smaller. Google's web.dev guide on replacing GIFs with video reports a similar jump, 3.7 MB of GIF to a 551 KB MP4, and Lighthouse flags large GIFs with the audit "Use video formats for animated content."
Upload rules are the other reason. YouTube's list of supported file formats includes MP4, MOV, WebM and others, but not GIF.
Option 1: ffmpeg (Windows, Mac, Linux)
ffmpeg is free and gives you full control. Get it from ffmpeg.org/download, which links Windows builds, or on a Mac with Homebrew (brew install ffmpeg, see the formula page).
- Open a terminal in the folder with your GIF.
- Run the command below, then check the MP4 in a browser or on your phone before you share it.
ffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p \
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4
What each part does:
-
-movflags +faststartmoves the MP4's metadata (its index of all the frames) to the start of the file "for better playback" (ffmpeg formats docs), so a browser can start playing before the whole file has downloaded. -
-pix_fmt yuv420psets the standard color format. MDN notes that most H.264 profiles use 4:2:0 chroma subsampling, which is what this flag gives you. - The
scalefilter rounds width and height down to even numbers.
Add -crf 28 for a smaller file or -crf 18 for a sharper one. In our test, leaving -crf out produced a byte-identical file to -crf 23.
The two ffmpeg gotchas
Gotcha 1: the default color format. We ran plain ffmpeg -i sample.gif naive.mp4. ffmpeg picked yuv444p and the "High 4:4:4 Predictive" H.264 profile. MDN notes that most H.264 profiles use 4:2:0, with 4:4:4 only in advanced profiles. Google's own GIF conversion command in the web.dev guide sets -pix_fmt yuv420p explicitly, and so should you.
Gotcha 2: odd dimensions. With yuv420p, the libx264 encoder needs even width and height. Our 481×271 test GIF failed with:
[libx264] width not divisible by 2 (481x271)
Conversion failed!
The scale=trunc(iw/2)*2:trunc(ih/2)*2 filter fixed it, producing a 480×270 MP4. The web.dev guide uses a crop filter with the same math, which cuts off a single pixel row or column instead of resizing.
Option 2: Clipchamp (Windows or any browser)
Microsoft's Clipchamp video editor has a free tier, and Microsoft says its drag-and-drop import works on Windows, Mac, and Linux.
- Import the GIF in the media tab and drag it to the timeline (Microsoft's GIF guide).
- Click Export and pick 480p, 720p or 1080p.
Exports are MP4 at 30 fps, and 480p to 1080p are free (Microsoft support). It's a good pick if you also want to trim the clip or add text. The trade-off is timing: every frame has to land on a 30 fps grid, so a GIF with uneven delays may play slightly differently.
Option 3: In the browser
Our free GIF to MP4 converter runs entirely in your browser using its built-in video encoder (WebCodecs), so the GIF is never uploaded. It keeps each frame's own delay, lets you pick a background color for transparent areas, can repeat a short loop until the video reaches 3, 10 or 15 seconds, and converts batches to a ZIP. Output is H.264 MP4 with even dimensions and fast-start. Limits: 100 MB, 3,000 frames and 16 megapixels per GIF, and it needs a browser with the H.264 video encoder: Chrome, Edge, Safari 16.4+ or desktop Firefox 130+ (MDN VideoEncoder compatibility). Firefox on Android doesn't have it yet.
Two well-known alternatives:
- Ezgif takes files up to 200 MB. Uploads are deleted after an hour, and it also offers a local-processing mode.
- CloudConvert converts on its own servers. The free plan gives 10 conversion credits a day, with a 1 GB file limit.
Limits to know
-
No transparency.
yuv420phas no alpha channel (ffmpeg -pix_fmtslists it with three components), so transparent pixels become a solid color. -
No built-in loop. A GIF can loop forever on its own. An MP4 loops only if the player or site does it. On your own site, use
<video autoplay loop muted playsinline>, the pattern web.dev recommends. MDN documents theloopattribute. - No sound. GIFs have no audio track, so the MP4 is silent.
- Slight quality loss. H.264 is lossy. At the default CRF 23 we couldn't see a difference at normal size (SSIM 0.997 against the GIF, where 1.0 is identical). At CRF 32, color bled around the hard edges, as the zoom below shows.
The same frame from the GIF and two MP4s, with a 4× zoom on the sun's edge.
FAQ
Will the MP4 always be smaller than the GIF?
Not always. A tiny 64×64 GIF with three frames went from 428 bytes to 1,739 bytes as an MP4. For anything bigger than an icon, expect real savings: our two test files came out 86% and 95% smaller.
Why won't my converted MP4 play on my phone or in a browser?
Check the pixel format first. If ffmpeg wrote yuv444p, re-run the conversion with -pix_fmt yuv420p.
Why does ffmpeg say "width not divisible by 2"?
Your GIF has an odd width or height. Add the scale (or crop) filter shown above.
Can I convert GIF to MP4 on an iPhone?
Yes, in Safari 16.4 or later with a converter that encodes in the browser.
Does converting keep the GIF's speed?
ffmpeg and our converter keep each frame's delay. We tested ffmpeg with a GIF whose last frame holds for one second, and the MP4 held it too. Editors that export at a fixed 30 fps, like Clipchamp, resample it, which can make the timing slightly uneven.
Cuelark Team


Top comments (0)