How to Convert GIF to MP4 (With Loop): Free Methods for Every Platform

GIFs are huge. MP4s are tiny. Learn how to convert animated GIFs to looping MP4 videos and slash file sizes by up to 95%.

Why Convert GIF to MP4?

GIFs are everywhere on the internet, but they come with a massive problem: file size. A typical 5MB GIF animation can be converted to a 500KB MP4 video with identical visual quality. That's a 90% reduction in file size.

The reason is simple. GIF is an ancient image format from 1987, originally designed for simple graphics with limited colors. When you use it for video-like animations, it becomes incredibly inefficient. Every frame is stored as a complete image, with no compression between frames.

MP4 uses modern video codecs like H.264 or H.265 that only store the differences between frames. This makes MP4 files dramatically smaller while maintaining the same quality. Plus, MP4 supports millions of colors, while GIF is limited to just 256 colors per frame.

The benefits of converting GIF to MP4 include:

  • Massive file size reduction (typically 80-95% smaller)
  • Better color quality (no color banding or dithering)
  • Faster loading times on websites and social media
  • Lower bandwidth costs for hosting and sharing
  • Smoother playback on most devices
  • Better compatibility with modern video players

The only challenge is making the MP4 loop seamlessly like a GIF. But that's exactly what we'll cover in this guide.

Understanding MP4 Looping

When you convert a GIF to MP4, the biggest concern is preserving the infinite loop behavior. GIFs naturally loop forever when displayed in browsers, but MP4 videos typically play once and stop.

There are two ways to make an MP4 loop like a GIF:

  1. Encode the loop into the video file itself using FFmpeg's -stream_loop or by duplicating frames during encoding
  2. Use HTML5 video attributes to enable looping in the browser (the loop attribute)

For web use, the second method is far more efficient. You convert the GIF to MP4 once, then use simple HTML to make it loop. For social media or video players, you might need the first method.

The key is also adding -movflags +faststart to your MP4, which optimizes the file structure for streaming. This moves the metadata to the beginning of the file so the video can start playing before it fully downloads.

Method 1: FFmpeg Command Line (Most Control)

FFmpeg is the most powerful tool for converting GIF to MP4. It's free, open-source, and works on Mac, Windows, and Linux. The learning curve is steep, but once you know the commands, you have complete control.

Installing FFmpeg

On Mac, use Homebrew:

brew install ffmpeg

On Windows, download from the official FFmpeg website and add it to your system PATH.

On Linux:

sudo apt-get install ffmpeg

Basic GIF to MP4 Conversion

The simplest conversion command:

ffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p output.mp4

This creates a standard MP4 that you can loop using HTML5 video attributes.

Let's break down the flags:

  • -i input.gif - Your source GIF file
  • -movflags +faststart - Optimizes for web streaming
  • -pix_fmt yuv420p - Ensures compatibility with most players
  • output.mp4 - Your converted video file

High-Quality Conversion with Custom Settings

For better quality control:

ffmpeg -i input.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -crf 23 -preset medium -movflags +faststart -pix_fmt yuv420p output.mp4

Additional options explained:

  • -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" - Ensures even dimensions (required for H.264)
  • -c:v libx264 - Uses H.264 codec for maximum compatibility
  • -crf 23 - Constant Rate Factor (18-28, lower = better quality)
  • -preset medium - Encoding speed vs compression (slow = smaller files)

Creating a Self-Looping MP4

If you need the loop behavior embedded in the file:

ffmpeg -stream_loop 10 -i input.gif -movflags +faststart -pix_fmt yuv420p output.mp4

The -stream_loop 10 repeats the input 10 times before encoding. For most purposes, this is unnecessary. It's better to keep the file small and use HTML/CSS for looping.

Batch Converting Multiple GIFs

To convert all GIFs in a folder:

for i in *.gif; do
  ffmpeg -i "$i" -movflags +faststart -pix_fmt yuv420p "${i%.gif}.mp4"
done

This bash loop processes every GIF file and creates an MP4 with the same filename.

Method 2: Compresto for Mac (Easiest)

If you're on a Mac and want a dead-simple solution, Compresto handles GIF-to-MP4 conversion with zero configuration.

Just drag your GIF file into Compresto, select MP4 as the output format, and click compress. The app automatically applies optimal settings for web use, including the fast-start flag for streaming.

Compresto is particularly useful when you're working with large batches of GIFs or need consistent quality across multiple files. The hardware acceleration makes conversions much faster than FFmpeg on Apple Silicon Macs.

It's also helpful if you're not comfortable with command-line tools. The visual interface shows file size comparisons in real-time, so you can see exactly how much space you're saving.

