Video broadcasting and recording with Cisco part 4. Wowza+Nginx

During these series we have installed Cisco Telepresence Content Server and Wowza Media Streaming Engine. TCS works as SIP gateway and converts SIP signalling with RTP payload to RTSP signalling with RTP for live streams. Wowza accepts RTSP and converts it to RTMP which can be used with Flash players and HLS for HTML5 (we will discuss HLS later).
Imagine that you have to provide live streaming for more than 1000 users. In that case Wowza have a solution – Wowza Origin and Wowza Edge. The idea behind it that you have one generating Wowza server and a number of retranslators (edges), which are situated closer to users. That’s great but you have to buy license for all those edges and it summs up to a big money. Maybe it’s worth investing when you have big video broadcasting events every week, but what if your weekly translations cover 700 users and such big events are held once a year. In that case there is open-source solution for retranslators: nginx web server with nginx-rtmp plugin (https://github.com/arut/nginx-rtmp-module).

1) Assume we have fresh installation of Ubuntu 14.04. Let’s install all supplementary packages.

# apt-get update
# apt-get upgrade
# apt-get install build-essential libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev git checkinstall

2) Create separate user for nginx

# useradd --no-create-home nginx

3) Download nginx and rtmp plugin sources

# mkdir /usr/build 
# cd /usr/build 
# git clone git://github.com/arut/nginx-rtmp-module.git 
# wget http://nginx.org/download/nginx-1.7.11.tar.gz

4) Unpack, configure, compile and install package. Again I’m using checkinstall to get deb packet and the ability to delete installed package with dpkg in future

# tar zxfv nginx-1.7.11.tar.gz
# cd nginx-1.7.11
# ./configure --prefix=/usr/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --user=nginx --group=nginx --with-http_stub_status_module --with-http_gzip_static_module --add-module=/usr/build/nginx-rtmp-module
# make
# checkinstall --pkgname nginx-rtmp

5) Create a script to launch nginx

# cd /etc/init.d
# vi nginx

Copy following to vi

# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/nginx/sbin:/usr/nginx/bin
DAEMON=/usr/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON || true
echo "$NAME."
;;
status)
status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0

5) Make it executable and add to autolaunch. Now you can start, stop and restart it with

# /etc/init.d/nginx start|stop|restart command
# chmod +x /etc/init.d/nginx
# update-rc.d -f nginx defaults

6) Now post following to /etc/nginx/nginx.conf and restart nginx

worker_processes  1;
error_log /var/log/nginx/error.log  debug;
events {
worker_connections 1024;
}
rtmp {
    server {
        listen 1935;
        application live-edge {
                live on;
                pull rtmp://<wowza IP adress>:1935 app=live;
       }
    }
}

http {
        server {
                listen 8080;
                location /stat {
                        rtmp_stat all;
                        rtmp_stat_stylesheet stat.xsl;
                }
                location /stat.xsl {
                        root /usr/build/nginx-rtmp-module/;
                }
               location /control {
                        rtmp_control all;
                }
        }
}

RTMP section of the config creates RTMP server that serves live-egde RTMP application. Whenever user opens browser with flash player, the player makes a connection to this nginx server and provides app name (live-edge) and stream number (1002). When nginx gets this request it connects to Wowza and query for app=live and same stream name. When second user comes it servres him chached data without creating additional connection to Wowza.  You can as many such retranslators as you want.

Additionally you can query nginx for connected users by consulting http://<server IP>:8080/stat.

Video broadcasting and recording with Cisco part 2. TCS+Wowza

Last time we created two aliases on Cisco Telepresence Content Server – 1001 for recording and 1002 for live streaming. Up to this step we are able to call these aliases (or add them to conference) to record or broadcast our call or conference.

But TCS can generate RTSP stream and it’s not an obvious task how to integrate this stream into user’s browsers. Again – usually you have 1G link on TCS server and it will allow approximately 500 connections to HD-quality streams.

We are going to use Wowza Streaming Engine to converts RTSP streams to RTMP/HLS/HDS streams that can be served to various flash/html5 players. At the same time we will use Wowza to down-rate streams to lower qualities – not all users have good Internet connection to allow HD streams.

1) Register and download Wowza Streaming Engine from http://www.wowza.com/.
2) Save license key and  WowzaStreamingEngine-4.1.1.deb.bin installation
3) I’m using Ubunty Trusty at the moment. Let’s install Java

# apt-get update
# apt-get upgrade
# apt-get install default-jre
# apt-get install default-jdk

4) Move to the folder with WowzaStreamingEngine-4.1.1.deb.bin and make it executable

# chmod +x WowzaStreamingEngine-4.1.1.deb.bin
#  ./WowzaStreamingEngine-4.1.1.deb.bin

5) During the installation you are prompted to enter license key, create admin credentials and will ask to add itself to autolaunch

6) Now Wowza is ready. Installation path is  /usr/local/WowzaStreamingEngine/.

To start service sudo service WowzaStreamingEngine start
To stop service sudo service WowzaStreamingEngine stop

7) Download WowzaStreamingEngine-Update-4.1.2.zip from  http://www.wowza.com/ and move it to /usr/local/WowzaStreamingEngine/updates/

8) Unpack update file

# apt-get install unzip
# mkdir /usr/local/WowzaStreamingEngine/updates/WowzaStreamingEngine-Update-4.1.2/
# unzip /usr/local/WowzaStreamingEngine/updates/WowzaStreamingEngine-Update-4.1.2.zip –d /usr/local/WowzaStreamingEngine/updates/WowzaStreamingEngine-Update-4.1.2/

9) Stop all Wowza services

# service WowzaStreamingEngine stop
# service WowzaStreamingEngineManager stop

10) Move to folder with update script and launch it

# /usr/local/WowzaStreamingEngine/updates/WowzaStreamingEngine-Update-4.1.2/linux
# chmod +x *.sh
# ./update.sh

11) After update go to  http://<wowzaserver_ip&gt;:8080/  and login with credentials from step 5.

12) Navigate to Applications -> Add Application -> Live (single server or origin) and enter  _defapp_

13) Navigate to Live Applications -> Live. In list below select Incoming Security and make it look like

14) Now navigate to Server -> Publishers -> Add publisher and add new publisher name and password (they will be used lated when configuring Cisco TCS)

15) Edit /usr/local/WowzaStreamingEngine/conf/live/Application.xml

16) Search for Properties and RTP sections – they should look like:

<Properties>
  <Property>
    <Name>sortPackets</Name>
    <Value>true</Value>
    <Type>Boolean</Type>
  </Property>
  <Property>
    <Name>sortBufferSize</Name>
    <Value>500</Value>
    <Type>Integer</Type>
  </Property>
 </Properties>

 <RTP>
  <Authentication>
    <PublishMethod>digest</PublishMethod>
    <PlayMethod>digest</PlayMethod>
  </Authentication>

17) Move to Cisco TCS administration web-interface. Navigate to Management -> Recording Setup -> Media server configurations -> +Add Wowza Media Server for Flash configuration

18) Set the parameters

Name: Wowza 1002
Server address:wowzaserver_ip>
Support live unicast streaming: Yes
User name/Password/Password confirm: see step 14
Use default live URL: Yes
Application directory: live
Static stream name (optional): 1002

19) Hit save. If everything is ok you’ll see:

20) Navigate to Management -> Recording Setup -> Templates -> Live and set

Media server configuration to Wowza 1002

21) Call 1002 from you video codec, navigate to Wowza administration interface Applications -> Live -> Incoming streams, choose 1002, hit Test players in upper right corner, choose appropriate player and you’ll be able to monitor your broadcasting stream.