用开源nginx-rtmp-module搭建flash直播环境

21 篇文章 0 订阅

1、将nginx和nginx-rtmp-module的源码包解压
PS:nginx-rtmp-module网址
https://github.com/arut/nginx-rtmp-module

2、进入nginx的源代码目录,编译
./configure --add-module=<path-to-nginx-rtmp-module> --without-http_rewrite_module
make
make install


3、写一个测试配置文件
#user nobody;
worker_processes 1;

error_log logs/error.log debug;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

rtmp {
server {
listen 1935;

chunk_size 4096;

application myapp {
live on;
}
}
}

http {
server {
listen 8080;

location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}

location /stat.xsl {
root /home/arut-nginx-rtmp-module-e5d61f2/;
}

location / {
root /home/arut-nginx-rtmp-module-e5d61f2/test/rtmp-publisher;
}
}
}


4、启动nginx
/usr/local/nginx/sbin/nginx -c /home/arut-nginx-rtmp-module-e5d61f2/test/nginx.conf


5、用ffmpeg产生一个模拟直播源,向rtmp服务器推送
ffmpeg -re -i ~/2012.flv -f flv rtmp://192.168.11.75/myapp/test1
注意,源文件必须是H.264+AAC编码的。192.168.11.75是运行nginx的服务器IP


6、访问http://192.168.11.75:8080/stat,可以看到统计情况

7、网页播放测试,用nginx-rtmp-module自带的一个例子修改,在test/rtmp-publisher目录下

player.html

<!DOCTYPE html>
<html>
<head>
<title>RTMP Player</title>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashVars = {
streamer: 'rtmp://192.168.11.75/myapp',
file:'test1'
};
swfobject.embedSWF("RtmpPlayer.swf", "rtmp-publisher", "500", "400", "9.0.0", null, flashVars);
</script>
</head>
<body>
<div id="rtmp-publisher">
<p>Flash not installed</p>
</div>
</body>
</html>

访问http://192.168.11.75:8080/player.html,可以播放。用三星P7500安卓平台也可以播放,就是播放大视频会很卡

8、HLS测试(2013-4-20更新)

修改测试的配置文件

rtmp

...

application myapp {
live on;
hls on;
hls_path /tmp/app;
hls_fragment 5s;
}
...

http

...

location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
}
alias /tmp/app;
expires -1;
}

配套的测试html文件

<!DOCTYPE html>
<html>
<head>
<title>HLS Player</title>
</head>
<body>
<video height="270" width="480" controls>
<source src="http://211.154.154.80:8080/hls/test1.m3u8" type="application/vnd.apple.mpegurl" />
<p class="warning">Your browser does not support HTML5 video.</p>
</video>
</body>
</html>


nginx-rtmp-module还有许多其他特性,例如支持FLV/MP4的点播、HLS直播、多worker工作模式、push and pull工作模式等,以后慢慢挖掘

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值