Neglect

I’ve been neglecting this blog of late, it’s not that I haven’t had stuff to put up on it, I have, I’ve just not got my finger out. Since I’ve been fiddling with some NoSQL and MapReduce stuff lately, I thought I should extract said finger and write some blogs in case someone find any of it useful. So there maybe a small surge of blogs in the next week or so…

Extracting Audio Tracks From MKV Files

I’ve been ripping all my DVDs to MKV files, so I can serve them up via XBMC running on a Raspberry Pi. I was up in the loft at the weekend, mainly trying to sort out the mess into something more logical. I suddenly remembered that I had a number of music DVDs that I bought with the express intention of ripping the audio from, so I dug them out.

My normal DVD ripping process is to use MakeMKV to get a raw MKV file and then use Handbrake to re-encode the contents it into something slightly smaller. I want to be able to listen to these DVD tracks on a mobile player as well as at work, so I don’t just want them as MKV files with video and audio, I want a separate audio file as well. One of the features of Handbrake, is the ability to add more audio tracks with different encodings etc, so it’s really easy to have your DD or DTS passed through and have it re-encoded into FLAC, Vorbis or MP3 on a separate track.

Armed with a MKV file that contains a FLAC/Vorbis/MP3 audio track, the only thing left is to extract this track into a separate file. If you are using Linux or Windows, then there are a couple of command line utilities that make doing this quite easy, they’re part of the MKVToolNix package, which you should be able to get out of your distributions repositories or download from here. I had four DVDs to extract audio tracks from, one of the DVDs had two different live concerts, so you can imagine there was a fair few files to extract audio from once each song had been ripped to its own MKV file.

It would have taken a while to manually extract the audio track from each MKV file, so I needed a way to script it, so it could all be done automatically. Firstly, I needed to find out the track number that the audio was on, I used mkvmerge for this:

~/scrap/music/mkv/Franz Ferdinand/Live at Brixton$ mkvmerge -i 08\ -\ I\'m\ Your\ Villain.mkv
File '08 - I'm Your Villain.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AC3)
Track ID 3: audio (A_FLAC)
view raw mkvmerge hosted with ❤ by GitHub

All the MKV files I’d created had the FLAC audio track on ID 3, which made life slightly easier, so then it was just a case of finding all MKV files in the current folder tree and extracting track three from them. I used mkvextract in the following script:

#!/bin/bash
find . -type f -name *.mkv | while read filename; do mkvextract tracks "$filename" 3:"${filename%.*}".flac; done
view raw extract-flac.sh hosted with ❤ by GitHub

It would be cool to call the script with the output format you want to extract (A_FLAC in this instance) and parse the output of mkvmerge for each MKV file to find the desired track id to pass to mkvextract. Doing it this way, with a fixed track id, was all a bit quick and dirty, but it worked for me. Maybe I’ll modifying it in the future, but as I’ve no more music DVDs needing audio ripped from them, I’m in no rush…

A Second Slice of Pi

My second Raspberry Pi turned up yesterday, which made me smile. Now I just need to decide on a project to use it on. I have a few ideas, but as with anything, finding the time to execute might be problematic. The other small issue, is that I’m pants at electronics, it’s one subject that I never really paid any attention to when at Uni, so my skills are a bit lacking. Hopefully something like the Gertboard or the PI Face IO board will help in that respect, but I should probably get a breadboard from somewhere and start tinkering.

I have two main projects in mind, one is to automate my home brewery, the other, to turn the Raspberry Pi in to a flight computer for use in my high power rockets. There are a few other things that I’ve thought of, but those are the two main ones. Even though I’ve been told that the Raspberry Pi isn’t ideal as a flight computer, I’d still like to fly it, although I might wait for the camera board before looking into doing that.

Either way, I now have to Pi’s and I need to start making use of them.

XBMC the Thecus N3200 NAS and NFS

After getting OpenELEC installed on an SD card and running on my Raspberry Pi, the next step was to get XBMC serving up all the media that is stored on our Thecus N3200 NAS.

It looked like it should be pretty straight forward, as I already have various NFS mounts setup on the NAS for access via my Kubuntu laptop. However, I just couldn’t get XBMC to browse into any of the mounted folders; it could see them, just not access them.

