Introduction
The RTMP streaming media protocol is a set of audio and video real-time transmission protocols developed by Adobe; nginx-rtmp is an RTMP service module based on nginx, open source and free
https://github.com/arut/nginx-rtmp-module
Install nginx and nginx-rtmp
sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y
mkdir ~/working
cd ~/working
wget http://nginx.org/download/nginx-1.9.7.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
Install the unzip package.
sudo yum install unzip
tar -xvf nginx-1.9.7.tar.gz
unzip v1.2.1.zip
cd nginx-1.9.7
. /configure --add-module=../nginx-rtmp-module-1.2.1/
make
sudo make install
sudo nano /usr/lib/systemd/system/nginx.service
Fill the file with the following content.
[ Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[ Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[ Install]
WantedBy=multi-user.target
sudo systemctl start nginx.service
Tell SystemD to automatically start the Nginx service at startup.
systemctl enable nginx.service
Install epel-release
and update the system.
sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel -y
Open the Nginx configuration file.
sudo nano /usr/local/nginx/conf/nginx.conf
Add the following to the configuration.
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
exec ffmpeg -i rtmp://localhost/live/$name -threads 1-c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1-strict -2-b:a 56k rtmp://localhost/live360p/$name;}
application live360p {
live on;
record off;}}}
After adding this configuration text, you can customize settings such as video bit rate, audio bit rate and resolution. These changes will only be applied to lower quality streams. To add more quality, copy and paste the exec FFmpeg line and change the settings. You also need to create a new application. You can do this by copying and pasting the live360 example already included. Don't forget to update the exec FFmpeg line with the address of the new application. You can do this by changing the final RTMP address in the exec FFmpeg line.
**Note: Afterwards, changing the value -b:v
will change the video bitrate. In kilobits per second. Changing the value -b:a
afterwards will change the audio bitrate. In kilobits per second. Changing the value -s
afterwards will change the resolution. *
Press CTRL+ to save the file X.
Restart Nginx.
sudo service nginx restart
**Note: ***For best performance, each stream to be converted should have its own CPU core. For example, if you want to create two quality 360P and 480P from a 720P stream, you should use a Vultr instance with at least two CPU cores. *
If you are using a firewall, you need to make sure that TCP 1935
is allowed.
The current configuration allows anyone to stream to your server. We can solve this problem by granting only certain IP address publishing permissions. Open Nginx configuration.
sudo nano /usr/local/nginx/conf/nginx.conf
Find the following line.
live on;
record off;
Add the following to the lines above. Change 0.0.0.0
to your actual IP address.
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;
Now, the configuration will look like this.
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;
exec ffmpeg -i rtmp://localhost/live/$name -threads 1-c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1-strict -2-b:a 56k rtmp://localhost/live360p/$name;}
application live360p {
live on;
record off;
allow publish 127.0.0.1;
allow publish 0.0.0.0;
deny publish all;}}}
Press CTRL+ to save the file X.
Restart Nginx.
sudo service nginx restart
Streaming applications usually have two fields for connecting information. The first field is usually used for server information, and the second field is usually used for stream name or key. Lists the information you should put in each field. The stream name or key can be set to anything.
Field 1: rtmp://your.vultr.ip/live/
Field 2: stream-key-you-set
To view the stream, please open the following link in a player that supports RTMP.
rtmp://your.vultr.ip/live/stream-key-you-set
rtmp://your.vultr.ip/live360p/stream-key-you-set
https://www.vultr.com/docs/setup-nginx-rtmp-on-centos-7
Recommended Posts