Rootop 服务器运维与web架构

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

准备软件:
nginx-1.6.0.tar.gz
yamdi-1.9.tar.gz

yamdi 是渐进式流支持模块,抓取视频资源关键帧实现播放时的随意拖动效果
下载地址:http://ncu.dl.sourceforge.net/project/yamdi/yamdi/1.9/yamdi-1.9.tar.gz

flv视频可以通过http或rtmp方式发布。这里用http方式。

安装nginx及mp4支持模块和flv模块:
nginx支持mp4模块下载地址:http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
下载后解压。

安装编译环境:

[root@localhost nginx-1.6.0]# yum install -y zlib zlib-devel pcre pcre-devel
[root@localhost nginx-1.6.0]# useradd -s /sbin/nologin www
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_ssl_module --user=www --group=www --with-http_flv_module --with-http_stub_status_module
[root@localhost nginx-1.6.0]# make && make install

make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.6.0′
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -D_LARGEFILE_SOURCE -DBUILDING_NGINX -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail \
-o objs/addon/src/ngx_http_h264_streaming_module.o \
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_h264_streaming_module.c
In file included from ../nginx_mod_h264_streaming-2.2.7/src/ngx_http_h264_streaming_module.c:2:
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: In function ‘ngx_streaming_handler’:
../nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ‘ngx_http_request_t’ has no member named ‘zero_in_uri’
make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] Error 1
make[1]: Leaving directory `/root/nginx-1.6.0′
make: *** [build] Error 2

出现一个错误,解决方法:

编辑/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c

[root@localhost src]# vim ngx_http_streaming_module.c

注释掉:
/* TODO: Win32 */
if (r->zero_in_uri)
{
return NGX_DECLINED;
}

重新make通过。

nginx配置文件:
[root@localhost nginx-1.6.0]# grep -v “#” /usr/local/nginx/conf/nginx.conf | grep -v “^$”

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;

location ~\.flv {
flv;
}

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

创建两个视频文件夹/usr/local/nginx/html/flv、/usr/local/nginx/html/mp4 存放视频文件。

安装yamdi实现拖动效果:
[root@localhost yamdi-1.9]# make && make install  #两步即可

给视频添加帧:
[root@localhost flv]# yamdi -i 1.flv -o test.flv  #给1.flv添加关键帧输出为test.flv

找一个flash播放器,下载地址:http://chinaapp-wordpress.stor.sinaapp.com/uploads/2013/08/player.swf   推荐wget方式下载。
测试:
浏览器访问: http://192.168.0.172/player.swf?type=http&file=flv/test.flv

192.168.0.172 #服务器ip地址
player.swf       #flash播放器程序
http                  #用http方式发布
flv                     #为路径
test.flv             #为视频文件

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3212.html

作者:Venus

服务器运维与性能优化

评论已关闭。