Nginx builds RTMP streaming media server (Ubuntu18.04)

1 Environment Construction

The environment construction is mainly to use the plug-in module nginx-rtmp-module of the nginx server to perform the push-pull stream operation of rtmp.

Dependency library installation

Those who have installed nginx can skip this step, mainly to install ssl, pcre and zlib library dependencies

#安装ssl依赖库
sudo apt-get install openssl libssl-dev 
#安装pcre
sudo apt-get install libpcre3 libpcre3-dev
#安装zlib
sudo apt-get install zlib1g-dev 

Source code download and compile

Source code download path: https://github.com/arut/nginx-rtmp-module
Download the source code, if the git command cannot be downloaded, go directly to the web page to download and copy to the corresponding directory.

mkdir /home/rtmp
cd /home/rtmp
git clone https://github.com/nginx/nginx.git
git clone https://github.com/arut/nginx-rtmp-module.git

compilation process

Set nginx compilation parameters

auto/configure --with-http_ssl_module --with-http_v2_module --with-http_flv_module --with-http_mp4_module --add-module=../nginx-rtmp-module

compile and install

make -j4
sudo make install

After installation, you can check whether the nginx version is normal.
Default installation path: /usr/local/nginx/
insert image description here

2 Streaming service

2.1 Using file streaming

After completing the installation of the nginx server, you need to configure the rtmp service. You only need to modify the nginx configuration:

vi /usr/local/nginx/conf/nginx.conf

Notes on configuration content:

  • Enable root permission so that you can access the directory under home;
  • The play path is set to your own video folder path
user  root;
rtmp {
    
      #RTMP server
    server {
    
    
        listen 1935;  #server port
        chunk_size 4096;  #chunk_size
        application vod {
    
    
           #play /mnt/hgfs/ygf/vod; #media file position
           play /home/ffmpeg_learn/test_sources/test-av;
        }
    }
}

insert image description here
restart nginx

/usr/local/nginx/sbin/nginx -s reload

It should be noted that the playback path must be correct. At the same time, the playback audio is aac video and h264. Add a test.mp4 file here.
insert image description here
The following is the test process, windows uses the vlc tool to play the path of rtmp. The ip here needs to be set to your own Ubuntu ip address.
insert image description here
The video effect is as follows:
insert image description here
Note that the format of the video file needs to be determined:
Audio is AAC Video is H264

2.2 Fill one stream to nginx server rtmp for streaming

1 Modify the nginx configuration and add a live node for FFmpeg to push the stream to the corresponding node

        application live{
    
     # live add
           live on;
        }

insert image description here
2 Restart the nginx server

/usr/local/nginx/sbin/nginx -s reload

3 Perform streaming operation

ffmpeg -re -i /home/ffmpeg_learn/test_sources/test-av/Titanic.mp4 -c copy -f flv rtmp://192.168.88.180/live/Titanic

Use vlc to view the video, as follows:
insert image description here

3 Live streaming

Using VLC above is a streaming process.
The FFmpeg command line operation is introduced here.

#利用ffplay直接观看
ffplay rtmp://192.168.88.180/vod/Titanic.mp4
#利用FFmpeg下载到文件
ffmpeg -i rtmp://192.168.88.180/vod/Titanic.mp4 test.mp4

Guess you like

Origin blog.csdn.net/qq_38731735/article/details/125821551