MythTV Protocol Library: HD on a PPC Mac mini

2007-01-15

I've been playing around with the mythproto code recently, not so much implementing protocol commands, but building applications on top of the basic ones that have already been implemented. Anybody that has taken a look at the source repository has probably seen the frontend.py module. This was not ever meant to be a usable piece of code, but more of a way for me to test new commands without having to constantly rewrite a test method.

However, I found that the frontend module has been extremely useful in playing back HD content that the official MythFrontend has problems with. For instance, when frames are dropped from the MPEG source, MythFrontend tends to lose audio sync. Usually, this isn't very noticable but it can accumulate over the course of a show and become unbearable. The official frontend also, until a recent patch, didn't support digital audio output on OS X, a major annoyance for someone like me with an external DTS decoder connected to my Mac Pro. These problems can be avoided by using VLC as a video player instead of the builtin MythFrontend one. VLC keeps the audio synced surprisingly well and it takes a lot more pushing to make it loose sync than anything else I've seen (I also tested mplayer for this purpose). VLC also supports digital audio output right out of the dmg, no configuration needed.

Over the weekend, I moved my Mac mini and one of the 20" displays into my bedroom to replace ye olde TV with something a bit more... hackable. To my dismay, I found that the PowerPC mac mini just doesn't have the CPU power needed to decode a 18 Mbps MPEG-2 stream in realtime. After a few days of thinking on the problem, I decided that I could transcode the video to a less CPU intensive format and stream it from there. I didn't want to keep two copies of everything on the backend, as that would be a waste of disk space (and causes the CPU on the myth box to spend all of it's time transcoding). Instead, I'm running mythproto's myth.frontend module on the Mac Pro, that feeds the stream into VLC with these obscure options --sout "#transcode{vcodec=mp2v, vb=1500, venc=ffmpeg, scale=0.5, acodec=mp3, ab=192, aenc=ffmpeg, threads=2 }:standard{access=udp, mux=ts, dst=10.1.2.100 }" - 2>&1 >>/tmp/mythproto.log in order to transcode the video to MPEG-2 at half the resolution and stream it to the mini. The key here is that the video is scaled to half resolution, the rest of the options are just tweaks for quality. The end result is that I fire up VLC in UDP listener mode on the mac mini and pop it into fullscreen with fairly impressive results. While I can tell the difference between the transcoded video and full resolution HD up close, it's nearly impossible to tell them apart from across the room. VLC chews up about 120% of the CPU (out of a possible 400% due to four cores) on the Mac Pro to decode and repack the video in realtime, not bad considering that it takes about 110% of the CPU just to decode and view HD locally on the Mac Pro. On the Mac mini side of things, it takes a mere 30% of it's CPU to decode and play the stream in realtime, leaving plenty of room to add more interesting functionality.

In the course of making this hack work, I started to think that it would be a good idea to write a MythTV plugin for VLC. This would offer easy setup and good integration without having to write a new video player. Expect to see more in this direction soon.

Also worth noting... I added auto commercial skip support to the frontend module shortly after I got the mac mini stream going. Without an easy way to skip around the stream, I found this to be a very useful feature. Commercial skip hasn't been tested much yet, so it may not work completely. Worst case: You end up sitting through a few commercials for poorly targeted products (Who puts tampon commercials on Spike's TV for men?).

Next post - MythTV protocol library updates