實驗目的:讓Nginx支持flv和mp4格式文件,同時支持Rtmp協議;同時打開rtmp的hls功能
資料:
HTTP實時流媒體(縮寫是HLS)是一個由蘋果公司提出的基於HTTP的流媒體網絡傳輸協議。
使用的ffmpeg來完成對FLV,MP4,MP3等格式的轉化(點播實驗特點描述:暫未添加不測試)
一,準備工作
模塊:nginx_mod_h264_streaming(支持H264編碼的視頻)
模塊:http_flv_module支持FLV
模塊:http_mp4_module支持MP4
下載地址:
http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
http://nginx.org
https://github.com/arut/nginx-rtmp-module
1,安裝依賴包:
#yum的-Y安裝GCC的glibc的glibc-devel nasm的pkgconfig庫與開發OpenSSL的開發外籍發育gettext的發育libtool的mhash.x86_64 Perl的精華,SHA1.x86_64
2,安裝git的工具:
目錄#mkdir軟源
#CD軟
#wget的http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
#用tar xzvf git-latest.tar.gz的
#CD的git-2013-02-04
#autoconf的
#。/ configure時
#&& make install的
#GIT - 版本
Git版本1.8.1.GIT區
#CD。
3,安裝的ffmpeg及其依賴包:
+ + + + + + + + yasm的+ + + + + + + + + + +
#wget的http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
#用tar xzvf yasm的-1.2.0.tar.gz
#CD yasm的-1.2.0
#。/ configure時
#
#make install的
#CD。
+ + + + + + + + x264的+ + + + + + + + + + +
#Git克隆的git :/ / git.videolan.org/x264
#CD X264
#。/ configure時加入 - enable-共享
#
#make install的
#CD。
+ + + + + + + + + LAME + + + + + + + + + + +
#wget的http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
#用tar xzvf跛腳3.99.5.tar.gz
#CD跛腳3.99.5
#。/ configure時加入 - enable-nasm的
#
#make install的
#CD。
+ + + + + + + +的libogg + + + + + + + + + + +
#wget的http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
#用tar xzvf的libogg-1.3.0.tar.gz
#CD的libogg-1.3.0
#。/ configure時
#
#make install的
#CD。
+ + + + + + + +的libvorbis + + + + + + + + + + +
#wget的http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
#用tar xzvf的libvorbis-1.3.3.tar.gz
#CD的libvorbis-1.3.3
#。/ configure時
#
#make install的
#CD。
+ + + + + + + + libvpx + + + + + + + + + + +
#Git克隆http://git.chromium.org/webm/libvpx.git
#CD libvpx
#。/ configure時加入 - enable-共享
#
#make install的
#CD。
+ + + + + + + + FAAD2 + + + + + + + + + + +
#wget的http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
#的tar zxvf FAAD2,-2.7.tar.gz
【#CD FAAD2-2.7
#。/ configure時
#
#make install的
#CD。
+ + + + + + + + + FAAC + + + + + + + + + + +
#wget的http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
#焦油zxvf FAAC-1.28.tar.gz
#CD FAAC-1.28
#。/ configure時
#
#make install的
#CD。
+ + + + + + + + XVID + + + + + + + + + + +
#wget的http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
#焦油zxvf xvidcore-1.3.2.tar.gz
#CD xvidcore /製造/通用
#。/ configure時
#
#make install的
CD ..
#Git克隆的git的:/ / source.ffmpeg.org / FFMPEG
#CD的ffmpeg
#。/配置的 - prefix = /選擇/ FFMPEG / - 使版本3加入 - enable-libvpx了 - enable-libfaac - 啟用libmp3lame - 啟用的libvorbis了 - enable-libx264 - 使libxvid - 使共用了 - enable-GPL - 啟用postproc - 啟用非自由了 - enable-avfilter了 - enable-pthreads的
#&& make install的
#CD。
修改/ etc / ld.so.conf文件如下:
包括在ld.so.conf.d / *。CONF
/ lib目錄
/ lib64目錄
/ usr / lib目錄
位於/ usr/lib64
的/ usr / local / lib目錄
/ usr/local/lib64
的/ opt / ffmpeg的/ lib目錄
#ldconfig的
二,安裝Nginx的相關模塊
#焦油zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
#git的克隆的git :/ / github.com / arut / nginx的RTMP-module.git
#焦油zxvf PCRE-8.12.tar.gz
#CD PCRE 8.12
#。/ configure時
#&& make install的
#焦油zxvf nginx的1.2.6.tar.gz
#CD nginx的1.2.6
#。/配置的 - prefix = / USR /本地/ nginx的 - 附加模塊= ../nginx_mod_h264_streaming-2.2.7 - 與http_flv_module的 - 與http_gzip_static_module的 - http_stub_status_module - 與http_mp4_module - - 添加模塊=。。/ nginx的RTMP模塊 - 添加模塊。/ nginx的,RTMP模塊/ HLS-CC-OPT = -I/opt/ffmpeg/include - LD- -OPT ='-L/opt/ffmpeg/lib的WL-rpath選項= /選擇/ ffmpeg的/ lib目錄“
#&& make install的
用戶nobody人;
worker_processes 4;
error_log中日誌/ nginx_error.log的信息;
PID日誌/ nginx.pid;
worker_rlimit_nofile 51200;
事件
{
使用epoll的;
worker_connections 51200;
}
#rtmp_auto_push;
RTMP {
服務器{
聽1935年;
應用VOD {
玩的/ opt /媒體/ nginxrtmp / FLV;
}
}
}
HTTP
{
包括的mime.types;
default_type應用程序/八位字節流;
server_names_hash_bucket_size 128;
client_header_buffer_size 32K;
large_client_header_buffers 4 32K;
client_max_body_size 50米;
limit_conn_zone $ binary_remote_addr區侏羅紀:256K;
limit_conn_log_level通知;
發送文件;
tcp_nopush;
keepalive_timeout 6000#測試並發臨時調大
TCP_NODELAY;
gzip壓縮;
gzip_min_length 1K;
gzip_buffers 4 16K;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types文/簡單的應用程序/ X的JavaScript文本/ XML / CSS應用;
gzip_vary;
#日誌格式
log_format主要的$ REMOTE_ADDR - $ REMOTE_USER [$ time_local]“請求”“
'的狀態$ body_bytes_sent“HTTP_REFERER”
'“$ HTTP_USER_AGENT”HTTP_X_FORWARDED_FOR“;
#支持FLV
服務器
{
聽8081;
SERVER_NAME 192.168.0.33;
根目錄的/ opt /酒館/媒體/ nginx的#HTTP協議時候,FLV視頻位置
位置〜*。(FLV |瑞士法郎| MP4 | WMA | WMV)$ {
valid_referers沒有阻止。xxxx.com http://localhost的;
如果($ invalid_referer){
返回403;
}
}
位置〜\ FLV $ {
FLV;
limit_conn一個20#限制客戶端並發連接數
limit_rate 200K#限制每客戶端最大帶寬
}
位置〜\ MP4 $ {
FLV;
limit_conn一個20;
limit_rate 20萬;
}
ACCESS_LOG主要日誌/ nginxflv_access.log;
}
服務器
{
聽8082;
SERVER_NAME 192.168.0.33;
指數的index.html;
位置/ {
根目錄的/ opt /酒館/媒體/ nginx的RTMP;
}
ACCESS_LOG主要日誌/ nginxrtmpflv_access.log;
}
服務器{
聽8080;
位置/ STAT {
rtmp_stat;
rtmp_stat_stylesheet stat.xsl;
}
位置/ stat.xsl {
根目錄的/ opt /酒館/軟/ nginx的RTMP模塊的;
}
位置/ {
根目錄的/ opt /酒館/軟/ nginx的RTMP模塊的/測試/ RTMP發行的;
}
}
http://192.168.0.33:8080/stats查看RTMP客戶請求信息
http://192.168.0.33:8081/index.html查看nginx的HTTP協議時候的FLV視頻
http://192.168.0.33:8082/index.html查看nginx的RTMP協議時候的FLV視頻
四,基本功能測試:
播放器採用開源播放器jwplayer,將播放器放到index.html的同級目錄下
NGINX-HTTP測試頁面的index.html(切記HTTP的時候需要給視頻添加暫未添加關鍵幀)
<!DOCTYPE HTML PUBLIC“ - / / W3C / / DTD XHTML 1.0 / / EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>測試nginx的HTTP </ TITLE>
</ HEAD>
<BODY>
<div id="myElement"> </ DIV>
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="360">
<param name="movie" value="player.swf"
<param name="quality" value="high"
<param name="wmode" value="opaque"
<param name="swfversion" value="6.0.65.0"
<param name="flashvars" value="type=http&file=http://192.168.0.33:8081/2.flv&autostart=true">
<EMBED SRC =“player.swf”WIDTH =“480”HEIGHT =“360”質量=“高”PLUGINSPAGE的=“http://www.macromedia.com/shockwave/download/i
ndex.cgi?P1_Prod_Version = ShockwaveFlash“FlashVars的”類型= HTTP和文件http://192.168.0.33:8081/2.flv&autostart=true“WMODE =”opaq
UE“/>
</ OBJECT>
</ BODY>
</ html>
NGINX RTMP測試頁面的index.html
<!DOCTYPE HTML PUBLIC“ - / / W3C / / DTD XHTML 1.0 / / EN”“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE> nginx的RTMP </ TITLE>
</ HEAD>
<BODY>
<div id="myElement"> </ DIV>
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="360">
<param name="movie" value="player.swf"
<param name="quality" value="high"
<param name="wmode" value="opaque"
<param name="swfversion" value="6.0.65.0"
<param name="flashvars" value="streamer=rtmp://192.168.0.33:1935/vod&file=2.flv&autostart=true">
<EMBED SRC =“player.swf”WIDTH =“480”HEIGHT =“360”質量=“高”PLUGINSPAGE的=“http://www.macromedia.com/shockwave/download/i
ndex.cgi?P1_Prod_Version = ShockwaveFlash“FlashVars的”流光RTMP :/ / 192.168.0.33:1935 /視頻點播和文件2.flv和自動啟動=真“的wmode =”O
Paque聯合“/>
</ OBJECT>
</ BODY>
</ html>
頁面能打開正常播放就說明配置是正確的。
五,並發測試
NGINX-HTTP採用LoadRunner的測試(略)
NGINX的RTMP採用開源軟件flazr測試:
前提需要安裝JDK軟件
:/ / client.bat RTMP 192.168.0.33:1935 / vod/2.flv的負載500
這裡的500是並發數
借鑒地址:
https://github.com/arut/nginx-rtmp-module/wiki/Examples
http://blog.sina.com.cn/s/blog_438308750100ez27.html
http://space.itpub.net/27043155/viewspace-735288
http://riches.blog.51cto.com/1167414/649598
https://github.com/arut/nginx-rtmp-module
http://www.yeeach.com
利用nginx搭建http和rtmp協議的流媒體服務器
版主: stnet253
誰在線上
正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客