Animated gif previews of video files

A few months ago I won some bonus points with the boss, in a way that deserves keeping a note here.

Our office keeps a large collection of training videos on a networked drive, as part of the orientation program. New employees walk through them in sequence as part of their introduction, and I expect other companies may do something similar.

The files are named with a complex numbering system though, and it doesn’t lend itself to the actual topic of the video. We’ve mentioned that to the training staff and IT specialist, but it’s rather far down the list.

I took the initiative one afternoon and following a lead by Prashanth Ellina, found a way to thumbnail a video frame, and use that as a preview.

Prashnath’s command works like a charm for run-of-the-mill AVI files.

ffmpeg  -itsoffset -4  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg

My only addition would be the -y flag, which overwrites old images; that really only comes into play while you’re testing the output though. ;)

A picture is worth a thousand words, so a six-frame animated gif is probably worth about 6,000 — and that’s my contribution to Prashanth’s trick. You’ll need imagemagick for this part:

for i in {10..70..10} ; do ffmpeg  -itsoffset -${i}  -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test-${i}.jpg ; done ; convert -delay 75 -loop 0 test-* test.gif

And the end result is a simple, six-frame looping gif that shows the content of the first minute or so of the video.

Since our videos all incorporate the same 10-second intro before showing a title screen and opening the lecture, this gives us a snapshot opening frame, followed by a few moments of content. It’s easy to see what the topic is, and remember where you are in the sequence.

You could adjust that loop to start at the 60 second mark and snap a frame every minute, or however you like. It’s convenient and flexible, and the end result can be seen in a browser or an image viewer, so it doesn’t rely on specific software.

The only downsides that I can see involve how ffmpeg tracks to those points in the video: it runs out to the 10-second mark, then snaps. Then restarts, spins out to the 20-second mark, and snaps. Then 30, 40 and so forth, taking a longer time to track out each time.

I don’t know if there’s a way to adjust Prashanth’s original command and just loop through once, and snap at every 10-second interval. I leave that to higher minds than mine.

But it might be inconvenient if you have a lot of videos to gif-ize. In our case it was about 50-60 videos, which was easy to loop through but took about half an hour to process. The end results were worth it though.

This worked for me in Arch, but I don’t see how it wouldn’t work with almost any other Linux flavor that includes ffmpeg. And since Prashanth’s command dates back to 2008, I think earlier releases would be fine as well. For what it’s worth, I’ve used this with Flash videos too.

And that … is everything. For now. :mrgreen:

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s