Twiddling Your Thumbs – The MKV Thumbnail Problem in Ubuntu

Ubuntu Lucid is a marvelous OS.

Thought I should just come out and say it. It’s a gem of an OS – fast, stable, works with almost anything out-of-the-box, and to top it all off, an LTS release – meaning it gets supported for two and a half years by the Ubuntu people. In all, I’ve been satisfied with Lucid since when I’d first installed it.

But as always, there are some points that really could do with a bit of improvement – and the most major among them, to me, is the default video thumbnailer.

Lucid uses the thumbnailer that comes with totem, its default movie player. It’s not bad, per se, but it has some serious… limitations. For example, suppose you have a large mkv file (I mean on the order of 400-500 MBs to GBs – common, in the era of 720p/1080p video encodes). Totem might successfully generate a thumbnail for the file, it might not – and the chances dwindle as the file size gets larger. This has something to with how long the thumbnailer can run before it decides to time out and leave in disgust. Also suppose if you have a folder with tens (or worse, hundreds) of such videos, in which case opening it with Nautilus makes it run the thumbnailer for each file, meaning CPU usage can climb to 100% in the blink of an eye – and stay there. The program hogs CPU like me in a coffee shop. 😉

The answer? Of course there is one – this is Linux, after all! The answer is ffmpegthumbnailer, a fast and lightweight thumbnail generator that can speed up thumbnail generation by an order of ten or more. A simple apt-get can install this for you:

sudo apt-get install ffmpegthumbnailer

Now pay attention – you can’t just get Nautilus to use this vanilla program for your videos! Some tweaks are needed, for various reasons:

  1. ffmpegthumbnailer only works with absolute file paths, whereas Nautilus by default supplies file URIs;
  2. totem has some internal logic that makes it seek a frame with useful content in it (e.g. faces), whereas ffmpegthumbnailer has to be provided the actual frame to which it should seek to.

To escape these limitations, we need to use a wrapper over the program. Let’s write a wrapper script (called ffmpegthumbnailer_script for convenience) in /usr/local/bin and make it executable:

coderman@coderman-desktop:~$ sudo su –
[sudo] password for coderman:
root@coderman-desktop:~# cd /usr/local/bin
root@coderman-desktop:~# cat > ffmpegthumbnailer_script
#!/bin/bash

## START OF SCRIPT

## ITERATE THROUGH THE FLAGS
while getopts :s:i:o: OPTION
do
case “$OPTION” in
s) size=”$OPTARG”;;
i) inputURL=”$OPTARG”;;
o) outputImage=”$OPTARG”;;
[?]) exit -1;;
esac
done
shift $(($OPTIND – 1))

## ESCAPE THE SINGLE QUOTES IN FILE URI
inputURLWithEscapedSingleQuote=$(echo “$inputURL” | sed “s/’/\\’/g”)

## CONVERT FILE URI TO ABSOLUTE FILE PATH
inputFile=$(python -c ‘import gio,sys; print(gio.File(sys.argv[1]).get_path())’ “$inputURLWithEscapedSingleQuote”)

## RANDOMIZE THE PLACE THE PROGRAM SHOULD SEEK TO FOR THUMBNAIL GENERATION – between 20%-60%
seekThumbnailAt=$((RANDOM%60 + 20))

## GENERATE THUMBNAIL
ffmpegthumbnailer -f -s “$size” -i “$inputFile” -o “$outputImage” -t “$seekThumbnailAt”

## END OF SCRIPT
root@coderman-desktop:~#chmod +x ffmpegthumbnailer_script

Oh, and you need python installed for the script to work – any version will do. And obviously you can use gedit or vi or any other editor too to write the script. 🙂

Finally fire up gconf-editor from the terminal, then in the GUI go to /desktop/gnome/thumbnailers/video@x-matroska and edit the thumbnailer command to:

/usr/local/bin/ffmpegthumbnailer_script -s %s -i %u -o %o

and check the enable option.

Now sit back, wait and enjoy your fast-and-sweet mkv thumbnails – I know I did! 🙂

Advertisements
Posted in Linux | Tagged , , | Leave a comment

Back To 1^2 !

Huh, a full bloody month of teaching – my insides feel like mush. Anyway, after 5 grueling weeks of teaching C++/UNIX to bright-eyed young’uns (no, really!) I’m back from Trivandrum – to work fun and mayhem again over the unsuspecting city!

Heh.

Anyway, seems like what people believe – that teaching helps the teacher to learn new facts and nuances of the subject – are, well, true. (Gasp! Deep has fallen prey to conventional thinking! Is there no end to this corruption?!) I’ve certainly learned a lot – mostly about threading and templates – while trying to dodge the questions the guys and gals were asking with oh-so-innocent faces (hit some of them for sixes, though 😉 ). But really and truly, I need more coding experience.

To that end, my new resolution – another read of Stroustrup’s C++ book, as well as a thorough read-up on design patterns. Java or .NET can wait, I want another step towards the (admittedly little-envied) position of a C++ guru.

