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

搭建基於nginx-rtmp-module的流媒體伺服器

1.業務流程圖

 

2.軟體下載

  2.1 windows下載obs

  2.2 linux 安裝nginx(附加rtmp模組)

     1.cd /usr/local

     2.mkdir nginx

     3.cd nginx

     4.wget  http://nginx.org/download/nginx-1.14.1.tar.gz 

     5.wget  https://github.com/arut/nginx-rtmp-module/archive/master.zip

     6.tar -zxvf  nginx-1.14.1.tar.gz

                  7.unzip  master.zip

     8.cd  nginx-1.14.1

     9.   ./configure --add-module=/usr/local/nginx/nginx-rtmp-module-master       (編譯並新增rtmp模組)

       10.make && make install

     

     啟動nginx:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

     success:

    

 

  2.3 yum 安裝 ffmpeg

       1.先安裝第三方yum源

     rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

     rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

     2.安裝ffmpeg及其開發包

     yum install ffmpeg ffmpeg-devel -y

 

    輸入ffmpeg,出現下圖所示,ffmpeg安裝成功。

               

 

 

3.環境配置 

  3.1nginx配置  

#這裡講nginx server的埠都改為66,因為想同時使用nginx和apache
#全域性塊中增加rtmp塊
rtmp { server { listen
1935; #服務埠--預設 chunk_size 4096; #資料傳輸塊的大小--預設 #設定直播的application名稱是 live application live{ live on; #live on表示開啟直播模式 } #設定推流的應用名稱 application push{ live on; #開啟直播 push rtmp://ip地址/live; #推流到上面的直播應用 } } }


  #http塊中增加 server
 server {
listen 66; #埠
server_name IP地址;
#下面兩個是加上去的,用來配置直播的http訪問
#具體的意思可以在github的文件中檢視
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
#注意這裡的路徑不能錯誤,直接寫絕對路徑就可以
root /usr/local/nginx/nginx-rtmp-module-master;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
 

重啟nginx,瀏覽器輸入  ip地址:66/stat,出現下圖所示,則流媒體伺服器搭建成功。推流,拉流時,此介面會有具體資料顯示。

 

   3.2 obs推送視訊流

  

   錄影->推流

   

 

  

       3.3 vlc拉流

   媒體->開啟網路串流

  

 

  

  ps:以用ffmpeg來收錄rtmp視訊流,來生成視訊檔案  

  ffmpeg -i  rtmp://ip/live   -c copy  test.mp4

 

  即可完成直播流傳輸,但是延遲很嚴重。。