基於nginx的rtmp的服務器(nginx-rtmp-module)


,首先下載安裝nginx需要依賴的庫文件:

 1.1,選定源碼目錄

    選定目錄 /usr/local/RTMP

     cd /usr/local/RTMP

 

 1.2,安裝PCRE庫

    cd /usr/local/RTMP

    到www.pcre.org 下載pcre-8.37.tar.gz , 然后拷貝到/usr/local/HLS

    tar -zxvf pcre-8.37.tar.gz

    cd pcre-8.37

    ./configure

    make

    make install

 1.3,安裝zlib庫

   cd /usr/local/RTMP

   到www.zlib.net 下載zlib-1.2.8.tar.gz, 然后拷貝到/usr/local/HLS

   tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

   ./configure

   make

   make install 

   1.4,安裝SSL 

    cd /usr/local/RTMP

  到www.openssl.org下載openssl-1.0.2g.tar.gz, 然后拷貝到/usr/local/HLS

  tar -zxvf openssl-1.0.2g.tar.gz

  ./config

  make

  make install

 

二,安裝包含  nginx-rtmp-module模塊的nginx

2.1,下載並解壓nginx

    到nginx.org 下載穩定版本的nginx-1.8.1.tar.gz, 然后拷貝到/usr/local/RTMP

    tar -zxvf nginx-1.8.1.tar.gz

2.2,下載 nginx-rtmp-module

  到 https://github.com/arut/nginx-rtmp-module 下載:nginx-rtmp-module.1.1.4.tar.gz 然后拷貝到/usr/local/RTMP

  tar -zxvf nginx-rtmp-module.1.1.4.tar.gz

2.3,編譯安裝包含  nginx-rtmp-module模塊的nginx

  2.3.1,進入nginx-1.8.1源碼目錄

 依次執行以下命令運行:

 ./configure --prefix=/usr/local/nginx --add-module=/usr/local/RTMP/nginx-rtmp-module.1.1.4 --with-http_ssl_module 

 make -f objs/Makefile

 make -f objs/Makefile install

 

三,配置點播RTMP

  3.1,打開nginx/conf目錄下的nginx.conf配置文件

    3.1.1  在http{

    ……

     }  大括號里面的末尾添加以下配置內容:

  #配置rtmp狀態頁
  server {
  listen 8080;

  location /stat {
    rtmp_stat all;
    rtmp_stat_stylesheet stat.xsl;
    }

  location /stat.xsl {
    root /usr/local/rtmp/nginx-rtmp-module.1.1.4/; #在nginx-rtmp-module源碼根目錄
    }
  }

  3.1.2, 然后在nginx.conf的末尾加上以下內容:

  #rtmp點播配置
  rtmp {
    server {
    listen 1935;
    chunk_size 4000;
    application vod {
      play /usr/local/nginx/vod/flvs; #點播媒體文件存放目錄
      }
    }
  }

    3.1.3,保存以上配置信息。

  3.2,配置點播環境信息

      3.2.1,建立媒體文件夾

         mkdir  /usr/local/nginx/vod/flvs

     3.2.2, 准備媒體文件

         把媒體文件(如oooo.flv)拷貝到 /usr/local/nginx/vod/flvs目錄下

     3.2.3, 准備網頁

        下載jwplayer: www.jwplayer.com  需要注冊,才能下載並獲取相應的license                              key(如:601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==)

    下載jwplayer7.3.6.zip后, 解壓到:/usr/local/nginx/html/

     建立測試網頁test.html,也放到上面的目錄下:

   

<html>
         <head>
		 welcome test rtmp <br>
                   <script src="/jwplayer/jwplayer.js"></script>
         </head>
         <body>
		 <script type="text/javascript">
							jwplayer.key="601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==";
				   </script>
                   <div id='my-video'></div>
                   <script type='text/javascript'>
                            jwplayer('my-video').setup({
                                     file:'rtmp://192.168.1.104/vod/oooo.flv',    
                                     width:'50%',
                                     aspectratio:'3:2',
                                     fallback:'false',
                                     primary:'flash'  
                                     });
                   </script>
				   <script type="text/javascript">
							jwplayer.key="601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==";
				   </script>
         </body>
</html>

  

  3.3,啟動nginx

     3.3.1 執行  /usr/local/nginx/sbin/nginx

      3.3.2,從客戶端網頁輸入 http://192.168.1.104:8080/stat   得到如圖結果:

     

     3.3.3,從客戶端網頁輸入:http://192.168.1.104/test.html  得到如下如圖結果:

      

 

四,配置直播RTMP

 4.1,打開nginx/conf目錄下的nginx.conf配置文件

   4.1.1 在配置文件里面加入如下配置信息:

     #rtmp直播配置

  rtmp {

     server {

          listen 1935;

          chunk_size 4000;

          application  live {

                     live on;

            }

      }

  }

   4.1.2,如3.1.1相同加入rtmp的狀態配置信息 

  #配置rtmp狀態頁
  server {
      listen 8080;

      location /stat {
          rtmp_stat all;
          rtmp_stat_stylesheet stat.xsl;
        }

      location /stat.xsl {
        root /usr/local/hls/nginx-rtmp-module-master/; #在nginx-rtmp-module源碼根目錄
        }
    }

  4.1.3,保存配置信息。

4.2配置資源信息

    

4.2.1, 准備網頁

        下載jwplayer: www.jwplayer.com  需要注冊,才能下載並獲取相應的license                                key(如:601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==)

    下載jwplayer7.3.6.zip后, 解壓到:/usr/local/nginx/html/

     建立測試網頁test.html,也放到上面的目錄下:

    

<html>
         <head>
		 welcom to test rtml <br>
                   <script src="/jwplayer/jwplayer.js"></script>
         </head>
         <body>
		 <script type="text/javascript">
							jwplayer.key="601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==";
				   </script>
                   <div id='my-video'></div>
                   <script type='text/javascript'>
                            jwplayer('my-video').setup({
                               file:'rtmp://192.168.0.128/live/test', #live是applicatioin,test是直播緩存流文件
                                     width:'50%',
                                     aspectratio:'3:2',
                                     fallback:'false',
                                     primary:'flash'  
                                     });
                   </script>
				   <script type="text/javascript">
							jwplayer.key="601u+htlhuXp5LQPeZtRlAABKwyX/94L3LRAcg==";
				   </script>
         </body>
</html>

 4.3,啟動nginx, 如3.3中的啟動

  4.4,模擬推流

安裝ffmpeg    ,請參考網上其他網文,在linux系統上安裝ffmpeg。

用ffmpeg模擬產生一個直播源,向配置的rtmp服務器推送

   ffmpeg –i /usr/local/nginx/vod/flvs/oooo.flv -strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.1.104/live/test

  注意:源文件必須是H.264+AAC的編碼格式

  其中,live是application; test是直播緩存流文件,需要與配置文件中的直播緩存文件名一致。(關於rtmp的URL格式請自行查閱相關資料)

 

4.5,從客戶端網頁輸入:http://192.168.1.104/test.html  得到類似3.3的效果圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM