Line-out scrobbler

for years i’ve been trying to hijack music recognition services like shahzam to be able to recognize music. i’ve finally got this working thanks to the fine guys at echonest, who kindly provide a proper api for this. my proof of concept is running on a spare macbook.

here’s how it works on the mac atm:
1. the os x automator runs in a 90 second loop, recording audio with quicktime and then running a cli php script.
2. the php script first converts the recorded .mov file to .mp3 with ffmpeg/lame
3. the php script then runs the echonest binary for music fingerprinting, which generates a json string
4. part of the json string is sent via curl to the echonest service and (hopefully) resolved
5. echonest returns artist, title and a unique id. this id is saved i a recent-log so that the php script can skip a run if it runs 2 times during the same song
6. artist and title are curled back to our lamp-server, where we save all plays in a database (mongodb atm)
7. artist and title can then be sent to any service you wish to interact with

making this projekt was pretty straight forward, except for a minor obstacle which took me a few hours to figure out. it turns out that the echonest binary calls ffmpeg internally, and for some reason automator couldn’t find ffmpeg in it’s $PATH. when i realized this the fix was done in a second, i just needed to make a symlink from the $PATH automator used to where i had ffmpeg locally.

next step: will try this a few days and see how well it performs. if it’s good enough i’ll buy a tiny linux box and give it a pair of rca jacks.

the earth people account on which we scrobble vinyl to atm
the awesome echonest service

automated screendump creation

i recently had to create jpg thumbs of the first frame from a bunch of videos. doing this manually is not really an option if you have 100 files or more, so commandline to the rescue. i had an ubuntu box, on which i installed ffmpeg:

sudo apt-get install ffmpeg

then cd into the directory containing your video files and run this oneliner:

ls | xargs -i ffmpeg -i {} -vcodec mjpeg -vframes 1 -an -f rawvideo -s 114x64 {}.jpg

in the same directory, i now have a jpg screendump of each video file.
ffmpeg can decode a bunch of formats, should you need support for some other weird format you may need to compile your own version of ffmpeg. good luck!

php class for ffmpeg

i’ve had a few projects over the last years where i’ve needed to convert some video file to flv, generate a thumbnail and get the video’s duration. i’ve never really got around to wrapping this into something reusable. but here it is, get it if you need it.

you’ll also need a non-windows server with ffmpeg installed, and if you need compability with any non-standard formats (3gp/mp3/etc) you need to install these as well. i won”t go into detail about how this is done, just google it.

when ffmpeg is correctly installed on your box, use this class like this:

$encoder = new videoencoder();
$thumbnail = $encoder->export_thumb("yourfile.mp4");
$duration = $encoder->get_duration("yourfile.mp4");
$videofile = $encoder->export_video("yourfile.mp4");

ok i know it’s better to use a service for this, like the excellent – but hey, this is more fun – and really fast! also, worth noting is that while ffmpeg happily converts your files to flv, it will use the old “spark” codec for flash videos, instead of the newer and slightly better codec “on2” due to licensing issues. you can however use mp4 files with recent versions of flash player, which ffmpeg can convert to. use mp4 instead if you worry about video quality (which i guess you should…).

download my php class here.