Nginx 搭建直播流服务

搭建直播流服务器

技术

  • Nginx
  • nginx-rtmp-module-1.1.11 (nginx 插件)

步骤

  1. 下载nginx 和 nginx-rtmp-module 源文件
  2. 解压 nginx 和 nginx-rtmp-module
  3. ./configure --add-module=/home/shichangcheng/live/nginx-rtmp-module-1.1.11(将nginx第三方模块加入nginx)
  4. make ; make install;
  5. 配置nginx.conf
http {
	include       mime.types;
	default_type  application/octet-stream;


	sendfile        on;

	keepalive_timeout  65;

	server {
	    listen       80;
	    server_name  localhost;

	    #charset koi8-r;

	    #access_log  logs/host.access.log  main;

	    location / {
	        root   html;
	        index  index.html index.htm;
	    }

		error_page   500 502 503 504  /50x.html;
	    location = /50x.html {
	        root   html;
	    }

		# hls living
	    location /stat {
	        rtmp_stat all;
	        rtmp_stat_stylesheet stat.xsl;
	    }

	    location /stat.xsl {
	        root /usr/local/nginx/html/nginx-rtmp-module/;
	    }

	    location /control {
	        rtmp_control all;
	    }
	    location /hls {
	       types{
	         application/vnd.apple.mpegurl m3u8;
	         video/mp2t ts;
	        }
	       root /home/shichangcheng/live/my-app;
	    }
	}
}

rtmp {
    server {
        listen 1935;

        application hls {
             live on;
             hls on;
             hls_path /home/shichangcheng/live/my-app/hls;
             hls_fragment 5s;
       }

        application live{
             live on;
             max_connections 1024;
             allow play all;

             record_path /home/shichangcheng/live/my-app/live;

             recorder audio
             {
                record audio;
                record_suffix -%d-%b-%y-%T.flv;
             }
             recorder chunked

             {
                record all;
                #record_max_size 5120K;  
                record_interval 15s;
                record_path /home/shichangcheng/live/my-app/live/chunked;
             }
        }
    }
}

遇到的问题

  1. liunx 的权限
  2. nginx user 修改为root
  3. rtmp 中 record_path 保存客户端采集视频信息推动到服务器的地址,需要注意该文件的读写权限。
  4. 防火墙 iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT

推流地址

rtmp://123.206.231.130/hls/(movie)
(movie)为表示生成流文件的名字

播放地址

rtmp地址:rtmp://123.206.231.130/hls/(movie)
hvl 地址:http://123.206.231.138/hls/movie.m3u8

直播协议

  1. rtmp :rtmp 延时较低,需要使用flash,或者解码器才能播放。
  2. hlv :hlv 延时较高,自己测未进过cdn一般优化,延时5。移动端网页播放使用HLV协议。

客户端

  1. 直播工具可以使用金山云的DEMO
  2. 播放器
  • H5 只能使用 hlv 地址
  • 金山云提供的播放SDK
  • PC客户端 VLC Media Player

我的博客

转载于:https://my.oschina.net/shichangcheng/blog/889236

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值