Convert Video for Viewing on the HTC G1/Magic Android phone.

The Google Android OS is the best mobile Operating System I’ve used, and the HTC G1/Magic phones are really excellent machines. They become even more excellent when you can take films and TV shows with you on your morning/evening commute. The train ride will never be the same again.
I’ve had to look up quite a bit to find the right and easy way to convert videos for the phone, and ended up collecting all the information I found into a neat and handy Bash script.  I assume this could work for any other phone using the 3GPP / H263 video decoder/codec/type, but I haven’t tested it (you’re welcome to try it out and let me know).

Please remember that I’ve done this for myself mainly, so it assumes you’re using a Debian based distro for the setup portion of the script. If you don’t have apt, you’ll have to do the leg work and get all the pre-equisites sorted out yourself.

The script has two main parts: Setup and Conversion. The conversion is pretty straight forward. To convert 3 files you simple do:

./androvideo videofile1 videofile2 videofile3

However, converting to the phone requires the h263 decode/encode libs and ffmpeg to be compiled against them. When you perform the Setup portion (via ./androvideo -s) the script will attempt to do all for you. Attempt is the key word here. NO promises it will work for you (it does for me, but I’m special :o ).

During setup, what is supposed to happen is:

  • Get all build dependencies for ffmpeg via apt.
  • Get a few libs ffmpeg will need, subversion, checkinstall and build-essentials
  • Downloads the amr shared libs from and attempt to compile/install
  • Get latest ffmpeg from svn and attempts to compile/install with the amr libs included
  • Get rid of temp dir, all downloaded files and compiled pre-install stuff

Download the script (right click and Save Link As)
You’ll have to “chmod +x androvideo” after you download it to make it executable

I could not have done this without the very good help from these resources:
http://www.linuxquestions.org/questions/linux-mobile-81/androidg1-and-video-converted-via-ffmpeg-h263-687163/
http://po-ru.com/diary/up-to-date-ffmpeg-on-ubuntu-hardy/
http://tldp.org/LDP/abs/html/
http://www.penguin.cz/~utx/amr


15 Responses to “Convert Video for Viewing on the HTC G1/Magic Android phone.”

  • Daniel Hedblom Says:

    Thanks, this app is awesome! I was just about to compile ffmpeg myself and muck about when i struck this handy script.

    Thank you very much!

  • Daniel Says:

    Hi,

    neat script, thanks for that. You should add “checkinstall” to your list of packages apt should get, since it’s not part of build-essentials and might not be installed everywhere (it wasn’t for me).
    Other than that, good stuff. :)

  • harel Says:

    Hi Daniel,
    checkinstall is in the apt list already… I wonder why it didn’t work for you…

  • Jason Parekh Says:

    For Ubuntu Jaunty users, the apt-get install fails because liblame-dev is now called libmp3lame-dev

  • harel Says:

    I’ve updated the apt-get install and replaced liblame-dev with libmp3lame-dev. So anyone with Ubuntu distro prior to Jaunty should replace libmp3lame-dev with liblame-dev.
    Thanks Jason

  • magic Says:

    If you run into trubble and get a ‘unkown encoder mpeg4′ error, install the unstripped libraries of ffmpeg.

    Cheers

  • Truls Says:

    The latest ffmpeg in subversion has removed non-free amr support, so the script won’t compile. Maybe get a specific revision in the setup-part?

  • harel Says:

    I still need to test this, but the AMR support was removed on July 7th, so in theory if you add this:

    -r {2009-07-06}

    to the end of this line:

    svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg

    so that it becomes:

    svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg -r {2009-07-06}

    you should be getting the trunk the day before that support was removed. If anyone tests it, please let me know if it works and I’ll update the script.

    Thanks!

  • Erik Says:

    Just downloaded and setup the script today using jaunty and it worked fine without the need to add the -r tag to the svn checkout

  • Exceed & Frugal » Encodage video pour l’HTC Dream (G1) avec ffmpeg Says:

    [...] suis tombé sur le script androvideo qui, quelques modifs plus tard, est pour moi un parfait compromis poids/fluidité/vitesse [...]

  • jacob Says:

    Great script. Installed it on two machines running jaunty. Would be great to have option to add a subtitle file to be hardcoded.

  • Exceed et Frugal » Blog Archive » Encodage video pour l’HTC Dream (G1) avec ffmpeg Says:

    [...] suis tombé sur le script androvideo qui, quelques modifs plus tard, est pour moi un parfait compromis poids/fluidité/vitesse [...]

  • gc Says:

    amr is not mandatory; aac works just fine – just use the ffmpeg commandline with stock ffmpeg, it works properly

    ffmpeg -i -s “480×320″ -vcodec mpeg4 -b 512000 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2

    (default video bitrate produces too much noise for me, hence -b 512k)

  • gc Says:

    amr is not mandatory; aac works just fine – just use the ffmpeg commandline with stock ffmpeg, it works properly

    ffmpeg -i <sourcefile> -s “480×320″ -vcodec mpeg4 -b 512000 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 <outputfile>

    (default video bitrate produces too much noise for me, hence -b 512k)

  • Doycho Says:

    You should change the convert line to

    convert “$FILE”

    instead of

    convert $FILE

    to make sure filenames with spaces will be passed correctly since they are not without the quotes.

Leave a Reply