Download Compresto at compresto.app for a free trial.

Method 3: Online GIF to MP4 Converters

Several free online tools convert GIF to MP4 without installing software. These are convenient for quick one-off conversions, but be cautious about uploading sensitive or private content to third-party servers.

CloudConvert

CloudConvert supports GIF to MP4 conversion with quality settings. You can adjust the codec, bitrate, and resolution before converting. The free tier allows 25 conversions per day.

  1. Visit cloudconvert.com
  2. Upload your GIF file
  3. Select MP4 as the output format
  4. Click "Convert"
  5. Download the result

EZGIF.com

EZGIF offers a dedicated GIF-to-MP4 converter with no file size limits on free accounts. It's particularly good for quick tests.

  1. Go to ezgif.com/gif-to-mp4
  2. Upload your GIF (or paste a URL)
  3. Click "Convert to MP4"
  4. Download the converted file

The quality is decent, but you have limited control over encoding parameters.

Convertio

Convertio supports over 300 formats and offers browser-based conversion. The free tier is limited to 100MB file sizes.

The downside of online converters is upload/download time, especially for large files. You're also dependent on server availability and internet connection quality.

Method 4: VLC Media Player (Cross-Platform)

VLC isn't just a player—it's also a capable converter. It's available for Mac, Windows, and Linux.

  1. Open VLC Media Player
  2. Go to File > Convert / Stream (or Media > Convert / Save on Windows)
  3. Add your GIF file
  4. Click Convert / Save
  5. Select Video - H.264 + MP3 (MP4) as the profile
  6. Click Customize to access advanced settings
  7. In the Encapsulation tab, check MP4/MOV
  8. In the Video codec tab, select H.264 and set bitrate
  9. Choose a destination filename
  10. Click Start

VLC's interface is a bit clunky for conversion, but it works well for occasional use.

Method 5: Windows Built-in Tools

Windows doesn't have a native GIF-to-MP4 converter, but you can use PowerShell with FFmpeg or install free tools like HandBrake.

HandBrake (Free and Open Source)

HandBrake is primarily designed for video conversion, but it handles GIFs reasonably well.

  1. Download HandBrake from handbrake.fr
  2. Open the app and load your GIF
  3. Select the Fast 1080p30 preset (or adjust manually)
  4. Set the output format to MP4
  5. Click Start Encode

HandBrake applies sensible defaults automatically, including the fast-start flag.

Using MP4 as a GIF Replacement on Websites

The real power of converting GIF to MP4 shows up when you replace GIF tags with HTML5 video on your website.

Standard GIF Embed

Old way:

<img src="animation.gif" alt="Animated demo">

MP4 Replacement with Looping

New way:

<video autoplay loop muted playsinline>
  <source src="animation.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

The key attributes:

  • autoplay - Starts playing automatically (like a GIF)
  • loop - Repeats infinitely (like a GIF)
  • muted - Required for autoplay to work in most browsers
  • playsinline - Prevents fullscreen on mobile devices

Adding a GIF Fallback

For maximum compatibility:

<video autoplay loop muted playsinline>
  <source src="animation.mp4" type="video/mp4">
  <img src="animation.gif" alt="Animated demo">
</video>

Older browsers that don't support video will display the GIF instead.

Styling Video to Look Like an Image

To make the video behave exactly like an img tag:

video {
  width: 100%;
  height: auto;
  display: block;
}

This ensures the video is responsive and doesn't create layout shifts.

Social Media Platform Compatibility

Different social media platforms have varying support for MP4 uploads and looping.

Twitter/X

Twitter automatically converts uploaded GIFs to MP4 and displays them with looping. If you upload an MP4 directly, it will loop if it's under 15 seconds and has no audio track.

Facebook and Instagram

Both platforms support MP4 uploads and will loop videos in the feed. However, they apply their own compression, so quality may degrade. For best results, use these settings:

  • Resolution: 1080x1080 (square) or 1920x1080 (landscape)
  • Frame rate: 30fps
  • Bitrate: 5-8 Mbps
  • Codec: H.264

Reddit

Reddit natively supports MP4 uploads and displays them with autoplay and loop. GIF links also work but load slower.

Discord

Discord automatically converts GIF uploads to MP4 on their servers to save bandwidth. You can upload MP4 files directly, and they'll display with looping enabled.

Optimizing File Size Further

Even after converting to MP4, you can reduce file size further with these techniques.

Reduce Resolution

If your GIF is 1920x1080 but only displays at 600px wide, scale it down:

ffmpeg -i input.gif -vf "scale=600:-1" -movflags +faststart -pix_fmt yuv420p output.mp4

