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文件直播了

相关文章
相关标签/搜索