nginx搭建mp4和flv播放器

nginx搭建mp4、flv流媒体服务器

需要用到的源码包有

nginx-1.3.8.tar.gz(http://nginx.org/download/nginx-1.3.8.tar.gz)

pcre-8.12.tar.gz(ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz)

nginx_mod_h264_streaming-2.2.7.tar.gz(http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Nginx-Version2)。

yamdi-1.8.tar.gz(http://sourceforge.net/projects/yamdi/files/yamdi/1.8/yamdi-1.8.tar.gz/download)

其中pcre-8.12是与perl兼容的正则表达式库模块,nginx-1.3.8是应用服务器主程序,nginx_mod_h264_streaming-2.2.7是MP4流媒体支持模块,yamdi是用来为FLV提供meta信息的。

安装步骤如下:

1:解压缩各个压缩包

tar zxvf nginx-1.0.4.tar.gz

tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

tar zxvf pcre-8.12.tar.gz

tar zxvf yamdi-1.8.tar.gz

2:安装pcre

cd pcre-8.12

./configure

make

make install

3:安装yamdi

cd yamdi-1.8

make && make install

4:安装nginx

cd nginx-1.3.8

./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --with-debug --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_sub_module --with-http_realip_module

之后make,

会报错【ngx_http_streaming_module.c:158: 错误:‘ngx_http_request_t’ 没有名为 ‘zero_in_uri’ 的成员】之类的错误。这需要修改nginx_mod_h264_streaming-2.2.7的源代码:修改ngx_http_streaming_module.c,注释掉

if (r->zero_in_uri)

{

return NGX_DECLINED;

}

这一段。

之后make clean,之后重新configure,重新make,之后make install。

之后执行命令nginx,启动nginx服务器。访问http://ip:80出现Welcome to nginx! 时证明nginx安装成功。

5:配置nginx

Nginx安装完成之后安装路径在/usr/local/nginx。打开/usr/local/nginx/conf,修改nginx.conf配置文件,添加MP4/FLV支持。

在server配置中添加如下配置即可

location ~ \.mp4$ {

mp4;

}

location ~ \.flv$ {

flv;

}

限速:

limit_rate_after 10m;

limit_rate 512k;

6:FLV没有metadata关键帧数据

可以使用yamdi或flvtool2为你的flv视频添加关键帧

yamdi -i source.flv -o dest.flv

flvtool2 -U source.flv

测试的话如下:

基本上已经设置完毕,但是此时我们测试的时候还需要一个支持拖拽播放的flash播放器,开源的JW Player就可以实现这样的功能,下载地址:http://www.longtailvideo.com/players/jw-flv-player/。