The -1 maintains aspect ratio automatically.

Lower Frame Rate

Many GIFs have unnecessary frame rates. Reducing from 60fps to 30fps or even 24fps can halve the file size:

ffmpeg -i input.gif -r 24 -movflags +faststart -pix_fmt yuv420p output.mp4

Adjust CRF Value

The Constant Rate Factor controls quality vs file size. Experiment with values between 20-28:

ffmpeg -i input.gif -crf 26 -movflags +faststart -pix_fmt yuv420p output.mp4

Lower CRF = higher quality and larger file. Higher CRF = lower quality and smaller file.

Two-Pass Encoding

For the absolute best quality-to-size ratio, use two-pass encoding:

ffmpeg -i input.gif -c:v libx264 -b:v 1000k -pass 1 -f mp4 /dev/null
ffmpeg -i input.gif -c:v libx264 -b:v 1000k -pass 2 -movflags +faststart output.mp4

This takes longer but produces more efficient files.

Troubleshooting Common Issues

MP4 Won't Loop in Browser

If your MP4 doesn't loop, check these:

  1. Ensure you're using the loop attribute in the video tag
  2. Some browsers require muted for autoplay to work
  3. Add playsinline for iOS Safari compatibility

Poor Quality After Conversion

If your MP4 looks worse than the original GIF:

  1. Lower the CRF value (try 18-20 for high quality)
  2. Use -preset slow for better compression
  3. Match the output resolution to the input resolution
  4. Check if the source GIF was already low quality

File Size Barely Reduced

If your MP4 isn't much smaller:

  1. The GIF might already be well-optimized
  2. Try increasing the CRF value (24-28)
  3. Reduce the frame rate with -r flag
  4. Scale down the resolution if possible

Video Looks Pixelated or Blocky

This usually means the bitrate is too low:

  1. Use a lower CRF value (lower = higher quality)
  2. Add -b:v 2M to set a minimum bitrate of 2 Mbps
  3. Use -preset slow for better encoding efficiency

Audio Track Issues

GIFs don't have audio, but if your player shows an audio track:

ffmpeg -i input.gif -an -movflags +faststart -pix_fmt yuv420p output.mp4

The -an flag removes any audio streams.

Converting MP4 Back to GIF

Sometimes you need to go the other direction. Maybe you have a video clip and need a GIF for compatibility reasons.

Check out our guide on how to convert video to GIF on Mac for detailed instructions.

For best results, keep your GIF short (under 5 seconds), use a reasonable frame rate (15-24fps), and optimize the color palette for the smallest file size.

Compressing GIFs Before Converting

If you're stuck with GIF format and can't convert to MP4, you can still reduce file size significantly.

Our guide on how to compress GIF without losing quality covers techniques like:

  • Reducing frame count by removing duplicates
  • Optimizing the color palette
  • Cropping unnecessary edges
  • Lowering the resolution

However, converting to MP4 will almost always produce smaller files than even the most optimized GIF.

Which Method Should You Use?

Here's a quick decision tree:

Choose FFmpeg if:

  • You need precise control over encoding settings
  • You're converting large batches of files
  • You're comfortable with command-line tools
  • You want the smallest possible file sizes

Choose Compresto if:

  • You're on a Mac and want a simple visual interface
  • You need fast conversions with Apple Silicon acceleration
  • You don't want to memorize FFmpeg commands
  • You value consistency across multiple conversions

Choose online converters if:

  • You need a quick one-off conversion
  • You can't install software on your device
  • File privacy isn't a concern
  • The files are small enough for upload

Choose VLC or HandBrake if:

  • You already have them installed
  • You need cross-platform compatibility
  • You occasionally convert files (not batch processing)

For most web developers and content creators, the combination of FFmpeg for batch processing and Compresto for quick conversions works best.

Final Thoughts

Converting GIF to MP4 is one of the easiest ways to dramatically improve website performance. A single 5MB GIF converted to a 500KB MP4 loads 10 times faster and uses 10 times less bandwidth.

The best part is that modern browsers make MP4 look and behave exactly like a GIF with the right HTML attributes. Users won't notice any difference except that your site loads faster.

Start with the simplest method that works for your workflow. FFmpeg offers the most control, but tools like Compresto make the process effortless if you're on a Mac. Even online converters work fine for occasional use.

The key is making this part of your standard workflow. Every time you're about to upload a GIF, ask yourself: should this be an MP4 instead? In most cases, the answer is yes.

For more compression tips and tools, check out Compresto for Mac users who want a simple, powerful solution for all their media compression needs.

Ready to compress your files? Join thousands of creators using Compresto ⚡