centos7 RTMP直播服務器搭建

首先須要下載
nginx-1.8.1 : http://nginx.org/download/nginx-1.8.1.tar.gzhtml

nginx-rtmp-module : https://github.com/arut/nginx-rtmp-modulenginx

安裝nginx
1.安裝nginx-1.8.1
wget http://nginx.org/download/nginx-1.8.1.tar.gzgit

2.安裝依賴
yum apt-get update
yum apt-get install libpcre3 libpcre3-dev
yum apt-get install openssl libssl-devgithub

3.解壓
tar -xvf nginx-1.8.1.tar.gz -C /usr/local/live瀏覽器

4.配置
//修改默認監聽端口
vi conf/nginx.conf服務器

5.添加nginx-rtmp-module模塊並編譯安裝
將下載的nginx-rtmp-module文件解壓,進入第3步解壓完的nginx-1.8.1文件夾中app

./configure --add-module=../nginx-rtmp-module --prefix=/usr/local/live/nginx
make
make installide

6.運行nginx,進入第5步安裝完後的nginx文件url

./sbin/nginx3d

搭建流媒體服務器相關配置
1.繼續上面的第4步

events {
    worker_connections  1024;
}

//添加的部分
rtmp {
    server {
        listen 82;#以後推流拉流的端口
        chunk_size 4096;

        application live {  
            live on;
        }
    }

}

server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
      
        #添加的部分
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            #爲nginx-rtmp-module解壓的地址
            root /usr/local/live/nginx-rtmp-module/;
        }
     
        location / {
            root   html;
            index  index.html index.htm;
        }
    }

配置完成後重啓nginx
./sbin/nginx -s reload

瀏覽器url: http:// + 服務器ip +: + 端口號 + /stat

這時候就能夠試試推流給流媒體服務器了。

ffmpeg推流本地MP4文件 : ffmpeg install : http://www.javashuo.com/article/p-swybncja-a.html

rtmp://nemtech.cn:82/live/test 推流路徑 82 就是上面配置rtmp的監聽端口,live爲application配置號,test能夠隨便取名

ffmpeg -re -i /usr/local/live/video/1.mp4 -vcodec copy -acodec copy -f flv rtmp://nemtech.cn6:82/live/test

執行上面命令後控制檯的大體樣子
此時ffmpeg正將MP4文件以rtmp協議推送給上面的nginx流媒體服務器,此時能夠進入 http:// + 服務器ip +: + 端口號 + /stat 網頁查看信息
以下圖,先不要看紅框中的,應該會出現藍框中的信息,publishing,就是推流端,能夠看到有一個流正在一直被推送給nginx服務器

而後能夠使用播放器收看該直播流,這裏推薦時用VLC
VLC收看直播流

填入上面推流的url:rtmp://nemtech.cn:82/live/test

就能夠收看剛纔推送的MP4文件直播了

相關文章
相關標籤/搜索