Friday, September 20, 2013

Bucket List of People to Meet in Lifetime!

We all love meeting celebrities. Because of the geography that I live in right now, I have had the opportunity to meet quite a few of them over the past year.

I always had this list of people to meet in person before I die in my mind. Until a year ago, It was mostly more of a fantasy list. But once I moved to where I am now, the fantasy started becoming reality. So I wanted to transfer that list from my brain to a document so that I don't miss out on anyone if an opportunity knocks on the door.

Here is the list (in no particular order):

PersonWho/What/Why?Met/Been There?Note/Souvenir
Thierry HenryThe person I respect the most in the world.No-
Don KnuthFather of modern computer science.No-
Dennis RitchieFounder of C (The R in K&R).Not possible anymore!-
Brian KernighanFounder of C (The K in K&R).Yes2013-06-20: Autograph
Linus TorvaldsFounder of Linux and Git. Strongly believes in whatever he believes in.No-
Robert LoveA huge contributor to the Linux kernel.Yes2013-06-13: Autograph
Bjarne StroustrupFounder of C++.Yes2013-08-15: Picture with him & Autograph
Randall MunroeHe is a hero of mine and worship his sense of Sarcasm and WitNo-
Matthew PerryMy most favorite actor in the world.No-
Lisa KudrowMy most favorite actress in the world.No-
Michael SchumacherHe was a huge inspiration as i grew up watching him win.No-
Larry & SergeyMy role models in life.YesEvery Fridays (now every Thursdays).
Matt CuttsOne of the early employees of Google and famous for his work on Web Spam.Yes2012-12-20: Lunch
Jeff DeanThe most bad-ass engineer ever.Yes2013-01-22: A walk around Charleston Park
Stade De FranceMy most favorite football stadium in the world.No-
Nou CampThe holy grail of football.No-
The Corrs (Sharon Corr)My most favorite band and most favorite violinist.No-
Felicity HuffmanHer character's attitude in Desperate Housewives resembles almost 100% that of my wife.No-
Jim ParsonsWho wouldn't wanna meet him?No-
Ramsus LerdorfFounder of PHP. The language i have written most of my code in.No-
Jeffrey ArcherMost favorite author in the world.No-
Paolo MaldiniI grew up watching him play. Perfect combination of style and class.No-
Arsene WengerI grew up watching him. One of the most inspirational people.No-
Vint CerfThe reason why we all have a job. Founder of TCP.Yes2012-11-20: Said hi and shook hands
Kunnakudi VaidyanathanA person who can talk with violin.Not possible anymore!-
Ron RivestThe R in RSA.No-
Petr MitrichevHas been Topcoder #1 for many years.No-
Mary Lynn RajskubSecond most favorite actress.No-

I will try to keep this list updated mostly as a record for myself rather than for the world to see.


-Vignesh

Wednesday, September 11, 2013

VLC Media Player: Automatically Skip Songs in Indian Movies!


I watch a lot of movies. Really a lot. And VLC Media Player is my (and many others') favorite. Indian movies are plagued with songs in irrelevant times and most of the time it just interrupts the pace/flow of the movie. No offense to music lovers/music makers, I like listening to songs in general. But I don't like them in the middle of an important scene in the movie.

The Problem

Whenever a song starts, inevitably I try to use the seek bar (using the seek bar is really one of the big pain points of any media player as it almost never takes you to where you want) and seek to the end of the song. Most of the time I end up seeking either just after the song (thereby missing something important) or to some portion in between the song (thereby having to wait for some more time for the song to end).

As an engineer, I naturally wondered, Wouldn't it be wonderful to have an automated way (preferably a keyboard shortcut) to just skip the song and move to the more important stuff?

This is exactly what I sat down to solve. Based on this xkcd, it seemed like it would be worth the time.And I (sort of) have a perfect solution that helps me skip songs automatically in the press of a button in VLC Media Player.

The Solution

As hard as the problem might seem, I ended up using a very simple heuristic. Start analyzing the audio stream, and whenever there is a silence for about a second or so, it's likely that the song ends there. I just came up with this heuristic based on the fact that most Indian movie songs are continuous (either lyric or the music goes on throughout the song without any breaks) and when the song ends, there is usually a small interval of silence before the next scene starts. And if there is a silence somewhere in between the song, just do the analysis again and it will take you to the next silence which is most likely the end of the song.

Is it perfect? Absolutely not. It's not even a solution, it's more of a heuristic (aka hack) which exploits some pattern in the Indian movie songs. And in my observation (I have been using this for quite a while now), It seems to be working correctly 99% of the time.

Implementation Details

Note: This section has technical jibber-jabber. If all you care about is how to use the script in your VLC media player, skip ahead to the "Usage" section.

First things first, I chose VLC media player, because that's the one I use. If you aren't using it, then you should start using it too. To begin with, we need to query VLC Media Player.

The overall flow goes something like this:
  1. Get the name of the file that VLC is currently playing
  2. Get the time point of the current playback from VLC
  3. Analyze the audio stream of the file and detect the next silence beginning from the time point of current playback
  4. Seek VLC to the determined duration where silence was detected (this is likely the end point of our song)
As complex as these steps might seem, they are fairly trivial to accomplish. To perform steps 1, 2 and 4 all we need to do is enable the HTTP interface in VLC. Once that's done, it is straightforward to get details of playback and control the player through a simple HTTP interface. The 2nd step is a little more tricky as it involves analysis of the audio stream of a file. Fortunately, we have a swiss army knife in our hands which will not only analyze the audio stream, but pin point us to the exact location of silence that we are looking for. The tool is none other than FFmpeg. The silence detect filter in ffmpeg has been used to accomplish this.

Here is a rough sketch of the ffmpeg command that I use:

ffmpeg -ss <start_time> -i <input_file> -t 600 -vn -af silencedetect=noise=0.1 -f null -

Let me break that up:
  • -ss <start_time> :- seeks to the specified time in the input file. this value for this is obtained from VLC's HTTP interface
  • -i <input_file> :- absolute path of the file that VLC is currently playing. this value is obtained from VLC's HTTP interface
  • -t 600 :- analyzes only 600 seconds (10 minutes) of audio to detect for silence (as Indian movie songs are hardly longer than 10 minutes).
  • -vn :- ignore the video
  • -af silencedetect=noise=0.1 :- enable the silence detection filter with a threshold of 0.1dB. this value was picked by trial and error.
  • -f null - :- just print the output of the filter in stdout rather than a file.

We then grep for the exact duration and then seek VLC based on this output.

Code

Look into the variables on top of the file and change them as per your environment if required.

Usage

To use this script, you need to install the following (fairly straightforward if you are tech-savy, but doable even if you are not).


Once you do the above steps, all you need to do is to bind a keyboard shortcut such that the script will execute. For Mac, I used Keyboard Maestro to set up a global keyboard shortcut which will invoke the script. There should be an equivalent program for Windows/Linux too. So that whenever a song starts, I merely use the keyboard shortcut to skip it.

Hope you enjoy it.


-Vignesh


Education is a cure for all problems. Donate for the cause of Educating kids: Computer Kindness Foundation is helping schools to build Libraries. Follow the link to contribute.