20120106

VLC Multicast Streaming Server in Linux


Multicast streaming allows multiple clients to receive the same video but doesn’t place a heavy load on your network. And VLC is a perfect choice as a streaming server as the clients are available in multiple OS and tablets.
Below are the steps to create a multicast streaming server in Linux using VLC.

1. Download and install vlc-nox

VLC-nox is the GUI-less version of VLC. We don’t need  GUI or X to create a VLC streaming server.
The VLC GUI is only needed at the client end which means a PC.

2. Create VLC user and start streaming

VLC should not be run by root but a normal user.
Just create a user and login as that user and then issue the following command.
cvlc myvideo.mpg –sout udp://239.0.0.5 –ttl 5 -R
where
  • 239.0.0.5 is a multicast IP
  • ttl is the number of router the packets will cross
  • R is repeated streaming.
cvlc is the command line version of vlc.

3. Create route for multicast IP

The client PC will still not receive the VLC stream unless the route is set for the multicast ip at the Linux server.
Below is the command to set the route
route add -net 239.0.0.0/8 dev eth0
where eth0 is the interface which is communicating with the client PC.

4. Create a daemon to automate the task

Below an example using Ubuntu 10.04. This daemon file should be placed in /etc/init.d/.
PID=`pidof -o %PPID /usr/bin/cvlc`
case "$1" in
  start)
    log_daemon_msg "Starting IPTV server" "iptv"
    su -l user -c "cvlc /home/me/video/myvideo.mpg --sout udp://239.0.0.1 --ttl 5 -R &" >
    /dev/null 2>&1
    if [ $? -gt 0 ]; then
      log_end_msg 1
    else
      route add -net 239.0.0.0/8 dev eth0
      log_end_msg 0
    fi
    ;;
  stop)
    log_daemon_msg "Stopping IPTV server" "iptv"
    killall vlc > /dev/null 2>&1
    if [ $? -gt 0 ]; then
      log_end_msg 1
    else
      route delete -net 239.0.0.0/8 dev eth0
      log_end_msg 0
    fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0
where user is the user you have just created for VLC.

No comments:

Post a Comment