Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What command would I use to convert an mp4 or mv4 video file to an animated gif, and vice versa. That is, convert a animated gif to a mp4 or mv4.

share|improve this question

migrated from stackoverflow.com Jun 12 '12 at 21:11

This question came from our site for professional and enthusiast programmers.

In my case, using ffmpeg directly did the trick and provided the best result:

$ ffmpeg -f gif -i infile.gif outfile.mp4
share|improve this answer
produced a blank (corrupted) video on os x – Pykler Jul 14 at 23:53
@Pykler you should probably increase verbosity and/or check the log file to understand what's happening. – BenC Jul 17 at 19:02

Another way to convert GIF animation to video:

ffmpeg -i your_gif.gif -c:v libvpx -crf 12 -b:v 500K output.mp4

-crf values can go from 4 to 63. Lower values mean better quality. -b:v is the maximum allowed bitrate. Higher means better quality.

share|improve this answer
I have posted a question for the same at unix.stackexchange.com/questions/274352/… . Kindly have a look. :-) – We are Borg Apr 5 at 7:50

Here's what worked for me:

ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4

movflags – This option optimizes the structure of the MP4 file so the browser can load it as quickly as possible.

pix_fmt – MP4 videos store pixels in different formats. We include this option to specify a specific format which has maximum compatibility across all browsers.

vf – MP4 videos using H.264 need to have a dimensions that are divisible by 2. This option ensures that’s the case.

Source: http://rigor.com/blog/2015/12/optimizing-animated-gifs-with-html5-video

share|improve this answer
Thanks this is the only version that worked for me on osx. – Pykler Jul 14 at 23:52

You should be able to use imagemagick and ffmpeg. This Stackoverflow post explains how to do it and includes links to additional resources.

Note: the title of the post says .avi, but the accepted answer outputs mpeg.

share|improve this answer
Please provide some of the answer here instead of just linking. – Naftuli Tzvi Kay Sep 10 '13 at 2:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.