Posted by: patdavila | March 10, 2010

Re-Encoding MythTV recordings for viewing on your Android phone

So what if you’d like to watch a recording from you MythTV system on your Android phone? Android phones have an onboard video decoder that will let them play h264 encoded videos (youtube) easily in whatever resolution the phone’s screen will allow. Basically you’ll need to re-encode the MythTV recordings into a suitable format The most direct option is to use ffmpeg to convert the videos for use on your phone. ffmpeg literally is the swiss army knife of multimedia in the F/OSS world. You can basically convert any video/audio file into any other format using a multitude of codecs. ffmpeg is a commandline tool that has a lot of flags that a noobie might be a little intimidated by. Here’s my ffmpeg command to re-encode videos for my Nexus One:

ffmpeg -i inputfile.mpg -aspect 16:9 -s 800x480 -vcodec libx264 -b 480k -r 13 -acodec libfaac -ab 128k -sameq -pass 1 -f rawvideo -an -y /dev/null && ffmpeg -i inputfile.mpg -aspect 16:9 -s 800x480 -vcodec libx264 -b 480k -r 13 -acodec libfaac -ab 128k -ac 2 -sameq -pass 2 outputfile.mp4

The above command will do a 2 pass encoding of the video file using the x264 encoder for video and faac for the audio. While more time consuming 2 pass encoding improves the quality of the video greatly. The videos tend to come out much smoother with little or no artifacts. I tested the above command with both hi-definition and standard definition recordings that were captured with my PVR-1212 and my HDHomerun capture devices. A one hour HD recording that was roughly 4.1 gig in size was re-encoded to a 332mb file that plays perfectly on my Nexus One in 800×480 resolution. I tried bumping up the video bitrate and frames per second rates. As a result the files were slightly larger and improvement in video quality was negligible. I also tested playing back my videos on a co-worker’s Verizon Droid phone and they all played back without issue. It should be easy to bump down the resolution to 320×480 and have the videos work on lower powered Android phones (G1, Mytouch3G, Hero, Eris, Backflip). I forwarded my settings to John Baab, the developer of MythExport. Hopefully we’ll soon have a default Android preset that will let you re-encode your MythTV recordings right from the menus in Mythbuntu. Good times.

Advertisements

Responses

  1. I really enjoyed this article. It seems finding people like you and I interested in going through the effort to convert videos to the phone (and are actually concerned about the quality) are few and far between. I will say, however, that while I have used a very similar script in the past, my efforts are somewhat diminished by the creation of tools like Handbrake and HTC’s HD converter, both of which are extremely good at creating the same quality output as a straight FFmpeg script, and in the case of Handbrake – even has a Queue so I can assign a list of videos, go to bed, and wake up with a whole new cache of videos on my Nexus One. Thanks again for writing such an engaging piece!

  2. Thanks! I’d been strugling to get h264 encoding to work for my new HTC Desire, and this command line work just great! many thanks 😀

  3. Thanks so much for posting this, I was struggling with ffmpeg flags for this. I have taken the liberty of changing your command slightly to handle a later version of ffmpeg. I have also removed the forced aspect ratio as the Desire allows you to scale on the device itself.

    ffmpeg -i [inputfile] -vcodec h264 -b 480k -r 13 -acodec aac -ab 128k -sameq -pass 1 -f rawvideo -an -y /dev/null && ffmpeg -i [inputfile] -vcodec h264 -b 480k -r 13 -acodec aac -ab 128k -ac 2 -sameq -pass 2 outputfile.mp4


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: