Archive for the ‘video’ Category

Bash Video Thumbnailer

September 1, 2012

Video thumbnail: a montage of screenshots from a video file, often accompanied by some file info.  Like this:

I wasn’t satisfied with the thumbnailers I had tried for a few reasons:

  • usually incredibly slow
  • work with some files/formats but not others
  • usually don’t understand anamorphic video and make shots with bad aspect ratio
  • often require X and a graphical desktop

So I decided to make my own bash script, videothumbs, that:

  • is quicker than the stuff I already tried
  • works with every video codec and container that my OS supports
  • gets the damn aspect ratio right!
  • works on headless or non-gui systems

And here it is: http://pastebin.com/x96WYVTx

20 March 2013: New version at http://pastebin.com/2iVWDEkx now makes all thumbs with ffmpeg as changes in newer versions of mplayer and some containers caused problems.

As you can see from the image above (click for full size), videothumbs creates an image identically named as the input file except for the file extension, 1024 pixels wide with 4 columns of 10 images.  At the top is some basic file info: file name, video codec and dimensions, audio codec and number of channels.

There is only one user option -o

“videothumbs -o  path  mymovie.mkv”

to have the thumbnail image output to path instead of the same directory as mymovie.mkv.

It uses mplayer or ffmpeg (depending on file type) to grab/create the images and imagemagick’s montage command to make the thumbnail sheet.  It’s quickest with files in Matroska (.mkv) or .mpg/.mpeg  containers.  MPlayer grabs uncompressed png frames really quickly from mkv or mpg but can choke seeking to a specific point in avi files (I think because a position specified in seconds doesn’t always correspond to a keyframe) and on some mp4 files (I don’t know why).  So, for everything that isn’t in mkv/mpg, videothumbs falls back to using ffmpeg to create the images.  This is slower, but still better than hanging….  For a quick comparison I booted Windows XP and made a thumbnail sheet using Media Player Classic: it took absolutely ages and was much slower than my script.

I’ve tested videothumbs on the following containers:

mkv, mp4, avi, vob, wmv, mov, divx, mpg

which contained various codecs:

video: h264, divx/xvid, wmv3, Sorenson Media Video 3 (Apple QuickTime), mpeg2 (DVD), ogv, ogg

audio: aac, ac3, dts, mp3, ogg vorbis, mp2, ima4 (Quicktime)

and probably some others too.  So far everything worked.  YMMV.  I’m running Debian Stable (Squeeze) with (proper) ffmpeg and mplayer from the unofficial deb-multimedia.org repositories.  I have no idea if this script will work with libav as it does with ffmpeg.

Advertisements