Creating video for Android phones from Ubuntu Linux
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:
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.