There isn’t much information out there about my NAS, mainly as it was superseded pretty quickly by the N3200PRO. Which meant that there wasn’t much information with which to try and diagnose the issue. After a bit of googling, I did manage to track down a post that implied that my NFS mounts would need to invoke insecure mode, which was backed up by the XBMC wiki. Shame the N3200 doesn’t expose any real NFS settings, so you can’t configure the mounts from the frontend; at least not with the last official firmware.

I did look at adding the insecure flag the NFS mounts directly, via the /etc/exports file; shame that you can’t SSH into the NAS by default though. After a bit more trawling, I found a couple of modules that would allow me to reset the root password and run a SSH demon. With the modules loaded, I SSH’d into the NAS and added the insecure flag to each of the NFS mounts; shame the changes were lost when I rebooted. I eventually gave up trying and asked for help on the Thecus forums, I haven’t had a reply yet.

While I wait on a reply, I just added the various mounts to XBMC via SMB. It’s not my first choice, but it appears to work fine, at least there were no obvious streaming issues while I watched Ratatouille last night…

OpenELEC

The HDMI cables and SD cards I ordered via Amazon, were waiting for me when I got home on Friday after work. So I spent some of Saturday morning trying to get OpenELEC up and running on my Raspberry Pi, with various levels of success.

Earlier in the week I cloned the OpenELEC github repository and compiled the source, before installing it onto the SD card I normally use in my Nikon P6000. I followed the instructions on this page of the OpenELEC wiki and it appeared to all go to plan. A couple of corrections needed to be made in the Installing OpenELEC to the SD Card section, as the build put certain files in a different place to that specified. Instead of copying the files from:

$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/arm128_start.elf /media/System/start.elf
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/bootcode.bin /media/System/
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-driver-*/boot/loader.bin /media/System/

They were in the bcm2835-bootloader-* folder, not the bcm2835-driver-* folder, so I copied them with:

$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/arm128_start.elf /media/System/start.elf
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/bootcode.bin /media/System/
$ sudo cp build.OpenELEC-RPi.arm-devel/bcm2835-bootloader-*/loader.bin /media/System/

After a bit of faffing with my TV and AV equipment, I finally managed to get a picture displaying on the TV, but as you can see from the image at the top of this post, all I got was an error message. Rather than break out the laptop to edit the cmdline.txt file and spend a while trying to get the partition name correct, I just downloaded one of the nightly builds and ran the create_sdcard utility. This produced a working SD card and I was able to boot straight into XBMC, all in all a much easier and less time consuming option.

Binding Backbone Callbacks

There’s one thing about JavaScript that’s always been an issue for me and that’s remembering to bind callback methods to the correct scope. For some reason I always forget and then spend an age trying to figure out why things aren’t working correctly. I’m forever doing this kind of thing in a Backbone view:

Backbone.View.extend({
events: {
'click a.enable': 'enableHandler',
'click a.disable': 'disableHandler'
},
initialize: function() {
this.model = new Model();
this.model.bind('change', this.render, this);
}
// ...
enableHandler: function(e) {
e.preventDefault();
this.model.save({
enabled: true
}, {
wait: true,
success: function() {
this.$('a.enable').hide();
this.$('a.disable').show();
},
error: function() {
// ...
}
});
}
// ...
});
view raw NoBinding.js hosted with ❤ by GitHub

I’m then left wondering why all my enable/disable links, or similar, are being changed, instead of just the one that was clicked on. You’d think it would just fail, instead, the jQuery selector isn’t scoped to the Backbone view element and instead selects all matching elements in the document.

It’s really not that hard to wrapper the callbacks with the Underscore bind function:

Backbone.View.extend({
events: {
'click a.enable': 'enableHandler',
'click a.disable': 'disableHandler'
},
initialize: function() {
this.model = new Model();
this.model.bind('change', this.render, this);
}
// ...
enableHandler: function(e) {
e.preventDefault();
this.model.save({
enabled: true
}, {
wait: true,
success: _.bind(function() {
this.$('a.enable').hide();
this.$('a.disable').show();
}, this),
error: _.bind(function() {
// ...
}, this)
});
}
// ...
});
view raw Binding.js hosted with ❤ by GitHub

It would be nice if I could remember to do this automatically when writing a callback function. Given that I’m still forgetting to do it after years of programming JavaScript, I don’t hold out much hope that I’ll suddenly start remembering…

github

I’ve finally succumbed and created a github account. I have no idea how to use github or git, other than cloning a repository. I have some ideas of what to put on there, I’m just not sure how I should lay it all out yet. Suppose I should really dust off a couple of old projects that have fallen by the wayside and finish them off.