19/08/2007: Sequential Video Thumbnails on Linux
So, I was looking for a way to create sequential video thumbnails (like this one) from a video file on Linux. I found that my options were severely limited. On Windows there are a plethora of tools capable of this fairly simple task, including Media Player Classic, but on Linux all I could find was QFrameCatcher. The QFrameCatcher website was inaccessible yesterday; today I managed to download the source code, but couldn’t get it to build.
Anyway, I decided it probably wouldn’t be very difficult to build my own so…
dhyana.pl
dhyana.pl is a small Perl script that co-ordinates mplayer and ImageMagick to create a lovely montage of thumbnails. (Dyhana — roughly pronounced as “jahna” — is the Sanskrit word for a deep meditation.)
Usage
dhyana.pl MovieFile.avi 8 4 ‘240×180+10+10’
The first parameter is required and is the file name for the movie file. dhyana.pl has been tested with videos in AVI, WMV and MPEG formats. MPEG videos come out looking like crap, but AVI and WMV look much better.
The second and third parameters are the numbers of rows and columns in the output file. These parameters are optional and default to 6 rows and 4 columns = 24 thumbnails.
The fourth parameter is a geometry setting to be passed to ImageMagick. This is also optional. It takes the form of WxH+L+T where:
- W is the thumbnail width
- H is the thumbnail height
- L is the left and right padding
- T is the top and bottom padding
Thumbnails will be resized keeping their aspect ratio, so images don’t look squished. Normally with ImageMagick you can precede the width with an exclamation mark to force the image to be resized to exactly the sepcified dimensions. I’ve not tried this with dhyana.pl, but it should work. The default geometry is ‘240×180+10+10’.
Requirements
- ImageMagick
- MPlayer
- ffmpeg (optional)
- Perl 5
FFMPEG is used for MPEG video captures and MPlayer is used for other video captures. As previously mentioned MPEG video captures look like crap — but they look even worse when you use MPlayer. AVI and WMV captures look great. (This has to do with key frames and stuff… I won’t go into the boring details. Also, it’s worth noting that ffmpeg is very slow for video captures. MPlayer is significantly faster.)
If you have those programs, but they’re not installed in the normal place (/usr/bin/), then you’ll need to open up dhyana.pl in your favourite text editor and manually set the correct paths.
Actually, you’ll probably need to open it up anyway and enter in the path to your favourite TrueType font, as it’s probably different to how it is on my system.
Download
If, after all that, I’ve not scared you away, here it is…
Comments
Comment 001
Thank you for this script! There were some problems - missing midentify (ends with Error creating montage!) but i find it here https://lists.berlios.de/pipermail/gpodder-devel/2006-November/000289.html (if somebody will need it) and put it to /usr/bin/midentify and it works well now!
so thank you very much!
Date: Friday, 24th August 2007, 1:57am (BST)
Comment 002
Nice job! Thanks a lot for this usefull tool.
Damian.
Date: Sunday, 26th August 2007, 2:35pm (BST)
Comment 003
Very nice! Thanks a lot! Exactly what I needed.
Date: Sunday, 16th September 2007, 5:02pm (BST)
Comment 004
Tnx, great script
Date: Wednesday, 26th September 2007, 6:18pm (BST)
Comment 005
Tried your script. When I run it as a regular user, it dies with ‘Error creating montage’.
So I tried sudo’ing it, and it got further. However now it dies at the end. It appears to have worked, but the last few lines are this:
debug: Annotating montage.
convert: unable to get type metrics `-‘.
convert: unable to open image `/tmp/dhyana-6972//annotation.png’: No such file or directory.
debug: Saving final file.
debug: Cleaning up temporary files
This is on Ubuntu Gutsy Gibbon. Any help would be appreciated.
Date: Sunday, 30th September 2007, 8:05am (BST)
Comment 006
Okay, this is weird. I posted about those errors… And yet the file is there?! It’s definitely worked. Very strange.
So disregard.
Date: Sunday, 30th September 2007, 9:02pm (BST)
Comment 008
I get the same error like Drood on Gutsy Gibbon:
debug: Annotating montage.
convert: unable to get type metrics `-‘.
convert: unable to open image `/tmp/dhyana-6972//annotation.png’: No such file or directory.
Date: Sunday, 18th November 2007, 6:03pm (GMT)
Comment 009
This is really great! I love the fact that video info is printed too. And though I’m not a programmer, this PERL code is so simple and therefore very customizable (I had to change paths and it was quite easy). Thanks a lot!
Date: Sunday, 25th November 2007, 10:06am (GMT)
Comment 012
I’ve got the same problem as drood and anonymous on fedora 8. the thumbnail image is created, but without annotation.
convert: unable to get type metrics `-‘.
convert: missing an image filename `/tmp/dhyana-1934//annotation.png’.
convert: unable to open image `/tmp/dhyana-1934//annotation.png’: No such file or directory.
convert: unable to open file `/tmp/dhyana-1934//annotation.png’.
I assume that the syntax of parameters passed to convert has changed or is wrong. this is how convert is actualle called:
/usr/bin/convert
background ‘AliceBlue’ -fill ‘#0080’ -font ‘@/usr/share/fonts/msttcorefonts/trebuc.ttf’ -pointsize ‘18’ -gravity North -trim +repage -bordercolor ‘AliceBlue’ -border 20×20 text:‘/tmp/dhyana-1934//annotation.png’$ convert -version
Version: ImageMagick 6.3.5 09/20/07 Q16 http://www.imagemagick.org
Copyright: Copyright © 1999-2007 ImageMagick Studio LLC
would really like to have annotations in the thumbnail image.
otherwise - great work
Date: Thursday, 20th December 2007, 2:31pm (GMT)
Comment 013
A newer version is available…
Date: Sunday, 6th January 2008, 2:42am (GMT)
Comment 020
Thinks very very much…~!!!
Wow, this is great..
if you are using debian
$ apt-get install libgetopt-argvfile-perl
$ apt-get install libfile-chdir-perl
and using Premek’s advice
Date: Friday, 25th January 2008, 2:33pm (GMT)
Comment 036
for those receiving “convert” errors that prevents the file info from printing at the top of the thumbnail like convert: unable to open image `/tmp/dhyana-1934//annotation.png’: No such file or directory.
look for $text_font and $text2_font
and fix the paths to point at a font that exists i.e. /usr/share/fonts/corefonts/trebuc.ttf
Date: Sunday, 9th March 2008, 10:51am (GMT)
Comments are moderated and may take one or two days to show up on the site. You can bypass comment moderation by signing up as a registered user.