centos7 install nginx-rtmp

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

  1. Install the tools needed to compile Nginx and Nginx-RTMP from source code.
sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y
  1. Create a working directory and switch to that directory.
mkdir ~/working
cd ~/working
  1. Download Nginx and Nginx-RTMP sources.
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
  1. Extract Nginx and Nginx-RTMP sources.
tar -xvf nginx-1.9.7.tar.gz
unzip v1.2.1.zip
  1. Switch to the Nginx directory.
cd nginx-1.9.7
  1. Add modules to compile into Nginx. Including Nginx-RTMP.
. /configure --add-module=../nginx-rtmp-module-1.2.1/
  1. Use Nginx-RTMP to compile and install Nginx.
make
sudo make install
  1. Create a SystemD unit file for Nginx.
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
  1. Start and enable the Nginx service.
sudo systemctl start nginx.service

Tell SystemD to automatically start the Nginx service at startup.

systemctl enable nginx.service

10. Install FFmpeg

Install epel-release and update the system.

sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now
  1. Install Nux repository.
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
  1. Install FFmpeg and its development kit.
sudo yum install ffmpeg ffmpeg-devel -y

Configure Nginx-RTMP and FFmpeg

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. *

Safety instructions###

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

Configure the software to use Nginx-RTMP

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

centos7 install nginx-rtmp
Centos6 install Python2.7.13
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
Centos7 install Python 3.6.
CentOS7 install MySQL
Centos7 install protobuf
CentOS 7 install Docker
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
CentOS install Python 3.6
Vmware install CentOS6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
Centos install Python3
centos7 install docker
CentOS install jdk
CentOS8 install MySQL8.0
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL
CentOS7 install MySQL8
CentOS 7 install Java 1.8
CentOS 6 install Docker
centos 6.5 install zabbix 4.4
Centos8 install Docker
CentOS6.8 install python2.7
CentOS install nodejs 8
CentOS6.5 install GNS3
centos 7.5 install mysql5.7.17
Centos7 install MySQL8.0-manual
CentOS7 install Kubernetes 1.16.3
VirtualBox install centos7
centos7 install lamp
Install centos7 and connect
Install Docker on Centos7
Centos7 install docker-18.x original
install LNMP on centos7.4
Centos7 YUM install MariaDB 10.0