linux 下 nginx+obs 搭建rtmp流媒体,实现直播

1、下载nginx-rtmp-module:

nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

使用命令:

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

将nginx-rtmp-module下载到linux中。

2、安装nginx:

nginx的官方网站为:http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.8.1.tar.gz  
tar -zxvf nginx-1.8.1.tar.gz  
cd nginx-1.8.1  
./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module    
make && make install  
本次默认安装目录为:/root, add-module为下载的nginx-rtmp-module文件路径。

安装时候可能会报错没有安装openssl,需要执行命令:

yum -y install openssl openssl-devel   

3、修改nginx配置文件:

vi /usr/local/nginx/conf/nginx.conf  

末尾加入以下内容:

rtmp {    
    
    server {    
    
        listen 1935;  #监听的端口  
    
        chunk_size 4000;    
          
           
        application hls {  #rtmp推流请求路径  
            live on;    
            hls on;    
            hls_path /usr/share/nginx/html/hls;    
            hls_fragment 5s;    
        }    
    }    
}  

修改http中的server模块

 location / {  
        root   /usr/share/nginx/html;  
        index  index.html index.htm;  
    }  

启动nginx:

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

4、开始推流

做好以上的配置后,就可以开始推流了,我们可以使用obs来推流。

下载地址  https://obsproject.com/download#mp

打开OBS点击设置

在设置->串流 中填写信息:URL为 rtmp://xxx:1935/hls,xxx为你的服务器的IP地址,hls是用来存放流媒体的。

秘钥可以随便填写一个,用来播放的时候识别播放哪个流媒体的,例如填写test等。

填写完毕后,点击开始串流,就说明我们的流媒体服务器搭建成功了。


访问可用vlc播放器 或者H5 video标签

<video>    
    <source src="http://xxx:81/hls/test.m3u8"/>    
    <p class="warning">Your browser does not support HTML5 video.</p>    
</video>  


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值