From the Canyon Edge -- :-Dustin

Saturday, January 16, 2010

Streaming Live, Down-sampled Audio from MythTV over SSH

I'm hanging out here in Wellington, New Zealand this weekend ahead of

Unfortunately, I'm missing the New Orleans Saints vs. Arizona Cardinals NFL playoff game. I'm not a huge NFL fan, but having grown up in Louisiana, I am a Saints fan. And they have had a pretty incredible season.

I scoured the Internet trying to find a live stream, but for various reasons, I couldn't get any of them to work. My mom has a Slingbox setup, and I have gotten that to work under Wine, but I try avoid it whenever possible.

Hence, I hacked this up, which allows me to stream audio over SSH from my MythTV backend at home. I thought I'd document it, in case it's useful to anyone else. Or more likely, to myself some time in the future.

First, I used MythWeb to record the program. While normally I would record this from my HD tuner, for this usage, I want the low-def version, as my bandwidth here in NZ leaves a bit to be desired.

Next, I located the actual path to the file actively being recorded. It was the most recently touched file in my recordings directory. I found it like this:
ls -t /var/lib/mythtv/recordings/*mpg | head -n1 
Now I just want to extract the audio of this mpg. And my bandwidth is fairly constrained, so I'm going to downsample it from 44KHz to 11KHz too, using ffmpeg:
tail -f/var/lib/mythtv/recordings/1002_20100116163100.mpg \
| ffmpeg -i - -ar 11025 -f wav /tmp/out.wav
Input #0, mpeg, from 'pipe:':
Duration: N/A, start: 3069.045267, bitrate: 6384 kb/s
Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 480x480 [PAR 4:3 DAR 4:3], 6
000 kb/s, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16, 384 kb/s
Output #0, wav, to 'out.wav':
Stream #0.0: Audio: pcm_s16le, 11025 Hz, stereo, s16, 352 kb/s
Stream mapping:
Stream #0.1 -> #0.0
size= 55680kB time=1293.60 bitrate= 352.6kbits/s

Here, I can see the new bitrate is ~350kb/s -> 44KB/s, which is about what I'm getting here in the hotel. So the quality will be a bit lower (more like AM radio), but it shouldn't skip, or pause to buffer.

Now, I just need to get a stream that I can pipe directly into my player. I used sshfs to mount the remote output directory locally
mkdir /tmp/mnt
sshfs /tmp/mnt

Finally, I just need to pipe this output to my player, vlc, into its standard in.
cat /tmp/mnt/out.wav | vlc -

And there we have it! Working like a champ. Streaming down-sampled audio from my MythTV back home over SSH, some 15,000 miles away. Who dat!