Setup Nginx-RTMP on CentOS 7

RTMP is great for serving live content. When RTMP is paired with FFmpeg, streams can be converted into various qualities. Vultr is great for these applications as they provide fast and dedicated CPU performance. Vultr’s global network also ensures that you can deliver high-quality live content with minimal delay. Let's get started!

Installing Nginx and Nginx-RTMP

Install the tools required to compile Nginx and Nginx-RTMP from source.

sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y

Make a working directory and switch to it.

mkdir ~/working
cd ~/working

Download the 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

Extract the Nginx and Nginx-RTMP source.

tar -xvf nginx-1.9.7.tar.gz
unzip v1.2.1.zip

Switch to the Nginx directory.

cd nginx-1.9.7

Add modules to compile into Nginx. Nginx-RTMP is included.

./configure --add-module=../nginx-rtmp-module-1.2.1/

Compile and install Nginx with Nginx-RTMP.

make
sudo make install

Create a SystemD unit file for Nginx.

sudo nano /usr/lib/systemd/system/nginx.service

Populate 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

Start and enable the Nginx service.

sudo systemctl start nginx.service

Tell SystemD to start Nginx services automatically at boot.

systemctl enable nginx.service

Installing FFmpeg

Install epel-release and update the system.

sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now

Install the 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

Install FFmpeg and its development packages.

sudo yum install ffmpeg ffmpeg-devel -y

Configuring Nginx-RTMP and FFmpeg

Open the Nginx configuration file.

sudo nano /usr/local/nginx/conf/nginx.conf

Append 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 you've added that configuration text, you can customize settings such a video bitrate, audio bitrate, and resolution. These changes will only be applied to the lower quality stream. To add more qualities, copy and paste the exec FFmpeg line and change the settings. You'll also need to create a new application. You can do this by copying and pasting the live360 example that has been 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: Changing the value after -b:v will change the video bitrate. This is measured in kilobits per second. Changing the value after -b:a will change the audio bitrate. This is measured in kilobits per second. Changing the value after -s will change the resolution.

Save the file by pressing CTRL + X.

Restart Nginx.

sudo service nginx restart

Note: For best performance, each stream being converted should have its own CPU core. For example, if two qualities, 360P and 480P, are being created from a 720P stream, a Vultr instance with at least two CPU cores should be used.

Security Note

If you're using a firewall, you'll need to make sure TCP 1935 is allowed.

The current configuration allows anyone to stream to your server. We can fix this by only giving certain IP addresses the publish permission. Open the Nginx configuration.

sudo nano /usr/local/nginx/conf/nginx.conf

Look for the following lines.

live on;
record off;

Add the following to each set of the above lines. 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;

The configuration will now look something like the following.

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;
        }
    }
}

Save the file by pressing CTRL + X.

Restart Nginx.

sudo service nginx restart

Configuring Software to Work with Nginx-RTMP

Streaming applications typically have two fields for connection information. The first field is usually for the server information and the second field is usually for the stream name or key. The information that you should place into each field is listed. 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 streams, open the following links in a player supporting RTMP.

rtmp://your.vultr.ip/live/stream-key-you-set
rtmp://your.vultr.ip/live360p/stream-key-you-set

Lëreni një koment

Ngritja e makinave: Aplikimet në botën reale të AI

Ngritja e makinave: Aplikimet në botën reale të AI

Inteligjenca Artificiale nuk është në të ardhmen, është këtu në të tashmen Në këtë blog Lexoni se si aplikacionet e inteligjencës artificiale kanë ndikuar në sektorë të ndryshëm.

Sulmet DDOS: Një përmbledhje e shkurtër

Sulmet DDOS: Një përmbledhje e shkurtër

A jeni edhe ju viktimë e Sulmeve DDOS dhe jeni konfuz në lidhje me metodat e parandalimit? Lexoni këtë artikull për të zgjidhur pyetjet tuaja.

A e keni pyetur ndonjëherë veten se si fitojnë para hakerët?

A e keni pyetur ndonjëherë veten se si fitojnë para hakerët?

Ju mund të keni dëgjuar se hakerët fitojnë shumë para, por a keni menduar ndonjëherë se si i fitojnë ato para? Le te diskutojme.

Shpikjet revolucionare nga Google që do tju bëjnë të lehtë jetën tuaj.

Shpikjet revolucionare nga Google që do tju bëjnë të lehtë jetën tuaj.

Dëshironi të shihni shpikjet revolucionare nga Google dhe se si këto shpikje ndryshuan jetën e çdo njeriu sot? Më pas lexoni në blog për të parë shpikjet nga Google.

E Premte Thelbësore: Çfarë ndodhi me Makinat e drejtuara nga AI?

E Premte Thelbësore: Çfarë ndodhi me Makinat e drejtuara nga AI?

Koncepti i makinave vetë-drejtuese për të dalë në rrugë me ndihmën e inteligjencës artificiale është një ëndërr që e kemi prej kohësh. Por, pavarësisht nga disa premtime, ato nuk shihen askund. Lexoni këtë blog për të mësuar më shumë…

Singulariteti teknologjik: Një e ardhme e largët e qytetërimit njerëzor?

Singulariteti teknologjik: Një e ardhme e largët e qytetërimit njerëzor?

Ndërsa Shkenca evoluon me një ritëm të shpejtë, duke marrë përsipër shumë nga përpjekjet tona, rriten edhe rreziqet për t'iu nënshtruar një Singulariteti të pashpjegueshëm. Lexoni, çfarë mund të thotë singulariteti për ne.

Funksionalitetet e shtresave të arkitekturës së referencës së të dhënave të mëdha

Funksionalitetet e shtresave të arkitekturës së referencës së të dhënave të mëdha

Lexoni blogun për të njohur shtresat e ndryshme në arkitekturën e të dhënave të mëdha dhe funksionalitetet e tyre në mënyrën më të thjeshtë.

Evolucioni i ruajtjes së të dhënave - Infografik

Evolucioni i ruajtjes së të dhënave - Infografik

Metodat e ruajtjes së të dhënave kanë evoluar mund të jenë që nga lindja e të dhënave. Ky blog mbulon evolucionin e ruajtjes së të dhënave në bazë të një infografike.

6 Përfitimet e mahnitshme të të pasurit pajisje shtëpiake inteligjente në jetën tonë

6 Përfitimet e mahnitshme të të pasurit pajisje shtëpiake inteligjente në jetën tonë

Në këtë botë të drejtuar nga dixhitali, pajisjet inteligjente të shtëpisë janë bërë një pjesë thelbësore e jetës. Këtu janë disa përfitime të mahnitshme të pajisjeve shtëpiake inteligjente se si ato e bëjnë jetën tonë të vlefshme dhe më të thjeshtë.

Përditësimi shtesë i macOS Catalina 10.15.4 po shkakton më shumë probleme sesa zgjidhja

Përditësimi shtesë i macOS Catalina 10.15.4 po shkakton më shumë probleme sesa zgjidhja

Së fundmi Apple lëshoi ​​macOS Catalina 10.15.4 një përditësim shtesë për të rregulluar problemet, por duket se përditësimi po shkakton më shumë probleme që çojnë në bricking të makinerive mac. Lexoni këtë artikull për të mësuar më shumë