Configure nginx + RTMP streaming media server under Ubuntu16.04

Table of contents

foreword

 1. The environment required to install nginx

1.1 View gcc version gcc -v

1.2 pcre, pcre-devel installation

1.3 zlib installation

1.4 install openssl

 2. Start the installation

 2.1 Create a folder

 2.2 Go to a folder

2.3 Download various installation packages

2.4 Decompression

2.5 compile

2.7 Configure nginx to use RTMP

 2.8 Restart the nginx server

3 Install FFmpeg

3.1 Add source

3.2 Update source

3.3 Download and install

4 tests

4.1 Streaming

4.2 Streaming

Recommended reading:


foreword

Recently, to deploy a project, I need to be responsible for the video network transmission. At the beginning, I used the socket to transmit the video. It was too stuck. The boss almost let me go. Fortunately, I have learned the method of using rtmp to push the vue front-end to pull the stream, otherwise I went to sleep under the flyover.

                                        

 1. The environment required to install nginx

1.1 View gcc version gcc -v

centos中安装GCC:

yum -y install gcc

Ubuntu中安装GCC:

apt-get install gcc

1.2 pcre, pcre-devel installation

pcre is a perl library, including a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed.

centos中安装PCRE:

yum install -y pcre pcre-devel

Ubuntu中安装PCRE:

apt-get install libpcre3 libpcre3-dev

1.3 zlib installation

The zlib library provides a variety of compression and decompression methods nginx uses zlib to gzip the content of the http package, so it needs to be installed

centos中安装zlib:

yum install -y zlib zlib-devel

Ubuntu中安装zlib:

apt-get install zlib1g zlib1g-dev

1.4 install openssl

Openssl is the cornerstone of web security communication. Without openssl, it can be said that our information is streaking. . . . . .

Install command:

centos中安装OpenSSL:

yum install -y openssl openssl-devel

# Ubuntu14.04的仓库中没有发现openssl-dev,由下面openssl和libssl-dev替代
#apt-get install openssl openssl-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev

 2. Start the installation

 2.1 Create a folder

mkdir /usr/local/web

 2.2 Go to a folder

cd /usr/local/web

2.3 Download various installation packages

wget http://nginx.org/download/nginx-1.9.15.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

2.4 Decompression

tar -zxvf nginx-1.9.15.tar.gz
unzip master.zip
cd nginx-1.9.15

2.5 compile

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
sudo make install

2.6 Start nginx and check whether nginx can run successfully

sudo /usr/local/nginx/sbin/nginx
ps -ef | grep nginx 

2.7 Configure nginx to use RTMP

Go to the configuration file to configure RTMP

vim /usr/local/nginx/conf/nginx.conf
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
                }
        }
}

 2.8 Restart the nginx server

sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

Now our environment is installed, but we also need to install a FFmpeg to use RTMP.

3 Install FFmpeg

3.1 Add source

sudo add-apt-repository ppa:djcj/hybrid

3.2 Update source

sudo apt-get update

3.3 Download and install

sudo apt-get install ffmpeg

4 tests

4.1 Streaming

ffmpeg -re -i /usr/local/web/studey/mysite/chat/video/4.mp4 -f flv rtmp://139.159.142.192:1935/live/test

 

4.2 Streaming

Test with VLC tool:

Recommended reading:

Python implements video and camera streaming through ffmpeg (ubuntu16+ffmpeg+nginx)

Guess you like

Origin blog.csdn.net/weixin_46504244/article/details/121982301