準備軟體:
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 #為視頻檔案