How to set up VLC for web streaming (X11 only)

Abstract

VLC is a separate application which can either read a plain file or a TS network stream. Using XSwallow, it is possible to incorporate VLC video output window right into the window of a browser. With additional tricks, it is also possible to launch a VLMS (VideoLAN MiniServer) on the server-side, and have the client read a live network stream. This document, intended for expert users only, describes the ways to do it.

Installing and configuring XSwallow for plain MPEG files

XSwallow is a software which allows any X11 window to be "swallowed" (technically, just reparented, so that it has no effet on performance anyhow) into the window of a netscape-compatible browser (Navigator, Mozilla, Konqueror, Galeon, Opera...). This is indeed a trick in the X11 windowing model, and don't even expect to port this behaviour to any non-X11-based operating system, even supported by VLC (MS Windows, MacOS X, BeOS, QNX, ...).

Download it here : http://www.csn.ul.ie/~caolan/docs/XSwallow.html. Compilation is really straightforward, it basically boils down to some :

 make -f makefile.linux 

Place the resulting xswallow.so in a directory scanned by your browser for plug-ins (for instance, /usr/lib/netscape/plugins, this scan path can with some browsers be read in $NPX_PLUGIN_PATH) and xswallow.conf in the directory indicated by the environment variable $MOZILLA_HOME. If it is currently unset, set it with for instance :

 export MOZILLA_HOME=/etc 

Of course your mileage may vary. The last step is to customize xswallow.conf so that it launches VLC to handle MPEG files. Comment out all lines you don't need, and add :

video/mpeg; mpeg,mpg,vob;   vlc -I dummy -V xvideo %s; VideoLAN Client 0.2.83 (XVideo output); VideoLAN

Notes :

From now on, if you have your browser reload its plug-in list, it will display VideoLAN as application handler for video/mpeg. You should now try and see what it yields.

Tricks for live web streaming using VLMS

With a little trick, it is possible to stream a video using VLC and VLMS, and make it appear in a Web browser (without having a local copy of the file). This will only work if there is no firewall (nor masquerading) between the server and the client. It requires to have a CGI support built into the Web server.

Here is the sketch :

Configuring the Web server

In this section I will only give configuration directives for Apache. You need to add a new MIME type for TS stream in httpd.conf :
 AddType video/x-mpeg-ts .ts 

And relaunch your Web server (apachectl reload). Next, create the vlc.html page. You need two specific lines, one to load vlc.ts, the other to start the VLMS server ; for instance in PHP (adapt it for Perl, Java, or whatever) :

<img src="vlc.ts">
<?php system("/var/www/cgi-bin/stream.sh $REMOTE_ADDR mystream.mpg > /dev/null 2>&1 &"); ?>

Where stream.sh is a simple shell script :

#!/bin/sh
vlms -d $1 -a mpeg $2

VLMS starts streaming mystream.mpg to $REMOTE_ADDR (the IP address fetched by the server, this is why you cannot do it through firewalls) on port 1234. Notes :

Finally, create the vlc.ts file. It just contains the address of the server, so that VLC can bind on it (you can't retrieve that from XSwallow). For instance :

 streaming.idealx.com 

Configuring XSwallow

You need to add an entry video/x-mpeg-ts in you xswallow.conf :
 video/x-mpeg-ts; ts; video-streaming.sh %s; VideoLAN Client 0.2.83 (XVideo output); VideoLAN 

The same provisions as before apply here. The video-streaming.sh file is a simple shell script which retrieves the server's name and spawns VLC :

#!/bin/sh
SERVER=$( cat $@ )
vlc -I dummy -V xvideo ts://$SERVER

Here you go. This is quite a hack, but it will hold until the next major release of VLC.

Acknowledgements

This page has been written by Christophe Massiot for IDEALX S.A.S.
$Id: web-streaming.html,v 1.1 2001/08/22 18:47:52 massiot Exp $