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

Αφήστε ένα σχόλιο

The Rise of Machines: Real World Applications of AI

The Rise of Machines: Real World Applications of AI

Η Τεχνητή Νοημοσύνη δεν είναι στο μέλλον, είναι εδώ ακριβώς στο παρόν Σε αυτό το blog Διαβάστε πώς οι εφαρμογές Τεχνητής Νοημοσύνης έχουν επηρεάσει διάφορους τομείς.

Επιθέσεις DDOS: Μια σύντομη επισκόπηση

Επιθέσεις DDOS: Μια σύντομη επισκόπηση

Είστε επίσης θύμα των επιθέσεων DDOS και έχετε μπερδευτεί σχετικά με τις μεθόδους πρόληψης; Διαβάστε αυτό το άρθρο για να λύσετε τις απορίες σας.

Έχετε αναρωτηθεί ποτέ πώς κερδίζουν χρήματα οι χάκερ;

Έχετε αναρωτηθεί ποτέ πώς κερδίζουν χρήματα οι χάκερ;

Μπορεί να έχετε ακούσει ότι οι χάκερ κερδίζουν πολλά χρήματα, αλλά έχετε αναρωτηθεί ποτέ πώς κερδίζουν τέτοια χρήματα; ας συζητήσουμε.

Επαναστατικές εφευρέσεις από την Google που θα σας φέρουν εύκολη στη ζωή.

Επαναστατικές εφευρέσεις από την Google που θα σας φέρουν εύκολη στη ζωή.

Θέλετε να δείτε επαναστατικές εφευρέσεις της Google και πώς αυτές οι εφευρέσεις άλλαξαν τη ζωή κάθε ανθρώπου σήμερα; Στη συνέχεια, διαβάστε στο blog για να δείτε τις εφευρέσεις της Google.

Friday Essential: Τι συνέβη με τα αυτοκίνητα που κινούνται με AI;

Friday Essential: Τι συνέβη με τα αυτοκίνητα που κινούνται με AI;

Η ιδέα των αυτοκινούμενων αυτοκινήτων να βγαίνουν στους δρόμους με τη βοήθεια της τεχνητής νοημοσύνης είναι ένα όνειρο που έχουμε εδώ και καιρό. Όμως, παρά τις πολλές υποσχέσεις, δεν φαίνονται πουθενά. Διαβάστε αυτό το blog για να μάθετε περισσότερα…

Τεχνολογική μοναδικότητα: Ένα μακρινό μέλλον του ανθρώπινου πολιτισμού;

Τεχνολογική μοναδικότητα: Ένα μακρινό μέλλον του ανθρώπινου πολιτισμού;

Καθώς η Επιστήμη εξελίσσεται με γρήγορους ρυθμούς, αναλαμβάνοντας πολλές από τις προσπάθειές μας, αυξάνονται και οι κίνδυνοι να υποβάλλουμε τον εαυτό μας σε μια ανεξήγητη Ιδιότητα. Διαβάστε τι σημαίνει η μοναδικότητα για εμάς.

Λειτουργίες Αρχιτεκτονικών Επιπέδων Αναφοράς Μεγάλων Δεδομένων

Λειτουργίες Αρχιτεκτονικών Επιπέδων Αναφοράς Μεγάλων Δεδομένων

Διαβάστε το ιστολόγιο για να μάθετε διαφορετικά επίπεδα στην Αρχιτεκτονική Μεγάλων Δεδομένων και τις λειτουργίες τους με τον απλούστερο τρόπο.

Εξέλιξη της αποθήκευσης δεδομένων – Infographic

Εξέλιξη της αποθήκευσης δεδομένων – Infographic

Οι μέθοδοι αποθήκευσης των δεδομένων εξελίσσονται μπορεί να είναι από τη γέννηση των Δεδομένων. Αυτό το ιστολόγιο καλύπτει την εξέλιξη της αποθήκευσης δεδομένων με βάση ένα infographic.

6 εκπληκτικά οφέλη από την ύπαρξη έξυπνων οικιακών συσκευών στη ζωή μας

6 εκπληκτικά οφέλη από την ύπαρξη έξυπνων οικιακών συσκευών στη ζωή μας

Σε αυτόν τον ψηφιακό κόσμο, οι έξυπνες οικιακές συσκευές έχουν γίνει κρίσιμο μέρος της ζωής. Ακολουθούν μερικά εκπληκτικά οφέλη των έξυπνων οικιακών συσκευών σχετικά με το πώς κάνουν τη ζωή μας να αξίζει και να απλοποιείται.

Η ενημέρωση του συμπληρώματος macOS Catalina 10.15.4 προκαλεί περισσότερα προβλήματα από την επίλυση

Η ενημέρωση του συμπληρώματος macOS Catalina 10.15.4 προκαλεί περισσότερα προβλήματα από την επίλυση

Πρόσφατα, η Apple κυκλοφόρησε το macOS Catalina 10.15.4 μια συμπληρωματική ενημέρωση για την επιδιόρθωση προβλημάτων, αλλά φαίνεται ότι η ενημέρωση προκαλεί περισσότερα προβλήματα που οδηγούν σε bricking των μηχανών mac. Διαβάστε αυτό το άρθρο για να μάθετε περισσότερα