How to stream videos using VLC +Webinfo
You want to make an internet TV show ?
You want to watch videos with other people but files are too big to upload ?
You have a decent internet connection or server with high traffic limit?
There is a way to stream videos like streaming music (internet radio).
What you need:
- VLC
- Optional: Webserver with PHP
- Access to the firewall/router if there is any
In this guide we're going to stream via HTTP. It's not the best way to stream because you can't take advantage of things like multicast to reduce traffic load but it's the only way that works for me behind a router.
So if you are behind a router and maybe also firewall like me you need to...
Step 1Forward a port to your local LAN IP. Any port works but it should be at least >1024 to avoid conflicts.
In this guide I use 5004 as port.
Open the port in your firewall if you have one running.
Step 2Get the latest VLC Version (older ones also work but VLC is known to be full of security flaws).
Once you have it running and open go to the menu: "Media" -> "Stream"
1. Choose the media you want to stream. When streaming ISOs directly check "No disc menus".
2. Click "Stream"
3. Source is prefilled by the previous dialogue so click "Next"
4.
DestinationsWhere is says "New destination" click on the dropdown and select "HTTP" and then on "Add".
Now as port use the one you opened i.e. 5004 path can be left empty but it's good to use something here so I use "/video".
Check the "Activate Transcoding" checkbox and as profile select "Video - H.264 + MP3 (TS)"
5. Click "Stream"
Now the VLC will show no video (unless you selected it) and you will notice the progress bar moving.
You are now streaming a video!
Other people can now watch the stream using a player like Windows Media Player or VLC when going to "Open Network Stream..." or "Open URL" etc.
And as url they have to put "
http://YOUR_EXTERNAL_IP:5004/video" and click Play.
Depending on your internet connection (upstream) and PC (transcoding) it will either buffer a lot or work fine.
You can play around with the transcoding options/profiles to reduce quality in case of buffers.
Step 3 - Optional and advancedSince with the method above it seems impossible (to me) to stream media information like what you are playing it would be nice to let your audience know what is currently playing some other way.
You can make a webpage for that information.
Here you need a webserver with PHP (or some other server sided scripting language, client JS can also work but that's beyond a short guide).
We take advantage of VLC functionality to have different interfaces.
In the open VLC window in the menu you go to "View" and then "Add Interface" -> "Web".
Once clicked you can go to
http://127.0.0.1:8080 to control your VLC player using a webpage! Though we don't need that.
When you have a webserver with php running you can now make a request to
http://127.0.0.1:8080/requests/status.xml to fetch the "now playing" information.
It's an XML file with a couple information. What's needed now is
<information>
<category name="meta">
....
</category>
...
</information>
Within the meta category is any meta data related to the current playing video stored.
Using PHP with SimpleXML you can do something like this to get the title information
function getNowPlaying()
{
$now_playing = 'error';
try {
$xml = new SimpleXMLElement(@file_get_contents('http://127.0.0.1:8080/requests/status.xml'));
}
catch (Exception $e)
{
return('stream not running');
}
foreach ($xml->information[0]->category as $cat) {
if($cat['name'] != 'meta') continue;
foreach ($cat->info as $inf) {
if($inf['name'] != 'title') continue;
$now_playing = $inf;
break;
}
}
return($now_playing);
}
If that doesn't work the media either has no title or your webserver is on another machine.
Let's say you have a webserver online you pay for but you want to stream using your PC at home and want to show the now playing information on your page using your webserver.
What you have to do is to allow external access to the web-interface of VLC.
To do this go to "C:\Program Files (x86)\VideoLAN\VLC\lua\http" (or wherever your VLC is installed to) and open the ".hosts" file and insert a new line somewhere where you put the external IP of your webserver so that only the webserver can access the controls in addition to the localhost.
I recommend using a playlist to stream. In the playlist you can put titles yourself, which is useful for files without media information embedded like certain video and all ISO files.
Step 4 - ExtraWhen at Step 2 point 5 you don't click "Stream" but "Next" you'll see the parameter VLC is using.
It will look like something like this
:sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ffmpeg{mux=flv},dst=:5004/video} :sout-keep
When you change it
:sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mpga,ab=128,channels=2,samplerate=44100,deinterlace}:http{mux=ffmpeg{mux=flv},dst=:5004/video} :sout-keep
Your video will stream deinterlaced as well.
You can use these parameters also to start VLC via short-cut or command line to stream directly by just replacing the ":" with "--".
Like this:
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" "PATH_TO_VIDEO_OR_PLAYLIST" --sout=#transcode{vcodec=h264,vb=800,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100,deinterlace}:http{mux=ts,dst=:5004/video} --sout-keep --loop --extraintf http
This one loops the video/playlist and also starts the web interface as well.
If you use a playlist you can also access those information via
http://127.0.0.1:8080/requests/playlist.xml (not very useful for one file but if you have a couple on there) and parse them with PHP or something else to display it online.