Saturday, December 29, 2012

convert video into an animated gif

Why would someone want to do that?  One use would be to use the animated gif as a profile pic on a social media site or an avatar for a user forum..those are two cases I can think of.

I wanted to convert this short video into an animated gif loop.  The below timelapse was acheived by using the FPS override function of the MagicLantern firmware upgrade for the Canon 5D:

In order to convert the movie, I did two things:
1) in Cinelerra, export a JPG sequence
2) use ImageMagick "convert" to convert to an animated gif

Export a JPG sequence
1) In Cinelerra, you can export your movie as a JPG sequence (among other choices like an EXR/PNG/TGA or TIFF image sequence):

Depending on the number of frames you're exporting, you'll get a whole bunch of files saved to your hard drive.  Since my project was set to 24fps, I had about 120 files saved to my filesystem.  The file names start and end with the number of the frames you selected to export (shown in this screen cap of the Cinelerra timeline):

Here's how the sequence of JPEGs looks in the filesystem:
-rw-rw-r--. 1 sodo sodo   1302637 Dec 28 19:50 seq000373.jpg
-rw-rw-r--. 1 sodo sodo   1304670 Dec 28 19:50 seq000374.jpg
-rw-rw-r--. 1 sodo sodo   1296049 Dec 28 19:50 seq000490.jpg
-rw-rw-r--. 1 sodo sodo   1297281 Dec 28 19:50 seq000491.jpg
-rw-rw-r--. 1 sodo sodo   1298527 Dec 28 19:50 seq000492.jpg

Once you've export all the single images from Cinelerra, use ImageMagick's "convert" program to assemble the individual images into an animated gif.  Since I wanted to resize the 1080P resolution images (1920x1080) into 1/8th the size of the original, I used 240x135 as the resize value.  You can see I've used other specifiers as well:
-delay 0 (no delay between frames)
-loop 0 (infinitely loop the gif)
seq*.jpg (convert is smart enough to assemble the jpgs in ordered sequence)
the other specifiers are essentially "high quality" output settings

[sodo@computer 2012_12_28]$ convert -resize 240x135 -colorspace RGB +sigmoidal-contrast 11.6933 -sigmoidal-contrast 11.6933 -colorspace sRGB -define filter:filter=Sinc -define filter:window=Jinc -define filter:lobes=3 -delay 0 -loop 0 seq*.jpg anim2.gif

The result is a thumbnail of the gif:

da mule