RTMP直播服务器搭建

首先需要下载
nginx-1.8.1 : http://nginx.org/download/nginx-1.8.1.tar.gz

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

安装nginx
1.安装nginx-1.8.1
wget http://nginx.org/download/nginx-1.8.1.tar.gz

2.安装依赖
yum apt-get update
yum apt-get install libpcre3 libpcre3-dev
yum apt-get install openssl libssl-dev

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文件夹中

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

6.运行nginx,进入第5步安装完后的nginx文件

./sbin/nginx

搭建流媒体服务器相关配置
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 : https://www.cnblogs.com/zhaocundang/p/10676994.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文件直播了

猜你喜欢

转载自www.cnblogs.com/zhaocundang/p/10675408.html