Sep 242009

A few months ago I purchased a “Google Phone”: a HTC Magic running the Linux-based Android operating system. I am incredibly pleased with this device.

Today I wanted to convert some video that I recorded on a Nikon Coolpix camera into a format that would play nicely on my Android phone. The resolution needed to be scaled down for the small screen, and I knew that h264 was the best video codec. After some searching online, and a bit of experimenting, I found that this worked wonderfully:

ffmpeg -i input.avi -aspect 3:2 -s 400x300 -vcodec libx264 -b 480k -r 30 -acodec libfaac -ac 1 -ab 32k -padtop 10 -padbottom 10 -padleft 40 -padright 40 -sameq -pass 1 output.mp4

This is a two-pass process, and so this command should be repeated a second time with the last option changed to “-pass 2”.

The “pad” options are to make the geometry work. The screen on the HTC Magic has a resolution of 480×320 pixels, which is a 3:2 aspect ratio. The video I was converting had an aspect ratio of 4:3, and so it conveniently scaled to 400×300. The paddings fill the video out to the full 480×320, ensuring that the aspect ratio is right during playback.

  One Response to “Converting video files for playback on Android Google Phone”

  1. I went to do this today, and there was some problem with libx264. I found some helpful information here, and the presets from -vpre seemed to work.

    First pass:
    ffmpeg -i Singing_with_Daddy.m4v -s 480×270 -vcodec libx264 -vpre fastfirstpass -b 480k -r 25 -acodec libfaac -ac 1 -ab 96k -padtop 24 -padbottom 26 output.mp4

    Second pass:
    ffmpeg -i FILE -s 480×270 -vcodec libx264 -vpre hq -b 480k -r 25 -acodec libfaac -ac 1 -ab 96k -padtop 24 -padbottom 26 output.mp4

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>