Create animated GIFs from videos

blue-dress

I wrote an article before, on how to create a Selected portion of the screen GIF image (Image above). This is called cinemagraph GIFs. That image is created with an IOS app which lets you select the portion of the video that you want animated in your final GIF output. The app is Echograph. Vimeo acquired it and is still planning on how to make a good use of it.

Since that app is only available to use on iPad or iPhone, desktop users (Windows and MAC) can’t play with it yet.

In this article, I am going to talk about how to create a GIF image on your desktop with only one free (also open-source) utility.

How to create a GIFs image from video file

I am here just going to re-blog what Amit from DigitalInspiration wrote back in the late 2011. Just because it works so well, and it seems he’s still using the method now, but I am going to use it with Libav instead of FFmpeg and without the other tool.

So let’s get started,

Step 1: Download Libav tool

FIRST, you need to download the latest version of Libav tool, a free (open source) tool to convert video/audio formats and as well as extract parts of it, or export image frames from a video. Libav is a forked (modified) version of the popular FFmpeg tool. Libav supports more video and audio file formats which is the reason I am using it. Amit has this section covered with FFmpeg, you can use either of it. But I prefer Libav.

To download it for Windows 32-bit, get it here. 64-bit version can be downloaded from here.

It’s compressed with 7zip, which you can get it here, if you don’t have Winrar or 7zip extractor.

Extract it to a folder, you would likely to remember. Mine is on the C:\libav-win32-20130610\

Step 2: Get your video file ready to export each of its frame into images.

In this step, you will make use of the Libav downloaded in the step 1. You will breakdown the video you would like to export as an animated GIF, by exporting each frames or images of the video into a folder first. Or in other words, you are going to do a video to image extraction. To do that,

1. Go to the folder you have extracted the Libav, then go to usr folder. Now you need to open the command prompt on the bin folder. To do that, press shift key and right-click on the bin folder, and click “Open command prompt here”. This opens up command prompt on this folder location, from where you would execute the Libav. Keep the command prompt window opened.

2. Now you need to get your video ready. It can be a Youtube video you have downloaded or any video you want to have a portion of it as an animated GIF. If you already have a short 5 or 10 seconds video already cut and saved, that’s even better. Copy the video to the bin folder, or else you will need to type out the entire file path of the video in the command below that does this video to image extraction.

3. Create a new folder in the bin folder, name it like output. So, the extracted images will go into this folder, else it will all be generated in the bin folder itself.

4. Go to the command prompt window, and enter the following command, and hit enter.

libav-avconv-video-to-image-extraction-cmd

avconv is the libav command line interface for video/audio processing.

vid.flv is my video, name it short, so it’s easy to type.

-ss denotes the start time of your video to extract images. It starts at 00:02:12 in the video I am using.

-t is for how long should the video be ran to extract images. It’s in seconds. 7 in the image above is 7 seconds.

frame_%03d.jpg denotes the multiple output files that will be in the format frame_001.jpg and so on…

And if your video is about 10 seconds or less, and you already have it cut out for this purpose, you can ignore the -ss and -t filters.

Running that command, extracted 175 images. Yours could be more or less depending on how many seconds you set to capture it and the frame rate of your video.

It’s now time to go to Step 3, where you combine all the extracted images into one GIF image.

Step 3: Combining all the extracted images into one animated GIF image.

If you noticed I extracted the images to jpg format, this is because, Libav is having some issues converting it to gif, the extracted images are all negative. But the positive side of using Libav is you can still extract the images to whatever image format you want but you can convert it all back to a single animated GIF file.

So still on the command prompt window, type a new command, this time to combine it all. The tool we are going to use is “convert” and not “avconv”.

So by now you have all the extracted jpg images in the output folder on bin. So let’s do the combining, the command is,

I am using a resize filter to resize the image. You can ignore if you don’t want to resize. As well as the input is output\frame_%03d.jpg[056-172]. That’s because I only want those extracted frames to be combined. If you want, say, all the 100 frames, then it would be [001-100].

My output is about 5Mb, and this is how it looks like,

frame

This is created from The Attraction’s semi finals performance at Britain’s got talent video.

That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *