Streaming MythTV Recordings Over the Internet

Article courtesy of Garry Parker at parker1.co.uk.

Introduction

My MythTV system records DVB programmes into very large MPEG2 files. These can be streamed around the house over a wireless-g connection without any problems. The bast way to do this is to install a MythTV frontend on a laptop. However, what if I wanted to view them on a PDA or over the Internet?

VideoLAN

The VideoLAN Client (VLC) is the answer to all your video streaming needs. It can do all of the above and more, even transcoding the MPEG2 files down to MPEG1 in real time and transmitting them over a HTTP connection to anywhere in the world. However, there is a small catch - none of this can be done with the version which is available under Ubuntu Breezy. You might find some sites which tell you to compile from source, but there is a much easier way...

 

Installing a VideoLAN Nightly Build on Ubuntu

The nice chaps at VideoLAN have kindly provided us with Ubuntu packages of their most recent software. By installing one of these, you get the latest VLC with none of the headaches. Instructions are available on the VideoLAN Nightlies website, but I'll summarise here:

Add the following line to the end of your /etc/apt/sources.list:

deb http ://nightlies.videolan.org/build/dapper-i386 /

Download the key file for the repository (instructions for verifying the key are on the VideoLAN Nightlies website):

wget -O /dev/stdout http ://nightlies.videolan.org/key|apt-key add -

Install the package:

apt-get update
apt-get install vlc

Client Software

The best way to view the stream is to install VLC on your client machine. There are packages for Windows, Mac, PocketPC, BeOs, etc. available here.

Accessing MythTV Recordings

By default, MythTV recordings are saved into /var/lib/mythtv. However, they're created with cryptic names such as 1009_20051031153000_20051031161500.nuv. A great way to access these files is with a script called mythlink.sh. This comes as part of the MythTV source code and creates a symbolic link to each file with a readable name.

Streaming DVB Recordings Over a LAN

Now for the fun bit. To stream an MPEG2 file in full quality, run mythlink.sh to generate a links to your recorded files. Then kick off a stream using:

vlc 03041759_The_Simpsons.nuv --sout '#std{access=http,mux=ts,url=:8081}'

To view the stream on your client machine, run the following command. Don't forget to replace the name loki with the hostname of your server.

vlc http ://loki:8081

Streaming Over the Internet

In this example, we'll be streaming over TCP port 8081. You can specify any port you wish, but remember that whichever port you choose must be opened on your firewall.

ADSL uplink speeds are pretty awful, so to stream over the Internet we'll need to shrink the MPEG2 file as small as possible. We could do this prior to streaming using a package such as ffmpeg. However, a much better solution is to get VLC to transcode the stream in real time. There are lots of parameters to play with, but the following works for me. It transcodes the stream into a tiny MPEG1 format, 0.25% of the original size. Not particularly watchable, but the principle is there! Run the following on the server:

SSH to your server and run the following:

vlc 03041759_The_Simpsons.nuv \

--sout '#transcode{vcodec=mp1v,vb=64,scale=0.25,acodec=mpga,ab=64}:

std{access=http,mux=ts,url=:8081}'

Run the client on the remote machine as before:

vlc http ://loki:8081

Controlling the Stream

So, you can now stream over the internet, but is there an easier way to choose which videos to watch? VLC comes with a number of interfaces which allow you to choose and control the streams. One of the best ways is the HTTP interface. VLC has a small web server built in, which you can control remotely using any browser. The following command starts a VLC server with a HTTP interface. Any files chosen from the browser will be transcoded and streamed as usual:

vlc -I http --http-host :8080 \

--sout '#transcode{vcodec=mp1v,vb=64,scale=0.25,acodec=mpga,ab=64}:

std{access=http,mux=ts,url=:8081}'

On the client machine, point your browser to http://loki:8080. You should see the VLC control screen. From here, you can access your server's filesystem and choose which videos or music to stream.

Then, simply connect to the stream using VLC as above.

MythStreamTV

The above method of using VLC for streaming and controlling it using the http interface is the underlying mechanism for MythStreamTV. This is an addon for MythWeb. However, it relies on very specific codecs which the standard pre-compiled versions of VLC don't support. Also, using VLC directly can be more flexible.

Category: