nginx搭建支持http和rtmp协议的流媒体服务器之三 【转】

来源:互联网 发布:举报网络电子邮箱地址 编辑:程序博客网 时间:2024/05/22 01:58

来自:http://blog.chinaunix.net/uid-26000296-id-4335088.html

四、配置Nginx,实现VOD,以RTMP方式播放FLV

1. 设置configure,nginx的补充编译,增加FLV和MP4功能。
# cd cd nginx-1.6.0 
# vim nginx_configure.sh
#!/bin/sh

echo "configure start ..."
./configure --prefix=/opt/nginx \
--add-module=../nginx_mod_h264_streaming-2.2.7 \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre=/opt/nginx_http_rtmp/pcre-8.12 \
--with-zlib=/opt/nginx_http_rtmp/soft_source/zlib-1.2.8 \
--user=www --group=www \
--add-module=../nginx-rtmp-module \
--with-cc-opt=-I/opt/ffmpeg/include \
--with-ld-opt=`-L/opt/ffmpeg/lib -Wl, -rpath=/opt/ffmpeg/lib`
echo "configure end!"
【保存并退出】
# chmod +x nginx_configure.sh
# ./nginx_configure.sh
# make && make install

http_flv_module和http_mp4_module即为对应的解析和seek功能支持。

2. 修改 conf/nginx.conf配置
# vim conf/nginx.conf
... 
worker_rlimit_nofile 51200;
events
{
  use epoll;
  worker_connections  51200;
}

# RTMP点播的配置
rtmp {
  server {
    listen 1935;
    chunk_size 4000;
    application vod {
      play /opt/pub/media/nginx/web/vod;  #点播媒体文件存放目录
    }
  }
}

http
{
  ... 
  # 配置RTMP虚拟机
  # VOD for FLV by RTMP
  server
  {
    listen 8080;
    location /stat
    {
      rtmp_stat all;
      rtmp_stat_stylesheet stat.xsl;
    }

    location /stat.xsl
    {
      root /opt/nginx_http_rtmp/nginx-rtmp-module/;   #在nginx-rtmp-module源码根目录
    }
  }
}

3. 启动Nginx
# /opt/nginx/sbin/nginx

4. 创建嵌入播放器的HTML页面
# cd /opt/pub/media/nginx/web
# vim rtmp_player.html

【保存并退出】

5. 测试
在浏览器输入栏中输入:

http://192.168.1.10/rtmp_player.html 



五、配置Nginx, 实现LIVE、以RTMP方式进行直播
1. 配置conf/nginx.conf
...
rtmp {
  server {
    listen 1935;
    chunk_size 4000;
    application vod {
      play /opt/pub/media/nginx/web/vod;
    }

    # Setting for LIVE
    application live {
      live on;
    }
  }
}
http
{
  ...
  # LIVE and VOD by RTMP
  server
  {
    listen 8080;
    location /stat
    {
      rtmp_stat all;
      rtmp_stat_stylesheet stat.xsl;
    }

    location /stat.xsl
    {
      root /opt/nginx_http_rtmp/nginx-rtmp-module/;
    }
  }
}

2. 重新加载Nginx
# /opt/nginx/sbin/nginx -s reload

3. 准备网页 rtmp_live.html
下载播放器jwplayer,并新建网页

4. 在浏览器输中输入
http://10.2.175.10/rtmp_live.html

5. 用nginx-rtmp-module自带的一个例子修改,在test/rtmp-publisher目录下player.html

Flash not installed

访问http://10.2.175.10/player.html


6. 使用ffmpeg推流
用ffmpeg产生一个模拟直播源,向rtmp服务器推送
# ./ffmpeg –i/usr/local/nginx/vod/flvs/a.flv-strict -2 -c:v libx264 -c:a aac -f flv rtmp://192.168.1.4/live/test

注意,
源文件必须是H.264+AAC编码的。
192.168.1.4是运行nginx的服务器IP,
live是applicatioin,
test是直播缓存流文件,需要与配置文件中的直播缓存文件名一样。

六、配置Nginx 支持HLS
暂时没有做测试,可见其它网文;
0 0
原创粉丝点击