Making Animated GIFs With Free Software in Four Steps
Note: this is not Linux-specific. the commands are essentially the same on the windows version of mplayer. The GIMP is also cross platform. see the comments for more details.
MPlayer is a pretty powerful tool for processing video files. It has a built-in command line option that will export specified movie frames to a GIF. Such a feature seems like it would make the guide I'm presenting here obsolete, but the problem with the feature is that the resultant GIF looks terrible: too few colors. As far as I've seen, the best way to get good quality animated GIFs using only free software involves using a combination of MPlayer's command line tools and a little bit of elbow grease in The GIMP. We will export the desired segment of video to a series of JPEG files, then use The GIMP to combine those files into a nicely animating GIF that should look nearly as good as the original video. I believe that it is possible to get MPlayer and The GIMP together in a script that will allow the end user to simply point the script to the desired movie file and the desired segment and the script will do all the "dirty work" and create the GIF. This is my end goal, but I have not taken the time necessary to learn any of GIMP's scripting language. If there is a pre-existing solution that allows one to do what I am trying to show here, I'd love to know about it, so please let me know.
Step 1 (for Debian or Ubuntu users):
sudo apt-get install gimp mplayer
Step 2:
mplayer -ao null -loop 0 -ss 0:11:22 -endpos 5 file.avi
This command will display the segment of file.avi on your screen that runs from 11:22 to five seconds later (11:27). It will loop infinitely until you close the window or send a ctrl+c to the terminal window. This command is useful for figuring out what your GIF will look like before you make it. The audio output will not be heard (is set to null)
Step 3:
mplayer -ao null -ss 0:11:22 -endpos 5 file.avi -vo jpeg:outdir=moviedirectory
This command actually creates the jpeg files you will need to make your animated gif. It is similar to the other command, but nothing is displayed on screen, and the command will not loop forever. The command will output the segment to a series of jpeg files in a directory called "moviedirectory".
Step 4:
Now that we have our directory full of jpegs, we should open the first of these files in The GIMP. Then, open the remainder of the images in the directory as layers (File -> Open As Layers). Every image in that directory should now be a layer. Now save the file as a .gif and choose to "save as animation" as opposed to "flatten image." Click export. Lastly, it is important to make sure "loop forever" is checked if you want a GIF that loops forever. The other options here can drastically change the effect of your gif because they change the speed that the gif is displayed at. A relatively fast gif will have a 15 millisecond delay between frames. The default delay of 100 ms is a bit slow in my opinion. Under frame disposal where unspecified I select "one frame per layer." I check "Use delay entered above for all frames" and "Use disposal entered above for all frames." Here are examples of the end result:


If you find that your image is too large, it is often helpful to resize it to be a bit smaller. This can help with the image's performance.
As Firefox is often the platform where people will be viewing your animated gif files, it is also a good tool to use to test them to see what the final product looks like.
If you liked this or thought it was cool, you should read my guide on using FFmpeg.
Thanks for reading! If you have any questions or suggestions, please leave a comment.

