UPnP ATSC Live Video Streaming

2009-04-30 16:15

This article will guide you through the process of setting up live video
streaming from a DVB (ATSC) capture card in Linux to a DLNA UPnP Media Renderer
that supports MPEG-2 Transport Streams (such as a PS3).

What you need

Mediatomb is a DLNA/UPnP media server for Linux. You'll want to set up
mediatomb to play regular files to your MediaRenderer before attempting the
configuration in this guide. It helps to know how the javascript import
and transcoding configuration in Mediatomb works, but this guide should be
adequate as long as you don't need to do anything fancy.

This is the tool that directly talks to your DVB capture card and streams
the video. This would be all that you need if your MediaRenderer
understands how to listen to a UDP stream. The can't do this (or I
couldn't figure out how to do this) so we need one more tool...

You also need to add a map from a file extension to a mimetype, I used ".live"
-> "video/x-dvb-stream", but you could use whatever you like, the mimetype
doesn't escape mediatomb, it's just used so we can tell mediatomb to
"transcode" the files into something else. Add the following to the
"<extension-mimetype>" tag:

<mapfrom="live"to="video/x-dvb-stream"/>

Finally, you need to add a transcoding profile for the "video/x-dvb-stream"
mimetype to transcode it into a "video/mpeg" stream. The "<transcoding>"
tag should look something like the following:

Don't worry about the "dvbstream-live" script just yet, we need to get
DVBStreamer set up first.

The final piece to the puzzle is the "import.js" script. This is where having
some knowledge of javascript and what you want to do helps quite a bit. You
should copy the default import.js script from wherever it's installed, and then
add the following code:

You also need to add the following to the top of the "addVideo" function:

if(videoIsLiveChannel(obj)){return;}

This tells the import script that if the file to be imported is a ".live" file,
we want to add it to the "video/television" section of the UPnP media library,
sans ".live" ending. Strictly speaking, adding this to the import script is
not necessary, but it makes the listings look a bit nicer.

Setting up DVBStreamer

DVBStreamer is a simple tool that reads from a DVB capture card and can stream
(and filter) the broadcast to a "udp://" url. To get DVBStreamer up and
running you will need to already have a "channels.conf" file, generated by a
program like "dvbscan". Then simply run the "setupdvbstreamer" command with
the appropriate options to get dvbstreamer working.

Use the DVBStreamer Wiki to look up how to do some basic tests, stream some
video to a file, or use mplayer to watch a UDP stream; essentially, you want to
verify that DVBStreamer is working correctly and doing what you expect.

To stream using the scripts below you need to run DVBStreamer as a daemon and
set to stream to "udp://localhost:12346". Create a file "dvbstreamer.startup"
with a single line:

System Message: ERROR/3 (<string>, line 145)

Cannot find pygments lexer for language "none"

.. sourcecode:: none
setmrl udp://localhost:12346

Start DVBStreamer like this:

dvbstreamer -f dvbstreamer.startup -d

Now all you need to do is get the scripts to do the "transcoding" and create
some ".live" files for your television channels.

The "transcoding" script(s)

There are two scripts that are used by the streaming system, one changes the
channel in DVBStreamer so the correct video is streamed, the other pushes the
stream from the UDP stream to a file (FIFO) which mediatomb provides as an
argument.

Here's the first, the channel changing script. It requires python >=2.5 (and
<3.0). It expects the path to a ".live" file as it's first (and only)
argument, and connects to the DVBStreamer instance (using the default
authentication credentials) to select the DVBStreamer service corresponding to
the name of the file. e.g. "/home/media/21-1 WXXI-HD.live" would select the
"21-1 WXXI-HD" DVBStreamer service.