RTMP is an open network protocol designed for real-time data communication. Developed by Adobe Systems, RTMP is used as a protocol for transferring audio, video, and data between Flash players and servers.
If you need live streaming, you can try to build your own RTMP server if you do not buy live streaming services such as Ali Cloud and Tencent Cloud. How to set up, see below we explain step by step.
The following uses the VPS server system installed with Debian10 as an example.
First, install service software
The server uses nginx with the nginx-rtmp-module module to provide RTMP services.
1, nginx
2, nginx – RTMP – module
First download the software and modules listed above, available in Debian10 using the wget command:
CD/TMP wget HTTP: / / http://nginx.org/download/nginx-1.19.10.tar.gzCopy the code
Once the download is complete, decompress nginx-1.19.10.tar.gz with the following command:
The tar XVF nginx - 1.19.10. Tar. GzCopy the code
Download the nginx-rtmp-module from the gitee clone with git to /opt/nginx:
cd /opt/nginx
git clone https://gitee.com/mirrors/nginx-rtmp-module.git
Copy the code
If the /opt/nginx directory does not exist, run the mkdir command to create it and change the permission of the directory to the current account linux265.
sudo mkdir /opt/nginx
sudo chown -hR linux265: /opt/nginx
Copy the code
If the git command is not installed, run the following command to install it:
sudo apt install git
Copy the code
After the /opt/nginx directory and git command are created and installed, run the following command to download the nginx-rtmp-module from the gitee clone:
git clone https://gitee.com/mirrors/nginx-rtmp-module.git
Copy the code
After downloading, go to/TMP /nginx-1.19.10 again and run the following command to configure and install nginx:
sudo apt install gcc make openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev
Copy the code
./configure --add-module=/opt/nginx/nginx-rtmp-module
Copy the code
sudo make && sudo make install
Copy the code
If all goes well, nginx will be installed in the /usr/local/nginx directory by default.
Configure the RTMP service
Go to the /usr/local/nginx/conf directory and run vim or nano to edit the nginx.conf file.
cd /usr/local/nginx/conf
sudo vim nginx.conf
Copy the code
The configuration is as follows:
#user nobody; worker_processes 1; error_log logs/error.log debug; rtmp { server { listen 1935; application myapp { live on; drop_idle_publisher 10s; } } } # HTTP can be used for accessing RTMP stats http { server { listen 8080; # This URL provides RTMP statistics in XML location /stat { rtmp_stat all; # Use this stylesheet to view XML as web page # in browser rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # XML stylesheet to view RTMP stats. # Copy stat.xsl wherever you want # and put the full directory path here root /path/to/stat.xsl/; } location /hls { # Serve HLS fragments types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; } location /dash { # Serve DASH fragments root /tmp; add_header Cache-Control no-cache; }}}Copy the code
After saving the configuration file, run the following command to test the correctness of the configuration file:
/usr/local/nginx/sbin/nginx -t
Copy the code
If yes, run the following command to start the nginx service:
cd /usr/local/nginx/sbin/
sudo ./nginx
Copy the code
After normal startup, enter your server address in the browser address bar and you will see a screen similar to the following:
Live on flow
We can live push stream through OBS, first you need to download and install OBS(OBS Studio), and then set up push stream, Settings similar to the following:
Then on the OBS main screen, set “Source” and click “Start Pushing stream”.
After that, refresh the page again and you should see something like this:
Watch the live broadcast
Pull stream is also called to access the live stream through the client, at this time we can use VLC which supports RTMP network video, configure the playback source:
So you can go straight to the live stream.
The above explains how to set up the RTMP live server on Debian10. If you are interested, please try it out.