davidrickard.net

Random stuff, randomly updated.

Don’t touch that dial!

VideoLan (or VLC as it is otherwise known) is a great piece of software. It’s capable of playing a plethora of video and audio file types. It’s also capable of converting files, streaming files over the network, and viewing live TV via any TV cards you might have.

Because of the way it works, it’s possible to take any input, and spit it out in any way pretty much. Some time ago I’d seen a discussion on a mailing list about using VLC and a digital TV card to broadcast live TV over the network (using multicast). I’d had a quick play, but never got it working. A discussion popped up on the Multiplay forums, so I thought I’d try and get it working again. Last night I was successful, so I thought I’d blog it up in case it’s useful for others. VLC is documented, but the documentation is a bit hit and miss in places – always the problem for many Open Source projects.

Read more after the jump.

Background

Digital TV, using either satellite (DVB-S) or terrestrial (DVB-T) is fundamentally the same – MPEG2 Transport Streams, which are multiplexed into one stream, then broadcast on a single frequency. The tuner will tune to the frequency, then pick the stream it wants, and play it on screen.

The idea behind what we’re doing here is to take that multiplex, and pick out the streams we want, then just multicast them as is onto the network. Using the SAP protocol, it’s possible to announce them in a nice neat way so clients can pick them up easily.

Because it’s already MPEG2, no re-encoding is really needed. I suppose you could do that, but I’ve not tried. This method uses hardly any CPU time, as it’s just pulling data in, patting it about a bit, and throwing it out the other side. In the original mailing list postings I read, the author was using some old Pentium 4 PCs with hardly any RAM. They were capable of tuning multiple channels with ease.

One caveat of this is that the tuner can only lock onto one frequency, so one multiplex is all you can play with; on Terrestrial (i.e. Freeview), the BBC multiplex contains all the BBC channels. If you wanted to multicast BBC and ITV channels for example, you’d need to add a second tuner and tune to the ITV multiplex.

In my investigations, I had the following setup:

Server Client PC
Windows 7
Hauppauge WinTV HVR-1300 Terrestrial Digital card
VLC 1.0.5
Mac OSX 10.6
VLC 1.0.5

Both are connected over a Gigabit network. However, the video streams are quite small (5-6Mb/s). Even 10Mb network could cope with that, although not many concurrently!

The server end

First of all, here’s the full command to kick start VLC on the Server.

vlc dvb-t://frequency=578000000 :adapter=0:dvb-bandwidth=8 --programs=4171,4235
--sout #duplicate{dst=std{access=udp,mux=ts,dst=239.255.255.239,sap,name="BBC One",
group="BBC"},select="program=4171",dst=std{access=udp,mux=ts,dst=239.255.255.238,
sap,name="BBC Two",group="BBC"},select="program=4235"

That’s all on one line, I had to break it up a bit!

So an explanation of it. Basically it runs VLC, tunes the frequency, using a selected adapter and channel bandwidth. It then selects the two programs I want (BBC One and Two), then outputs them via UDP on two different multicast addresses, using SAP to announce it.

First of all, I’d recommend running VLC up manually. Go to Media >Open Capture Device. Change the capture mode to DVB Directshow. Select the video format you’re using (I’m using DVB-T). Then dial in the frequency of the multiplex you want. Select 8Mhz for the bandwidth. You can find out the multiplex frequency using UKfree.tv.

Opening the TV card

Click Play, and it should open.

Testing the video works

If it doesn’t you might need to select your video adapter explicitly. I have two in my PC. The DVB-T card is adapter 0, whilst my DVB-S card is adapter 1. Click Media > Open Capture Device again , then tick Show more options and enter “:adapter=0” into the options box. In the previous screenshot I have highlighted this. Change the number until it works.

Once you are able to see the video, go to Tools > Messages. Change the Verbosity to 2. Stop and start VLC and watch the log fill up. There’s too much to try and work with it in the window, so click Save as…. Open the file you have saved, and look for a section similar to the following:

ts debug: new SDT ts_id=4107 version=3 current_next=1 network_id=9018
ts debug:   * service id=4171 eit schedule=1 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=BBC ONE
main debug: EsOutProgramMeta: number=4171
ts debug:   * service id=4235 eit schedule=1 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=BBC TWO
main debug: EsOutProgramMeta: number=4235
ts debug:   * service id=4415 eit schedule=1 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=BBC NEWS
main debug: EsOutProgramMeta: number=4415
ts debug:   * service id=4479 eit schedule=0 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=BBC Red Button
main debug: EsOutProgramMeta: number=4479
ts debug:   * service id=4671 eit schedule=1 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=CBBC Channel
main debug: EsOutProgramMeta: number=4671
ts debug:   * service id=4351 eit schedule=1 present=1 running=4 free_ca=0
ts debug:     - type=1 provider=BBC name=BBC THREE
main debug: EsOutProgramMeta: number=4351

Notice all the Service IDs. As you can probably tell, each of these represents a TV channel within the multiplex. You need to note down the ones you want to multicast. In this case I want BBC One (4171) and BBC Two (4235).

The next part of the command selects those programs and outputs them:

--programs=4171,4235 --sout

The next part is to make up the multicast. As the video is already in MPEG2 we don’t need to go re-encoding it, so it’s simply a case of spitting it out.

I’ll be honest, I’m not sure what this next section does – I think it is basically saying take the input and duplicate it to output elsewhere (i.e. other than on screen).

#duplicate{

We are going to broadcast on a multicast address (anything in the range 224.0.0.0 to 239.255.255.255). You need to choose your addresses. On a large network with multicast enabled, these could be in use, so it’s worth checking first. If you know you don’t have any multicast I think it’s fairly safe to pick a random address. I chose 239.255.255.255.239 and went down from there!

This next line is where we select UDP, make it a Transport Stream, select the target IP, and advertise it with SAP. The channel name, and group name are set here too:

dst=std{access=udp,mux=ts,dst=239.255.255.239,sap, \
name="BBC One",group="BBC"},select="program=4171",

Repeat for BBC Two. Use a different multicast address though!

dst=std{access=udp,mux=ts,dst=239.255.255.238,sap, \
name="BBC Two",group="BBC"},select="program=4235"

Now we have a full command, it’s a case of running it. I used a command prompt and ran VLC from there, but you could of course put it into a shortcut, batch file, registry run key, or whatever.

Multicasting Once it’s running, a very simple, hacky way of checking it is working is to look at your network switch. If it’s flashing away merrily on all ports, then it’s doing something!

The clients

Run VLC on another PC, Go into Preferences > Playlist > Services Discovery and tick SAP. You might need to re-start VLC. Go to the playlists, and you should see a group with the name you made, and your channels. Click one, it plays!

Screen shot 2010-06-18 at 23.14.41 As you can see, I’m doing this on my Mac, so it’s truly cross platform!

I did find in testing that it caused an effective DoS on my Wireless. I’m guessing the multicast was too fast for the slowest wireless device associated to the AP, and just wiped the lot out or something. Wired carried on working fine though. Something to bear in mind anyway!

I’m sure it’s possible to refine this a little more. The original version of this I saw had VLC daemonizing itself, which I’m not entirely sure is possible in Windows. Still, it’s a great way to get video served up over the network.

Oh, and remember, you still need a TV licence!

One Response to “Don’t touch that dial!”

  • [...] speed. I was going to test more though. I refined the whole thing into a somewhat more coherent posting on my blog. __________________ This post brought to you by: LOVEFiLM – DigiGuide TV [...]