利用nginx+rtmp搭建直播架构

服务端安装

nginx源码

$ git clone https://github.com/nginx/nginx.git

nginx的rtmp模块源码

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

nginx的依赖pcre源码

$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

tar−xzvf pcre−8.39.tar.gz

cd nginx$ git checkout release-1.9.9

安装依赖的库

sudo apt-get install openssl libssl-dev

将configure的命令封装成脚本

$ vim cfg.sh

cfg.sh文件的内容

auto/configure –prefix=/usr/local/nginx \
–with-pcre=../pcre-8.39 \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_flv_module \
–with-http_mp4_module \
–add-module=../nginx-rtmp-module/

chmoda+xcfg.sh

./cfg.sh

make

make install
 

配置nginx

安装完成后,打开Nginx的配置文件nginx.conf进行配置

首先在里面加入rtmp的配置

Java代码  

  1. rtmp {  
  2.     server {  
  3.         listen 1935;  
  4.   
  5.         application myapp {  
  6.             live on;  
  7.         }  
  8.         application hls {  
  9.             live on;  
  10.             hls on;  
  11.             hls_path /tmp/hls;  
  12.         }  
  13.     }  
  14. }  
  15. 在nginx.conf的最后加上

然后,针对hls,还需要在http里面增加一个location配置

Java代码  

  1. location /hls {  
  2.             types {  
  3.                 application/vnd.apple.mpegurl m3u8;  
  4.                 video/mp2t ts;  
  5.             }  
  6.             root /tmp;  
  7.             add_header Cache-Control no-cache;  
  8. }  

 

启动nginx

/usr/local/nginx/sbin/nginx

发现监听了1935,配置文件配置的端口

 

二:推流

方式1:用ffmpeg来模拟推流

ffmpeg -re -i film.mp4(视频文件) -c copy -f flv rtmp://服务器ip:1935/myapp/test1
 

方式2:在pc端用obs推流

三:拉流观看

用vlc

打开网络串流,输入rtmp://服务器ip:1935/myapp/test1,既可观看。

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值