58 comments:
Thanks for the guide!
This is awesome! And YES, it works exactly the same with MPlayer in windows!
Aww, I wish I knew more about computers. I managed to install mplayer for windows, and to get an avi file to play in mplayer, but I'm stuck at how to execute that stuff that pulls the gifs out ... anyone care to tell someone who knows nothing about the command line where to type what?
That's a pretty good looking GIF you got as an example. Looks great.
I've been looking for a way to create some sex tape GIFs and I can't wait to get started now!
coell: I may update the guide at a later time to specifically deal with a situation like yours.
IMPORTANT - be sure that the -loop 0 option is NOT included when you do step 3 (the step that saves the jpgs). I left that command looping (by mistake, of course) overnight, and woke up to find my hard drive full, all the free space taken up by images.
i've written a guide on my italian blog that it's very similar to this...
it doesn't make sense to use GIMP here if you don't need special timings or you want to do some editing...
this command is enough
mplayer video.avi -ss hh:mm:ss.lll -endpos hh:mm:ss.lll -vf scale=160:120 -vo gif89a:fps=3:output=out.gif -nosound
hh:mm:ss.lll it's the time (lll are milliseconds)
gif89a create a gif directly..
nosound speed up the process
-vf scale is for scale it (if you want)
:)
ups.. i forgot..
fps=3 means 3 frame per second...
you can play with it..
3 is really low :)
natonelbronx: have you found that the quality of gifs made with that method is as high as the quality if you output to jpeg first? the first gifs I made with this method about 9 months ago when I discovered it were very ugly (not many colors).
@Noah
i found they are good...
gif have at most 256 colors...
i don't know wich method is used by mplayer to generate the color palette but i'm alwasy found fine with it
anyway.. i think that it's a lot faster to generate the gif directly.. so it worth a try before using gimp..
if you don't like the result then go with gimp :)
what is the top gif from?
The top gif is from the film Rumblefish.
The entirety of that action scene is stylized and could potentially be considered "over the top," but the motorcycle attack takes it to another level.
ummm do you have permission to use those movie segments????
Pretty good blog! You should monetize this blog I think!
Good tutorial. Thanks,
I am thinking to create link back to this post. Hope you do not mind, Please let me know.
Do it.
Thanks Nova, it is done...here
http://phoenix2life.blogspot.com/2008/04/blogahfrorg-public-internet-web-log.html
Awesome tutorial! Everything worked like a charm and I've linked your post in my local forum for others to see. Thanks!
im a noob kthxbai~
hope u are enjoying this success, i hope it doesn't bother u that u stole material from a movie in order to make yourself look better........
Just so you know you can have TrueColor GIFs. They dont need to be limited to 256 Colors
http://phil.ipal.org/tc.html
Yeah -- I learned about true color GIFs when I first researched this topic, but how do you implement that?
anonymous wrote:
"hope u are enjoying this success, i hope it doesn't bother u that u stole material from a movie in order to make yourself look better........"
fair use. look it up.
Thanks a lot, a very good guide :]
With a little variation, this help for make animated pictures in Second life :p
Thanks.
I've been using GIMP for a while and actually forgot I could use it for that. Though instead of MPlayer, I used KMPlayer, the capture options are complicated and require another guide just to explain that lol.
I made this.
http://i26.tinypic.com/2d2acn9.gif
Took me ages to add a stroke because I needed to duplicate the Stroke layer, then move it and merge it like 50 times for each layer. :(
Cool gif.
I used it with Windows fine!
All you have to do is go in the command prompt (Windows key + r [run], and type cmd) and navigate to the folder that you installed MPlayer, and execute the commands from there. worked a treat!
okay i'm using windows and I got the command prompt running but its saying mplayer isnt a command. I've changed the directory to where I put the .exe, but I dont know what to do from there.
is it work with mac?
anonymous said...
is it work with mac?
you can install mplayer via macports:
http://www.macports.org/ports.php?by=name&substr=mplayer
When make gif-animation the Gimp it is hard to open the images as layers one by one if there are many of them. Is there a way to open them all at once?
Is it better to resize images by the MPlayer or somehowthe Gimp? I know how it happen the mcplayer: e.g. "-vf scale=160:120"
Anonymous: when you choose open as layers, it should let you select more than one picture so that you can open them all at once.
Looks like I'm too stupid because I dont get it. What I should to do when press "open as layers" and this appear?
http://img394.imageshack.us/img394/8320/sshot24tp4.png
Haven't tried this in Windows in a long time, but: you can't just click and drag over all the desired files, or ctrl + click to select more than one?
Finally, that "ctrl+click"-method work. This way I can open about 30 pics at once. Thank's again.
Gifsicle is a command-line program (runs on Windows, too!) that can assemble multiple GIF files into a single animated GIF image:
http://www.lcdf.org/gifsicle/
Im having hard time putting step 2 and step 3 I don't know how does that work? where should I go?! I have mplayer and gimp up and i don't know how to start! I have 3 video that i wanna all 3 short quickie video clip together..
bum sex
Man, no matter what delay I set the gif is still much slower than the original video.
Trying to get this to work in Windows, but I'm having some troubles. I have the Command Prompt open in the mplayer folder.
I copy the first command to preview what the .gif will look like. I replaced the "0:11:22" with "0:00:03" (I want it to start at the three second mark). I changed the "5" to a "3" as well, and of course made sure the file name was correct. I hit enter and either the video box comes up, but is just green, or it will not even start at the indicated starting point. It's as if my time intervals are off or something. Any ideas?
its great but the problem is; my animated pictures stoped animating in my blogs for a long time please help me any one.the blog pics are paralyzed,,,,my email is:freedom4ever2@gmail.com
@anonymous using windows (2 comments above): have you tried it with a variety of intervals? if you can't get it to work at all, post again. but sometimes, in my experience, it won't start/stop where you tell it to for some intervals.
@anonymous who needs blog help: do the pics stop for anyone using the site? in different browsers? you might have limited the number of times the animation loops (see step 4 above)
this fucking sucks
Thanks this guide I've been able to create animate gif using mplayer and GIMP on windows. But as a windows user I later found out the kmplayer and photoshop as a better combo. Kmplayer provides a GUI so it might be a bit more user friendly.
so where do i type the commands??
Type them in the Windows Command Prompt (cmd).
pretty cool!! I wonder if you can make animations with sounds you can customize.. i really like the ones from http://www.toonups.com..
haha did you seriously come here to plug a site that sells talking dog cartoons to put into powerpoint presentations?
you can also use ffmpeg to create uncompressed gif's (or the jpeg sequence, or mostly any video conversion).
$ ffmpeg -i "input_movie.avi" -r 5 -pix_fmt rgb24 -s 320x240 -vframes 120 -map 0:0 -b 100 -f gif -y "out.gif"
see here for what each option means: http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC9
this is a great walkthrough but my end result is the same as when i use Photoshop CS4... a slow gif in Firefox, even when i use 0ms delay for all frames.
what do i have to do to get faster motion like in yours?
natonelbronx's mplayer commands do yield poor colors in the output. This can be fixed by changing
-vf scale=160:120
to
-vf palette,rgb2gbr,scale=160:120
This yields nice colors, as in the GIMP method.
I use the following command, which works well on everything I've tried:
mplayer video.avi -ss 00:10:00.000 -endpos 00:00:10.000 -ao null -vo gif89a:fps=10:output=out.gif -vf palette,rgb2bgr,scale=160:120
Oh awesome, thanks for that tip! I spent quite a while trying to figure out how to get MPlayer to do it with nice colors, and never could.
Next time I make a gif, I hope to remember this. Thanks!
Hi there and thanx for the gif guide. A note to Windows7 (Vista) users: run the mplayer command as administrator or it will output nothing ;). Why does the gifs I made do not play in mediaplayer classic and acdsee too? its says bad or unrecogniced image header ... but works fine in firefox
Can an gif include audio and how can a 900 kb gif be reduced to a 200kb gif?
gif cannot include audio. in order to reduce the size of a gif you might try taking out some unnecessary frames or reducing the dimensions of the image....
Thanks! Finally I have my own animated gif for WLM. I use Step4 to create the animated gif.
Post a Comment