2、安裝Nginx相關模塊html
1.環境準備nginx
yum install –y pcre pcre-develgit
yum install –y zlib zlib-develgithub
yum -y install openssl openssl-develapp
2.下載nginx及rtmp模塊ide
wget http://nginx.org/download/nginx-1.6.2.tar.gz工具
tar xzvf nginx_1.6.2.tar.gz測試
git clone git://github.com/arut/nginx-rtmp-module.gitspa
3.編譯nginx-rtmpdebug
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_stub_status_module
若是須要安裝pcre,則 yum -y install pcre-devel openssl openssl-devel
make
make install
安裝完成後,nginx位於/usr/local/nginx/sbin目錄下,配置文件nginx.conf在/usr/local/nginx/conf目錄下
++++++++測試nginx是否安裝正確+++++++++++
#cd /usr/local/nginx
#./sbin/nginx -c ./conf/nginx.conf
打開網頁http://localhost,若是顯示Welcome表示安裝下正確,若是沒有顯示,請查看一下nginx的日誌。
++++++++測試RTMP+++++++++++
修改/usr/local/nginx/conf/nginx.conf的內容以下:
#debug
daemon off;
master_process off;
error_log ./error.log debug;
events{
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#live
application myapp {
live on;
}
}
從網上下載一款RTMP推流工具,我使用的OBS(Open Broadcaster Software),開始推流rtmp://your_ip/myapp/test,使用播放器(http://www.cutv.com/demo/live_test.swf)查看是否正常。
++++++++測試HLS切片功能+++++++++++
修改/usr/local/nginx/conf/nginx.conf的內容以下:
#debug
daemon off;
master_process off;
error_log ./error.log debug;
events{
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#live
application myapp {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 2s;
hls_playlist_length 6s;
}
}
}
#HTTP
http{
server {
listen 80;
#welcome
location / {
root html;
index index.html index.htm;
}
#hls
location /hls {
types {
application/vnd.apple.mpegusr m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
}
使用VLC或iPAD上的播放器進行查看 http://yourip/hls/test.m3u8。
++++++++測試FFMPEG轉碼功能+++++++++++
修改/usr/local/nginx/conf/nginx.conf的內容以下:
#debug
daemon off;
master_process off;
error_log ./error.log debug;
events{
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#live
application myapp {
live on;
exec /opt/ffmpeg/bin/ffmpeg -i rtmp://localhost/myapp/$name
-c:a copy -c:v libx264 -b:v 512K -g 30 -f flv rtmp://localhost/hls/$name_low;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_nested on;
hls_fragment 2s;
hls_playlist_length 6s;
hls_variant _hi BANDWIDTH=640000;
}
}
}
#HTTP
http{
server {
listen 80;
#welcome
location / {
root html;
index index.html index.htm;
}
#hls
location /hls {
types {
application/vnd.apple.mpegusr m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
}
使用ffmpeg轉碼時,
exec /opt/ffmpeg/bin/ffmpeg -i rtmp://localhost/myapp/$name
-c:a copy -c:v libx264 -b:v 512K -g 30 -f flv rtmp://localhost/hls/$name_low;
僅對視頻進行轉碼,音頻不作處理,同時向流從myapp轉推到hls, hls_variant會生成一個多碼率的m3u8文件,同時把切片文件存放到test_low目錄下,訪問多碼率時,直接訪問http://yourip/hls/test.m3u8,根據這個m3u8中的實現的內容訪問相應的碼流,在本例中,實際碼流URL爲http://yourip/hls/test_low/index.m3u8