How to transcode any video format to h264 (android-playable and/or G1) format.

The G1 has a chip in it that handles h264 encoded video (the same video codec used for YouTube videos), though format and scaling when transcoding video from other formats was a problem for me. With a lot of research and tweaking, the commands below seem to work very well for transcoding any video source (mpeg, avi, vob, etc) to an h264 video that the G1 can play natively. Note that the native resolution of the G1 screen is 480×320. Also one should avoid transcoding bitrates over 700kb/s.

For videos recorded off TV this command works well and keeps the video scaled properly:

mencoder input_file -o output_file.mp4 -of lavf -lavfopts format=mp4 -ss 1 -vf pp=ci,scale=432:324,crop=432:320,harddup -ovc x264 -x264encopts crf=30.0:nocabac:level_idc=30:global_header:threads=2 -ofps 30000/1001 -oac faac -faacopts mpeg=4:object=2:br=128:raw -channels 2 -srate 44100 -af volnorm

This isn’t an elaborate HowTo, otherwise I might break down each command switch. Check the man pages on mencoder for details on each of the switches. This does work, however.

For videos ripped from DVDs you own, (generally 16:9 ratio), this command works very well (really only the scale of the video has changed):

mencoder input_file -o output_file.mp4 -of lavf -lavfopts format=mp4 -ss 1 -vf pp=ci,scale=480:270,expand=480:272,harddup -ovc x264 -x264encopts crf=30.0:nocabac:level_idc=30:global_header:threads=2 -ofps 30000/1001 -oac faac -faacopts mpeg=4:object=2:br=128:raw -channels 2 -srate 44100 -af volnorm

This will keep the letterbox scale without stretching the video. You can play with the scale= ratios but the numbers in the above commands work pretty well. A 90 minute video ends up transcoded to about 210-220megs, which fit pretty well on today’s micro SD’s (my G1 has an 8gig micro SD). Though I wouldn’t want to watch too many movies on such a small screen (nevermind the battery life issues).

In the case where you may have ripped the entire DVD contents to a hard disk and want to transcode from a hard disk rip to h264, replace the input_file in the above command with the following:

-dvd-device /home/john/rips/GROUNDHOG_DAY/VIDEO_TS dvd://x

Where you replace your path to the rip instead of /home/john/… and where dvd://x is the DVD title (the primary movie is usually 1, so dvd://1). This will transcode the entire move of a ripped DVD to h264. You can also do this directly off a dvd simply by inserting the dvd and in place of input_file in the above command, simply type: dvd://1.