Wednesday, February 08, 2006

Animated Gifs

I did have other blogging plans tonight, but it is getting late, so I think I only have time for a quick post. In the future, maybe you should expect interesting topics on the weekends, and quick tips like this one on the week days.

Anyway, one of my friends was asking me about animated gifs today. Animated gifs are usually used for simple, sort animations on websites. For some reason, the friend in question wanted to convert a mpeg video into an animated gif. The mplayer media player/encoder has a handy way of doing this. (Mplayer is normally used on linux machines but also runs under windows, check out the website for more info). To really harness the power of mplayer, you need either a frontend or to use the command line. Anyway, to make an animated gif out of a mpeg (or any other supported file type) you can use a command like this:

mplayer -vo gif89a -ao none file.mpg

the -vo switch sets the video output driver, the -ao switch does the same for audio. You can replace either with help to see some other choices. In the example above, you will get a file out.gif, with your animated gif. Mplayer also comes with a very powerful video encoder, mencoder which works pretty much the same way (with -ovc and -oac). for more information on mencoder, read the documentation on the mplayer website.

Never wanting to be restricted to only one way of doing things, you can go about this a different way (if you have lots of ram/hard drive space), and convert the mpeg into a lot of png image files (one for each frame). **If you are smart, you will only run the following command in an empty directory (folder)**

mplayer -vo png -ao none file.mpg


Then you can use the ImageMagick image processing toolkit to change those pngs into an animated gif.

covert *.png file.gif

Fun to play with, but I don't know why you would want to use it.

to go the other way, from image files to another movie format you can use mencoders -mf option

mencoder mf://*.png  -mf type=png:fps=30 -ovc lavac -o out.avi

Changing options as needed. You can replace png with a number of other image formats, like jpeg (useful when you get a huge number of seperate frames from blender)

Some versions of mplayer can also output a video as ascii art, so run mplayer -vo help to see if you have that plugin installed (I don't so I can't remember what its called)

Happy animating!

No comments: