Use VLC to play multiple video clips on multiple computers in sync en

By Luuk1983 on Saturday 15 June 2013 17:43 - Comments (11)
Category: Software, Views: 24.602

Like most tweakers, this tweaker has way too many hardware which is not being used at the moment. So when it was time to plan my birthday party I decided to utilize the unused computers and even a 37" LCD television. The goal would be to play (music) video clips on multiple screens at the same time and preferably in sync. I found at that achieving this goal is not a walk in the park.

As observed in the title of this blog, I used VLC at the end. But before I choose VLC I tried out some other options. The first option was some kind of remote desktop, like RDP, TeamViewer or similar. But as expected, these protocols are not efficient enough for showing HD video fluently. It is also not an option to use lang cable to attach multiple monitors to one computers. So in the end, the best option would be a video stream, much like a television broadcast, which could be played on multiple computers.

The power of VLC
So when it comes to free streaming software for Windows, VLC is one of the best options as a streaming host. Most people know VLC as a video player which can play virtually anything you throw at it, but I found out that VLC can do much, MUCH more than most people know. VLC has many options for streaming and transcoding. But unfortunately the documentation is seriously lacking. Most documentation is not up to date, missing, or ambiguous. That why I'm writing this blog in English to appeal to more people who are struggling with VLC and streaming.

In this blog I will be using VLC 2.0.6. The target stream is a multicast stream, since this is the most effective way to stream on a network and also because I have a feeling that it's also the only type of stream that can be synchronized on multiple systems, but more about that later.

When using the interface of VLC, it's really easy to start a stream. In the VLC menu, an option 'stream' is available (Ctrl + S). Using the wizard it's really easy to start a stream. But here the first problem surfaces: You can only select one file as the source of the stream. If you select multiple files, only the first file will be used for the stream, if you select a playlist it does not work.

VLC by command prompt - setting up a stream
I found at that VLC has a huge array of start up parameters you can enter at the command prompt when starting VLC. You can actually do things that are not possible to do through the interface. I will explain the steps I took to create a batch file (a windows .bat file) step by step.

On a windows system, VLC is usually located in C:\Program Files\VideoLAN\VLC on 32-bit systems or C:\Program Files (x86)\VideoLAN\VLC on 64-bit systems. A .bat file to simply start VLC would look like this:

cd\program files (x86)\videolan\vlc

As I mentioned at the start of this blog, I want to play multiple video clips. So I decided that I want VLC to load all files from a certain folder in the playlist (in this case the music/clips folder on the S: disk). And now that we're at it, set the playlist to play at random and on loop, so that VLC doesn't ever stop playing:

vlc "file:///s:/music/clips/" --random --loop

In this case all files from a certain folder are loaded, but you can also use a playlist, or stream if you like.

So vlc can now be started from the bat file, clips can be loaded and played at random and loop. But now we need to determin the output, which will be a stream in multicast format. Here I set the ouput as a multicast stream at the multicast IP at port 5004:

vlc "file:///s:/music/clips/" --random --loop --sout="#rtp{dst=,port=5004,mux=ts}"

This however causes a new problem. Unless the files you play are exactly identical in bitrate, codec and all other characteristics, the clients will get disconnected after each played file. To have a continuing stream, it's neccesary to transcode all output in the same format. Transcode needs to be done real-time, so rather powerfull hardware is required. In this case I encode to a 1200kbit MPEG2 output on 1280 x 720 and 256kbit 2 channel audio:

vlc "file:///s:/music/clips/" --random --loop --sout="#transcode{vcodec=mp2v,vb=1200,scale=1,width=1280,height=720,acodec=mpga,ab=256,channels=2,samplerate=44100}:rtp{dst=,port=5004,mux=ts}"

On a Core 2 Duo Q9450, all 4 cores will use around 60% of processing power to do this real time.

Now, we also need to tell VLC that we want to treat all the individual files as a single entity in the output stream, so for the clients it should be a single stream, unaware that it's build from multiple files:

vlc "file:///s:/music/clips/" --random --loop --sout-keep --sout="#transcode{vcodec=mp2v,vb=1200,scale=1,width=1280,height=720,acodec=mpga,ab=256,channels=2,samplerate=44100}:gather:rtp{dst=,port=5004,mux=ts}"

--sout-keep makes sure the stream stays open/available after each file. I'm not sure what 'gather' exactly does, only that it's needed ;)

One thing remains, By default, it's possible that the steam will not take more than one hop on the network, meaning the stream will stop at the first router and not go further. Setting the TTL (Time To Live), makes sure that the stream will also cross routers:

vlc "file:///s:/music/clips/" --random --loop --ttl="5" --sout-keep --sout="#transcode{vcodec=mp2v,vb=1200,scale=1,width=1280,height=720,acodec=mpga,ab=256,channels=2,samplerate=44100}:gather:rtp{dst=,port=5004,mux=ts,ttl=5}"

You're now able to start a stream. Make sure your router support multicast and make sure the required port is open on the firewall.

VLC by command prompt - playing the stream.... in sync
Playing a stream in VLC player is really easy. You can open the stream through the user interface by selecting Media > Open Network Stream, and entering: rtp:// This is enough to open the stream.

As usual, this can also be done on through the command prompt:

vlc rtp://

Now if you play this stream on multiple computers (in my case three), the stream will never exactly play in sync. Network latency and even computer speed seem to make a difference. So, we need a way to make sure the computer are in sync. VLC has a option 'Network sync'. This can also be set from the user interface, but I will stick to the command prompt. Please note that the net sync feature is poorly documented and doesn't always work flawlessly.
Network sync works by making one computer the 'netsync master' to which the other computer refer to.
Let's update the startup parameters. We need two bat files: one for the net sync master and one for the netsync 'clients'. And while we're at it, also start the stream fullscreen:

For the master:

vlc rtp:// --fullscreen --control netsync --netsync-master

For the 'clients' who need to sync with the master:

vlc rtp:// --fullscreen --control netsync --netsync-master-ip <IP OF MASTER>

In my experience it's best to first start all the 'clients', THEN the master . If all goes well, the screens should all play in sync. It's possible you will see one of the screens 'hang', but this wil usually correct itself very quickly.

After some research, it's clear that playing video's in perfect sync is very hard to achieve. There are many extremely expensive software suites or hardware solutions to achieve this. So it's nothing short of a miracle that an open source program can do this. Sure it's badly documented and it doesn't work flawlessly, but it's the best you can get without paying some serious money.

I hope you enjoyed learning new things about VLC and using the command prompt. Hopefully, my party will be a success!