nginx搭建flv和mp4流媒體伺服器例子

來源:互聯網
上載者:User

準備軟體:

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             #為視頻檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.