Creating video for Android phones from Ubuntu Linux

Click here to download:
video2android (0 Bytes)

I recently replaced my phone and (Windows mobile) HP PDA with a
(Android) HTC Desire smartphone. I'm very happy with it, but my DivX
videos don't play on the built-in movie player. Android phones
understand baseline H.264 MP4 video, so I just needed to figure out
how to convert arbitrary video input to Android-compatible MP4 using
Ubuntu Linux (the OS I use more-or-less exclusively on devices bigger
than a phone). This turns out to be very easy, but it took a bit of
Googling around and messing about to get a solution that works
well. Most of my info came from the official Ubuntu wiki:

https://help.ubuntu.com/community/AndroidVideoEncoding

but I also picked up useful hints and tips from several other sites,
including:

http://www.talkandroid.com/android-forums/android-videos/1685-convert-videos-...

http://www.thesourceshow.org/node/125

http://alien.slackbook.org/blog/re-encoding-video-for-android/

Essentially, it's just a matter of using the wonderful "ffmpeg"
program, but you need the right arguments and the right (non-free)
codecs in order for everything to work. So, first you need the
non-free codecs, which are in "Medibuntu". My first problem was that I
thought I had Medibuntu enabled, but didn't, because I'd recently done
a dist-upgrade to 10.04 LTS (Lucid) which disables Medibuntu. So,
re-enable before continuing... Installing the dummy package
"non-free-codecs" from Medibuntu probably does the trick. Obviously,
you also need "ffmpeg" installed. After that, it's just a matter of
getting the right command line. Slightly different versions of ffmpeg
use slightly different syntax. I'm using the standard version
associated with Ubuntu 10.04 (Lucid). After a bit of messing around, I
found that the following works very well:

ffmpeg -i input.avi -s 432x320 -b 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec libfaac -r 15 output.mp4

where "input.avi" is the video to be converted, which does not have to
be in an AVI container - it can be anything that ffmpeg understands,
including AVI, MP4, FLV and VOB. "ouput.mp4" is the name of the output
file that should play (nicely) on Android devices. The attached bash script wraps up the command, so that it is easy to
call on multiple files. eg. calling "video2android *.avi" will convert
all AVI files in a given directory, using a sensible name for each
output file.

Basic Mandelbrot set in R

On a train home from Norwich at the end of a very long day...

The Mandelbrot set has been back in the news of late due to the
unveiling of the awesome "Mandelbulb" 3-D fractal:

http://www.skytopia.com/project/fractal/mandelbulb.html

So my programming exercise for tonight was to write a complete program
to compute and plot a basic old-style 2-D Mandelbrot set:

http://en.wikipedia.org/wiki/Mandelbrot_set

in fewer than 10 lines of code. It turns out to be quite doable in R,
exploiting the fact that R has built-in support for complex numbers
and can perform vectorised operations on complex matrices. Code and
image attached. I should point out that this vectorised approach has
limitations, but leads to code that executes reasonably quickly in
vectorised languages like R (and python, and Matlab,...). It's
certainly not how I'd approach the problem using a language that
doesn't have a huge penalty associated with explicit looping over
pixels (like C, or Java, or ...). See the above wikipedia article for further details,
including pseudocode that is a lot longer than 10 lines! ;-)

Mandel

Click here to download:
mandel.R (0 Bytes)

UK railway station codes and live train info via SMS

Attached to this post is a full list of three letter codes for UK
railway stations (and the corresponding full station name) which I
screen-scraped from the National Rail
http://www.nationalrail.co.uk/stations/codes/ web site a couple of
years ago. I've included CSV and XLS. I've included XLS not because
I'm a Microsoft fan (I actually created the file with OpenOffice
running on Ubuntu Linux!), but because it reads into PocketExcel on my
Windows Mobile PDA, and I find that the most convenient way to browse
and search the info when I'm out-and-about.
 
The three-letter codes are useful to know for all kinds of
reasons. For example, I use them when using National Rail and rail
ticket sellers web sites - they are just quicker, easier and less
ambiguous than full station names. However, they really come into
their own when travelling by train, when you have a mobile phone with
SMS but no internet. National Rail have excellent live train info
available via a text-back service, but to use it it's best to use
those three-letter codes...
 
The SMS number is 84950 - just text one or two codes to that number to
get live info. eg. texting "DHM" to 84950 will give the upcoming
departures from Durham, and if they are running late. But even more
useful, is to text, say, "DHM BHM" to 84950, to get information on the
next trains from Durham to Birmingham New Street, complete with
information on if, when and where you need to change. Obviously there
is a small charge for this service (I think it's 25p a go), but it is
very fast and convenient. I've been using this service for ages, but
talking to people, it's surprising how many people don't know about
it yet.
 
Note that there is a similar SMS text-back service for UK buses, which
you can find out about from www.traveline.info but for that it's
easiest to look up the bus stop codes you want in advance, on-line.

Click here to download:
railway-codes.csv (51 KB)

Click here to download:
railway-codes.xls (265 KB)
(download)