使用nginx与nginx-rtmp-module搭建 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。


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


注:在安装 nginx 过程中 会 遇到 报错  类似于   .......C computer......

       这说明  缺少gcc   ,需要安装 gcc

       命令如下:

            yum install gcc.

      假如碰到其他的错误 有可能是openssl 没有安装,则还需要安装openssl

       命令如下:

             yum install openssl openssl-devel 

3、修改nginx配置文件:

命令如下:

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


在nginx.conf 中假如一下内容

rtmp {  
       server {  
           listen 1935;  #监听的端口

           chunk_size 4000; 

           application hls {  #rtmp推流请求路径 
                    live on;  
                    hls on;

                    hls_path /usr/local/nginx/html/hls; #此处的路径为视频串流到的位置(nginx默认装在了usr/local/  所以路径也是这样的s)

                    hls_fragment 5s;

                } 
           }

}

hls_path  权限需设置成可读可写。

修改http中的server模块:

 server {  
    listen       81;  
    server_name  localhost;  
  
    #charset koi8-r;  
  
    #access_log  logs/host.access.log  main;  
  
    location / {  
        root   /usr/local/nginx/html;  #自己配置路径
        index  index.html index.htm;  
    }  
  
    #error_page  404              /404.html;  
  
    # redirect server error pages to the static page /50x.html  
    #  
    error_page   500 502 503 504  /50x.html;  
    location = /50x.html {  
        root   html;  
    } 
然后启动nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  

4,完成后安装obs


    1)可安装在我们的电脑上

     安装会出现bug 自己调试 (安装上就行)


     2)安装好后我们开始配置obs

    

     第一步 如上图点击进入

     

    

     第二步  修改编码可修改也可不修改

    

   

    第三步  广播设定                 

   

    第四步 后面的你们自定义配置吧!不配置也可以

   


5,前面的完成后我们再场景配置

     选择一个即可配置可视频(视屏捕捉设备)也可桌面的




6,完成后我们开始串流

   会出现如下形式(此处我的场景配置是显示器获取



7、好了接下来我们可以观看直播(拉流)

观看直播就比较简单了,

在linux上创建hls文件也可是其他的文件夹

书写一个index.PHP文件


内容可如下:

[php]  view plain  copy
  1. <video>    
  2.     <source src="http://xxx:81/hls/test.m3u8"/>    
  3.     <p class="warning">Your browser does not support HTML5 video.</p>    
  4. </video>  


然后就可以简单的使用h5的vedio标签就可以观看了。

可以访问http://xxx:81/hls/mystream.m3u8来观看直播,其中xxx为你的服务器IP地址,



   


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值