Sunday, January 4, 2009

Encoding videos for the G1

Soon after Android's debut, initial reviews were complaining about the G1's inability to play videos. At the time I felt it was a trifling matter. Since YouTube already works on the G1, a more general video player ought to require only minor tinkering. And why is it a big deal anyway? Are people in a rush to experience Hollywood blockbusters on a tiny screen and tinny speakers?

Sure enough, video playing apps appeared quickly on Android Market. I found at least three in my last search. As for their utility: now that I've played with them, I understand why some see a video player as a must-have, and not merely yet another vehicle for demonstrating the G1's capabilities.

While breathtaking cinematography, award-winning soundtracks and state-of-the-art special effects translate poorly to a handheld device, movies that derive their strength chiefly from factors such as a witty dialogue lose little. Informational clips are another good use case. And even with scenes that only work well with a big screen: if they're my favourite scenes of all time, it's still comforting to have them at my fingertips, even if they are greatly reduced.

Which leaves the problem of converting videos to a G1-friendly format. I knew almost nothing about the black art of video encoding, but after hours of false starts and trawling the net for help, I still know almost nothing. However, I picked up enough to get started.

An unofficial FAQ states the G1 currently supports the H.264, 3GP and MPEG4 video codecs. I skimmed a few Wikipedia entries to decode this alphanumeric soup, and my interpretation is that this really means the G1 recognizes .MP4 and .3GP files (which are container formats and not video encoding methods) and understands the H.263, MPEG-4 ASP ("roughly similar" to H.263) and H.264 (aka MPEG-4 AVC) video compression standards. [Trivia: ASP expands to the somewhat oxymoronic "Advanced Simple Profile".]

The G1 only speaks the BP (Baseline Profile) dialect of H.264; videos that use more advanced features of H.264 play incorrectly, or not at all. [At last this post makes sense to me!]

On Ubuntu, the easiest way to encode videos was to use avidemux (sudo apt-get install avidemux). For audio, I only tested the AAC codec (usually at 96kbps), but several others should also work. For video, selecting MPEG-4 ASP produced videos that seemed to tax the CPU heavily on playback, often to the point of unwatchability. Perhaps this could be remedied by lowering the number of frames per second via an appropriate filter.

In any case, I prefer selecting the MPEG-4 AVC video codec and dumbing it down for the G1 by disabling the appropriate H.264 options: I changed the Max Consecutive B-Frames to 0, unchecked all options related to B-frames, and disabled CABAC along with the 8x8 Transform and 8x8 Intra search options. As before, I added the MPlayer variant of the resize filter: the G1 has a 480x320 screen in landscape mode. At 384kbps, this produced videos that played smoothly though higher bit rates should be feasible.

Now that I appreciate video more, I eagerly await the "Cupcake" Android update which is rumored to have video recording. I also hope the next generation of hardware will have video out and enough power to handle any popular codec.

2 comments:

Doug said...

Check out Act 1 Video Player for optimizing encoding for the G1 using mencoder command line.

Virtual Studio Pvt Ltd said...

Virtual Studio is the pioneer web cast streaming service provider company in India based out of New Delhi, having web cast for various corporates and multinationals, a number of events of international importance. Starting from being the official webcasters of the ‘Pop John Pall’s visit to India in 1999; they have covered it all from Bill Clinton to Bill Gates. International Events such as Executive Assembly of World Energy Council to Multi Location simulcast of Golden Jublee Celebration of Cardio Thoracic Surgeons. Live Series of Technology Programs for MSN to whole of Cricket series including ICC World Cup 2003 to 2007; T20; Gavaskar Border Series 2008(India vs Australia); ICL; IPL 2009. Dreamspark launch by Bill Gates at IIT Delhi. Live streaming of 10 Channels of World Space satellite radio. And scores of live and on demand streaming web casts in between. For all streaming needs including live streaming services from India, the leading live streaming services provider is also providing on demand streaming services. In fact Virtual Studio is a preferred web cast streaming media company with its head office based in Delhi.