Office starts tomorrow. I guess I should be glad – back to the routine, the familiar faces.

Huh. As if.

Laters.

Posted in Uncategorized | Tagged | Leave a comment

Ian Tregillis – Bitter Seeds, a review

On 23rd October, 1920, three children found their destiny.

A Gypsy girl taken into the ‘care’ of a German doctor, a stepping stone in his vision of a road to humanity’s greatness. A young boy searching for food in a garden, among the wartime rationing in London. Another, a young second son of an English Duke, finally forced by his Grandfather into the dark and fiery heritage of his family.

The Second World War will bring them together. Twenty-odd years later, when the fire of World War II burns across Europe, and an ascending German Reich uses the terrifying powers of the foundlings experimented on by the enigmatic German Doctor, holding powers that stem from their transformed bodies unnaturally and beyond apparent physical laws. The young girl is now an Oracle, one who looks into the future and knows what awaits, and works it to her ends without any responsibility or regard for others of her kind. To stop her, an agent of the Crown will have to ally with a Warlock, the keeper of secrets that may mean an end to the Universe. But luck is never to be depended on if you will contend against a Seer, and every victory may contain bitter seeds of dust and ashes…

Ian Tregillis’s Bitter Seeds is a work of science-fiction, with a feeling of secret histories mixed in it, rife as it is with mentions of Nazi super-science and beings of otherworldly power. For all that, though, its success lies in prose and plot, and the interplay of the complexly drawn characters. The three main protagonists are carefully woven, strand by strand, so that in the end the reader is compelled to follow them along, caught in their wake. The young thief, Marsh, becomes a Secret Agent of the Crown, falls all over Europe, even into the heart of enemy territory; faces enemies human and otherwise, even falls in love – he is perhaps the most sympathetic character in the story. The Duke’s son, William the Warlock, is also written in a style that evokes our sympathy, especially near the end of the novel. The secondary characters are also powerful in their own ways, especially Liv and Kraus. But in the end, the Gypsy Seer is the one that stays with the reader the longest. An evil so indifferent to the ripples in the world that the common man would call his life – it is conceivable, but rarely has speculative fiction seen its kind. Throughout the pages resonates a feeling – that this is conceit, deception, manipulation – every little gesture, every word uttered serve the goal of the spider at the center of the web.

And finally, after wins and losses and when hope is proven to be a mirage, her shadow whispers in the reader’s ear – “incoming”!

Posted in Review | Tagged | Leave a comment

Review – D M Cornish’s Foundling’s Tales (aka Monster Blood Tattoo)

It’s been some time (yeah, I’m the king of sweeping understatements around here) since I’d last reviewed any kind of novel – so I guess I must be pretty rusty. Still, I liked the books in this series a little too much and there should be a memo or something – a reminder, when November rolls around, to go and actually buy the third installment.

Synopsis – The plot revolves around Rosamund, a foundling – an orphan deserted at birth at the door of an orphanage. Growing up with the embarrassing name apt for only a girl, he suffers, bravely, the taunts of his peers. Loved by the adults around him for his brave and sweet disposition (though he’s useless in a fight) he nonetheless dreams of the day he’ll be selected as a Vinegaroon (a sailor, in plain words) and venture into the seas. Fate has something else in mind for him, however, and he gets selected by a Lamplighter’s Agent to enter into their ranks – to light the ways all over the empire, facing Bogles and Nickers and other monsters! And his parentage might not be all it seems…

The books are refreshingly original. The first book was a tad too short, but the second more than makes up for it in volume. The world-building is masterfully done, the hand-crafted words coming alive in their sounds and imagery. Monsters are aplenty, and not all of them nonhuman. The side characters are engaging and well-drawn, especially the female characters – Europe the Duchess-in-waiting, and Threnody the teenage Lady Vey. Numps the crippled Seltzerman and Sebastipole the falseman leave an impression. And the main character is drawn with unusual force. Add to that the wits and fulgars, women who can throw around lightnings or turn your brain into mush; falsemen who sift truth and lies with unerring accuracy, or leers with their animal strength and senses – all joined in humanity”s fight to battle the monsters who, on their part, attack back to avenge the betrayal everymen did to them… the book is light fantasy at its best!

Volume one and two, Foundling and Lamplighter, are out. Book three, Factotum, comes out in November. Waiting impatiently!

Posted in Review | Leave a comment

Hope main (Post) { printf (“Hello World!”); return new Hope( ); }

Huh, so this is it. Another missile aimed at the blogosphere hovering above. Another channel like so many others probably destined to devolve into a charnel house of ideas best left forgotten…

But that’s all in the future, isn’t it? Who knows, another turn of the wheel… and things might be better than even they once were… and here and now, we. Are. Alive! 🙂

Optimism. There just isn’t any end to it, is there?

See you around. It’s time to move forward, into the future – one hopeful second at a time…

Posted in Uncategorized | Leave a comment