Main menu:


Please consider a small donation:



Or you can donate bitcoin:


Thanks to TekLinks in Birmingham, AL, for providing colocation and bandwidth.

Page Rank


FOSS Force Best Blog--2013 Award

Recent posts

Recent comments

About this blog

I am Eric Hameleers, and this is where I think out loud.
More about me.


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 425 other subscribers

My Favourites



April 2019
« Mar    

RSS Alien's Slackware packages

RSS Alien's unofficial KDE Slackware packages

RSS Alien's multilib packages

RSS Slackware64-current



Re-encoding video for Android

So I bought myself a nice Android phone in april. It’s a HTC Desire, a real “tweakers’ phone”. It runs Android 2.1 – and before the end of the year, HTC should have an update to Android 2.2 available.

It is an impressive piece of work, and when I compare it to the iPhone or Windows Mobile based phones some of my friends/collegues carry with them, it clearly gives me a lot of freedom – I do not have any desire to “root” or “jailbreak” my phone in order to make it do what I want. I dream of putting Slackware on it, sometimes, but then I usually wake up fast… It’s a real Linux phone (with a SSH and a VNC client installed from the Android Market!), and the HTC Sense interface makes it just perfect and enjoyable as it is.

It goes without saying that I took a flat-fee Internet subscription; this kind of phone is not fully functional unless it is always online. I have been running a bandwidth metering app which told me that I transfered 440 MB in my first month. That would result in a pretty heavy bill if I did not have unlimited traffic.

I may write some more about my experiences with the Desire in future posts (so may exciting things to tell!), but for this one I want to talk about video playback on Android. Android has decent multimedia support out of the box, and audio as well as video players can make use of the standard codec libraries that the Android platform offers.

The “native format” I think you may call it that, for the Android seems to be H.264 video and AAC audio in a MP4 container. There are some limitations however, as people found out when trying unsuccessfully to play MP4  video files on their Android device that would not have had playback issues on a normal PC or mediabox.

Android only supports the H.264 baseline profile, meaning that some of the fancy encoding tricks that give you great video quality at lower bitrates (but require more processing power on playback) can not be used for videos you want to play on your Android device.

And rest assured, you do want to watch videos on the 800 x 480 pixel WVGA screen of the Desire! The AMOLED display has fantastic vibrant colours.

So, in order to create a video file that fits the display dimensions perfectly (without the scaling/resizing which would result in an ugly picture) and contains fully compatible MP4 video, I once again turned to my faithful companion… ffmpeg.

Here is a ffmpeg command line for you. This will take a video file (any supported format will work as input) and produce an Android-compliant MP4 file with WVGA dimensions (800 by 480 pixels). The input file will be transcoded in a two-pass process in order to achieve the best possible results. The transcoding will take a long time, so find something else to do in the meantime.

$ ffmpeg -i [inputfile] -threads 0 -vcodec libx264 \
    -vpre slow_firstpass -vpre baseline -b 480k -r 13 \
    -acodec aac -ab 128k -sameq \
    -pass 1 -f rawvideo -an -y /dev/null && \
    ffmpeg -i [inputfile] -threads 0 -vcodec libx264 \
    -vpre slow -vpre baseline -b 480k -r 13 \
    -acodec aac -ab 128k -ac 2 -sameq -pass 2 [outputfile].mp4

If you are on Slackware, then you get lucky. My ffmpeg packages (the variant that supports AAC audio encoding) are right here:

Have fun experimenting!



Comment from dolphin77
Posted: June 4, 2010 at 14:07


a week ago I just got a Nexus One. Before that I had iphone 3G and I completely agree with your thoughts. Android is much more friendly and doesn’t require any magic like root, jailbreak, snowbreeze, or etc. And it is much more powerful device. (I already upgraded mine to unofficial 2.2 froyo, I had to do this mostly because of russian layout absence in 2.1. It is indeed much faster). I played with your handbrake package to convert videos for my device. But I couldn’t figure right dimensions. Now it is very simple. Thanks a lot once again.

Comment from escaflown
Posted: June 5, 2010 at 04:00

” I dream of putting Slackware on it, sometimes,…” It would be interesting to see how that works out 🙂

Pingback from Tweets that mention Alien Pastures » Re-encoding video for Android —
Posted: June 5, 2010 at 17:27

[…] This post was mentioned on Twitter by Pedro Mendes, Eric Hameleers. Eric Hameleers said: Re-encoding video for Android: So I bought myself a nice Android phone in april. It’s a HTC Desire, a real “tweake… […]

Comment from toby
Posted: June 7, 2010 at 19:43

Good choice, I have the android htc magic and I have been very happy with it – I modded it with the excellent cyanogen mod – watch xda forums for new community roms for your device. Thanks for all your work on slackware Alien- you are one reason its the best!

Comment from gonye
Posted: July 11, 2010 at 14:48

For some days I looking for a solution for the encoding.
I use pulse phone (android eclair), and this ffmeg encoding is work well! Thank you!

Comment from comp_
Posted: August 6, 2010 at 15:59

Wondering if you’re annoyed already by the way in which HTC decides to release firmware updates for their devices and details about what exactly they are updating and if you’ve found any way around it. 🙂

Comment from alienbob
Posted: August 6, 2010 at 21:46

@comp_ –

No, why would I be annoyed? I have an unbranded HTC Desire, and I received my first Over-The-Air update in june, and the second one last weekend got me Android 2.2.

So, actually I am very pleased with the support for this phone by HTC.

I have witnessed first-hand how providers mess with their customers by offering branded phones. Vodafone in the Netherlands pushed an update of their own containing nothing but their “vodafone 360” junk software … but no Android 2.2. And T-Mobile customers have to wait weeks until an upgrade for their branded phone is released. And who know what kind of spam that update will get?

I watched how a friend of mine loaded a generic Desire Android image on to his T-Mobile branded phone. Then we proceeded to download and install the Android 2.2 update using the phone’s recovery mode… a really easy process, no rooting required, which would not be possible if this would have been a Windows-powered phone.


Comment from comp_
Posted: August 9, 2010 at 08:35

The previous firmware update was available for my phone about 2 months after it was released (2.2 is not available yet for it) even if the phone is not operator-locked.

This should explain why

Not saying that any other phone is a better option compared to this one just that it’s not as open as it could be.

Comment from frasq
Posted: October 28, 2010 at 14:06

More info about transcoding audio or video files for droids and other equipment :

Comment from rhintze
Posted: July 28, 2011 at 02:07

I just noticed we need to add this to the end now “-strict experimental”. New version of ffmpeg?

Write a comment