1. 程式人生 > >用nginx-rtmp-module搭建rtmp流媒體伺服器

用nginx-rtmp-module搭建rtmp流媒體伺服器

前言

利用開源的nginx-rtmp-moduleNginx搭建流媒體伺服器。Nginx是一個非常出色的http伺服器,nginx-rtmp-module是一個開源的Nginx擴充套件模組,擁有很多功能特性,像接收rtmp推流拉流,hls直播等:

1.RTMP/HLS/MPEG-DASH live streaming
2.RTMP Video on demand FLV/MP4, playing from local filesystem or HTTP
3.Stream relay support for distributed streaming: push & pull models
4.Recording streams in multiple FLVs
5.H264/AAC support
6.Online transcoding with FFmpeg
7.HTTP callbacks (publish/play/record/update etc)
8.Running external programs on certain events (exec)
9.HTTP control module for recording audio/video and dropping clients
10.Advanced buffering techniques to keep memory allocations at a minimum level for faster streaming and low memory footprint
11.Proved to work with Wirecast, FMS, Wowza, JWPlayer, FlowPlayer, StrobeMediaPlayback, ffmpeg, avconv, rtmpdump, flvstreamer and many more
12.Statistics in XML/XSL in machine- & human- readable form
13.Linux/FreeBSD/MacOS/Windows

下面是配置安裝使用詳細過程
1.下載nginx

nginx官方下載地址:https://nginx.org/en/download.html

wget https://nginx.org/download/nginx-1.13.8.tar.gz
2.解壓
tar -zxvf nginx-1.13.8.tar.gz
3.下載nginx的擴充套件模組 nginx-rtmp-module

用於接收rtmp 推流,搭建流媒體伺服器
原始碼地址:https://github.com/arut/nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module
4.安裝些必要的外掛庫
 apt-get install libpcre3 libpcre3-dev -y
 apt-get install libssl-dev -y
5.配置安裝 nginx-rtmp-module

進入nginx原始碼,配置擴充套件nginx-rtmp-module模組,編譯安裝,下面的/home/hx/Downloads/nginx-rtmp-module 是 nginx-rtmp-module的下載目錄。

cd nginx-1.13.8
./configure --add-module=/home/hx/Downloads/nginx-rtmp-module
--with-debug make make install
6.配置RTMP及啟動nginx

安裝完後會顯示安裝目錄,一般安裝在/usr/local/nginx
更多配置請參考https://github.com/arut/nginx-rtmp-module/wiki/Directives
設定nginx.conf檔案加入rtmp配置

vim /usr/local/nginx/conf/nginx.conf

加入以下內容,更詳細的配置見模組的官網

rtmp_auto_push on;
rtmp {
    server {
        listen 1935;

        application mytv {
            live on;
        }
    }
}

啟動

cd usr/local/nginx/sbin
./nginx

停止nginx服務
檢視程序資訊包括id

ps -ef |grep "nginx"

殺死程序

kill -9 id