My thoughts on Slackware, life and everything

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: http://slackware.org.uk/people/alien/restricted_slackbuilds/ffmpeg/

Have fun experimenting!

Eric

9 Comments

  1. dolphin77

    Wow,

    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.

  2. escaflown

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

  3. toby

    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!

  4. gonye

    Hi,
    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!

  5. comp_

    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. 🙂

  6. alienbob

    @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.

    Eric

  7. comp_

    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 http://mithrandi.net/blog/2010/07/htc-ota-updates/

    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.

  8. frasq

    More info about transcoding audio or video files for droids and other equipment : http://www.frasq.org/en/transcoding-an-audio-or-a-video-file.

  9. rhintze

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

Leave a Reply to toby Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 Alien Pastures

Theme by Anders NorenUp ↑