首页 > 代码库 > 用开源NGINX-RTMP-MODULE搭建FLASH直播环境

用开源NGINX-RTMP-MODULE搭建FLASH直播环境

1、将nginx和nginx-rtmp-module的源码包解压PS:nginx-rtmp-module网址https://github.com/arut/nginx-rtmp-module2、进入nginx的源代码目录,编译./configure --add-module=<path-to-nginx-rtmp-module> --without-http_rewrite_modulemakemake install3、写一个测试配置文件#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.conf5、用ffmpeg产生一个模拟直播源,向rtmp服务器推送ffmpeg -re -i ~/2012.flv -f flv rtmp://192.168.11.75/myapp/test1注意,源文件必须是H.264+AAC编码的。192.168.11.75是运行nginx的服务器IP6、访问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="http://www.mamicode.com/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安卓平台也可以播放,就是播放大视频会很卡 nginx-rtmp-module还有许多其他特性,例如支持FLV/MP4的点播、HLS直播、多worker工作模式、push and pull工作模式等,以后慢慢挖掘

用开源NGINX-RTMP-MODULE搭建FLASH直播环境