Live Streaming with RTMP protocol
RTMP (Realtime Messaging Protocol) is a popular protocol to transmit the video at realtime over the internet. RTMP works by taking the large video and chunk them into smaller packets. One of the reason it is widely popular is it has the capability to transmit the video and also offers to persist the data in the server permanently for later use.
Create the RTMP server to transmit the real time video
In this tutorial, i am creating simple RTMP server using nginx, OBS as a broadcaster and VLC player on client side to play the realtime.
Setting up Nginx
If your are using the ubuntu OS, you need to install the nginx. To setup the nginx
sudo apt-get update
sudo apt install nginx
Once nginx installed successfully, need to install the RTMP module
sudo apt install libnginx-mod-rtmp
After successful installation of RTMP, now its time to configure the nginx conf to allow the RTMP protocol. open the nginx conf file in editor mode
sudo nano /etc/nginx/nginx.conf
Once conf file open add the following directives in the conf file
rtmp {
server {
listen 1935;
chunk_size 4096;
allow publish 127.0.0.1;
allow publish 2.49.64.105;
deny publish all;
application live {
live on;
record off;
}
}
}
chunk size is the size of the packet transferred. Allow publish will whitelist the IP that is allowed to connect with the RTMP server. Deny publish all make sure other IP are not allowed to connect. Record off will make sure the video stream will not be stored in the server. 1935 is the standard protocol that RTMP use to transmit the video.
Once nginx conf is edited, it is required to restart the nginx service. To restart the nginx service execute the following command.
sudo service restart nginx
sudo ufw allow 1935
Now the RTMP server is setup and ready to accept the live stream on the following link http://<ip>/live. Now the another step is to setup the broadcaster. FFMPEG is largely popular open source that is used for transcoding and streaming the local video. Here i am using the OBS which is widely popular, open source and very powerful desktop application for the broadcasting. Install the OBS application from the OBS site and you are all set ready to broadcast the live stream.
Install the OBS, once installed setup the stream connection.
open the OBS applicaton, click on settings on the right bottom menu pannel.

Service: The RTMP server link, in our example http://<rtmp_server_ip>/live
Stream key: unique key to stream the video. After adding the stream key the final link for the stream will be http://<rtmp_server_ip>/live/<stream_key>
Now your OBS application is all set ready to broadcast the video realtime on the server you have configured.
Viewing the Realtime Video.
One of the most popular application that support the RTMP protocol streaming is VLC player. VLC player can be downloaded via https://www.videolan.org/vlc/
Once the VLC media player is installed in your PC, you can start playing your live stream. Here is how it looks that i have setup myself after successful implementation.
