How to Make an Animated GIF from Video

Album Cover: Black Holes and Revelations

"Come ride with me through the veins of history. I'll show you a god who falls asleep on the job."
Muse / Knights of Cydonia

Posted on August 16, 2009 11:07 AM in Computers
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

My wife spends a lot of time over at OH NO THEY DIDN'T, a celebrity gossip site. Anyone who knows that site knows that its readers love their animated GIFs. My wife always says things like "I wish I had an animated GIF of that," and I've always wondered what it took to make one from video (yes, we're geeks). Today I decided to find out.

Amazingly enough, there doesn't seem to be a definitive source online for this information. There's this silent tutorial on YouTube that looks to require, at minimum, MediaCoder and GIMP. There's also this somewhat frightening YouTube walkthrough that seems to require a recent version of Photoshop. It wasn't until I stumbled upon Making Animated GIFs With Free Software in Four Steps that I saw something I might be able to work with.

As is typical with such posts, some of the information provided in the comments was actually more useful than the post content itself. Unfortunately, though, no one put the pieces together into one single, coherent walkthrough of how animated GIFs can be made from a video clip. That's where I come in.

The great thing about the information found at that site is that it applies to both Windows and Linux (and therefore likely Mac as well). In the end, all you end up needing to have on the software side of things is MPlayer (which I've covered here before), which can be had by downloading the "MPlayer SVN Windows with SMPlayer GUI" option from here or by typing apt-get install mplayer from the command line on Linux.

As the commenter natonelbronx pointed out in the aforementioned comments, it's possible to make a single command line call to mplayer.exe (Windows users will find mplayer.exe in a subfolder named "mplayer" underneath the root "SMPlayer" installation directory) to generate an animated GIF from a video file. What he didn't know, though, is that his method results in inferior color quality when used. Fortunately for me (and anyone else looking to create an animated GIF from video in one easy step), an anonymous commenter provided a better option, which takes advantage of MPlayer's additional video formatting options to ensure the color quality is much richer.

After combining the tips from both commenters, I ended up with the following command line call, which should look the same on either Windows or Linux, with the exception of the ".exe" part not applying to Linux:

mplayer.exe ghostbusters.mkv -ss 32:35 -endpos 7 -ao null -vo gif89a:fps=10:output=ghostbusters.gif -vf palette,rgb2bgr,scale=240:135

Here's a breakdown of what's going on in that command line call:

  • "ghostbusters.mkv" is the name of the video file I'm using to generate the animated GIF.
  • The -ss argument is used to tell MPlayer to start the GIF at the 32 minute and 35 second mark of the video file.
  • The -endpos argument tells MPlayer to stop the animated GIF 7 seconds after the starting point.
  • The -ao null argument/value pair tells MPlayer not to worry about sound, since that isn't needed for an animated GIF.
  • The -vo argument tells MPlayer how the video output should be formatted (gif89a makes the output a GIF, fps=10 sets the frame rate to 10 frames-per-second, and output=ghostbusters.gif gives the output a file name).
  • The -vf argument is the trick for making sure the colors are richer in the output, with the scale portion providing the dimensions of the resulting animated GIF (you'll want to keep this scale rather small because animated GIFs have a tendency to grow in file size very quickly).

In the example, I converted an MKV file, but I've seen this same call work for AVI and MP4 files as well. I assume any video format MPlayer can play should work just fine. The command only took a few seconds to run, albeit on a beast of a computer, and when it was done, I had generated the following animated GIF:

Animated GIF of a Clip from the Movie Ghostbusters

(You might need to give it some time to load since it's about half a MB in size).

So there you have it -- an easy way to generate an animated GIF from a video file without the hassle of expensive software or multiple steps. Have fun!

Comments

Indylavi on August 27, 2009 at 9:01 PM:

Hello, I'm a member of ONTD and sutbled upon your site on a google search. I wrote a tutorial on how to make an animated gif using VirtualDub and ImageReady. I posted that here

http://lavisworld.blogspot.com/2008/07/making-gif-using-virtual-dub-imageready.html

Watch out clicking on the thumbnails. I posted those before Imagevenue started putting their ads on links. So the adds may be NSFW :( They started putting some stupid dating site ads. I use tinypic now for that reason.

Anyway, It depends on the users computer. If you are using a windows PC. There are plenty of Options. You can use the above method with GIMP if you don't have Photoshop ImageReady. As both GIMP and VirtualDub are free programs. Just export video as an imagesequence in Virtualdub and import files as frames in GIMP.

A good non free program is Ulead. But that will only convert AVI files. But these programs only work on PC and not a MAC.

Permalink

Joe on October 08, 2009 at 9:16 AM:

Thank you! This is exactly what I needed.

Permalink

Matt on March 19, 2010 at 12:00 AM:

Yeah, this creates GIFs, but as you may have noticed, the quality of them really, really sucks.

Permalink

anonymous on September 12, 2010 at 11:41 PM:

But how do you run the command to begin with?

Permalink

Anonymous on September 27, 2011 at 5:47 AM:

This method makes low-quality gifs because mplayer's gif89a output converts them to 256 colors (8-bit; says its documentation). For 32 or 24-bit gifs (high quality), start with the method from his source site:

http://blog.ahfr.org/2008/03/making-animated-gifs-with-free-software.html

...BUT use these "vo" and "vf" command options instead of the site's "vo/vf" options:

-vo png:z=9:outdir=moviedirectory -vf pp=al,scale=240:135

Then, use GIMP or ImageReady to change the image color's mode to "indexed", optimized with dithering. "Save as" an animated gif with a delay between frames, and enjoy.

Permalink

Anonymous on September 27, 2011 at 6:43 AM:

@comment 11:41
You type/paste it in a Command Prompt (Terminal). If you're on Windows, look in the Start menu -> All Programs. If you don't see "Command Prompt", open Start menu -> Run, and type "cmd.exe". If you're on Linux, open a terminal window.

Before typing the mplayer command, learn to use the "dir" and "cd" commands (Google them) to navigate between folders from the command prompt. This is essential for typing the proper location of your movie file in the mplayer command and for specifying where mplayer saves its output images. The mplayer command will save its images inside whatever folder you're currently inside of on the Command Prompt.

To make it easier, put your movie in your "My Documents" folder, and run all commands from that folder. (so you only need to give mplayer filenames like "ghostbusters.avi", not full paths like "D:savedvideosghostbusters.avi")

Permalink

Anonymous on September 27, 2011 at 7:23 AM:

@5:47
Correction:
256 colors is not necessarily 8-bit. Gifs can have a palette of any 256 colors selected from the 24-bit color space. The high-quality difference comes with indexing optimizations (to select better colors) and dithering (to give the illusion of blended colors) in GIMP or ImageReady.

Permalink

Do Short Sales Still Help Homeowners? on October 31, 2011 at 9:48 AM:

I LOVE this post! I have been researching this topic and I appreciate the hard work that went into this post. I will be back very soon for more detailed information. Thanks again! Awesome Job!

http://www.investorsedgeuniversity.com

Permalink

Gif Man on January 01, 2012 at 1:20 PM:

This application provides a simple way to get the job done:
http://www.evanolds.com/movtogifsimple.html

Permalink

Post Comments

If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.

Name:

Email Address:

Website:

Comments:

Check this box if you hate spam.