centos7 搭建rtmp+hls直播流服务器及rtmp转hls直播流(nginx+nginx-rtmp-module-master+obs)

nginx安装

具体过程参考Centos 安装 Nginx 详细过程

nginx-rtmp模块安装

1、使用linux的root账号登录系统
2、执行一下命令

 cd /
 mkdir soft

3、从 https://github.com/arut/nginx-rtmp-module 下载nginx-rtmp-module,放到刚刚创建的soft目录下
4、执行一下命令

 cd /soft/nginx-1.8.1/
 ./configure --add-module=/soft/nginx-rtmp-module-master && make && make install

5、以上执行过程没有出现error证明nginx-rtmp安装成功

修改nginx配置

 cd /usr/local/nginx/conf/
 cp nginx.conf.default live_rtmp.conf
 vi live_rtmp.conf
 
 **在live_rtmp.conf里面加入一下代码**
 
   rtmp {
	    server {
	        listen 1935;
	        chunk_size 4000;
	        # TV mode: one publisher, many subscribers
	        application mylive {
	            # enable live streaming
	            live on;
	            # record first 200M of stream
	            record all;
	            record_path /usr/local/nginx/html/live_record;
	            record_max_size 200M;
	
	            hls on;
	            hls_path /usr/local/nginx/html/hls;
	            hls_fragment 5s;
	            hls_playlist_length 5;
	
	            allow play all;
	
	            #on_publish 'http://when start publish live call this url';
	            #on_done 'http://when live stop call this url';
	        }
	    }
	}
	
	**在http里面加入一下代码**
	
	server {
    listen       8080;
    # This URL provides RTMP statistics in XML
    location /stat {
        rtmp_stat all;
        # Use this stylesheet to view XML as web page
        # in browser
        rtmp_stat_stylesheet stat.xsl;
    }

    location /stat.xsl {
        # XML stylesheet to view RTMP stats.
        # Copy stat.xsl wherever you want
        # and put the full directory path here
        root /usr/local/nginx/html/;
    }

    location /hls {
        # Serve HLS fragments
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        root /usr/local/nginx/html/;
        add_header Cache-Control no-cache;
    }
 }

编辑完成验证nginx是否正确:

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/live_rtmp.conf

验证完成启动nginx直播流服务:

/usr/local/nginx/sbin/nginx  -c /usr/local/nginx/conf/live_rtmp.conf

使用obs验证直播流服务是否可用

obs官网下载windows版本的obs
使用教程如下:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

使用VLC验证是否可以正常拉流

vlc官网下载并安装,具体使用方式我以图片+文字的方式介绍
媒体–》打开网络串流在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这个时候如果网络好的话直播加载非常快,如果网络不好请稍等一会
在这里插入图片描述
直播已开始

rtmp地址:rtmp://192.168.0.117/mylive/demo
hls地址:http://192.168.0.117:8080/hls/demo.m3u8

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值