視頻有兩總髮布方式nginx
1、HTTP方式c++
這種方式要下載FLV視頻文件到本地播放,一旦FLV視頻文件下載完成,就不會消耗服務器的資源和帶寬,可是拖動功能沒有RTMP/RTMP流媒體方式強大,不少視頻網站都是用HTTP方式實現的,如:YouTube,土豆,酷6等git
2、RTMP/RTMP流媒體方式github
這種方式不用下載FLV視頻文件到本地,能夠實時的播放flv文件,能夠任意拖拽播放進度條,可是比較消耗服務器的資源web
實驗目的:
讓Nginx支持flv和mp4格式文件,支持RTMP協議的直播和點播
服務器
準備工做
Nginx: http://nginx.org
模塊: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
https://github.com/arut/nginx-rtmp-module
一、安裝依賴包:
#yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64
二、安裝相關工具包
1). 安裝git,之後後面一些程序須要安裝下載須要用到git
# mkdir soft-source
# cd soft-source
# wget http://codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xz
# xz -d git-latest.tar.xz
# tar xzvf git-latest.tar ide
# cd git-2014-06-27工具
# autoconf
# ./configure
# makepost
若是make報錯以下,執行:yum install perl-ExtUtils-Embed -y網站
#make install
# git --version 看到版本輸出證實安裝成功
# cd ..
2). zlib
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
# ./configure
# make
# make install
# cd ..
3). pcre
# wget http://exim.mirror.fr/pcre/pcre-8.12.tar.gz
# tar zxvf pcre-8.12.tar.gz
# cd pcre-8.12
# ./configure
# make
若是make過程出現瞭如下報錯,請安裝:yum -y install gcc gcc-c++,而後再從新執行./configure 再make
#make install
# cd ..
4). yadmi
yadmi的做用是爲flv文件添加關鍵幀,才能實現拖動播放
# wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz/download
# tar xzvf yamdi-1.4.tar.gz
# cd yamdi-1.4
# make && make install
# cd ..
使用方法:
# yamdi -i input.flv -o out.flv
給input.flv文件 添加關鍵幀,輸出爲out.flv文件
5). OpenSSL
# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
# tar -zxvf openssl-1.0.1c.tar.gz
# ./config
# make
# make install
三、安裝ffmpeg及其依賴包:
1). 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
# make install
# cd ..
2). x264
# git clone git://git.videolan.org/x264
# cd x264
# ./configure --enable-shared
# make
# make install
# cd ..
3). LAME
# wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
# tar xzvf lame-3.99.5.tar.gz
# cd lame-3.99.5
#./configure --enable-nasm
# make
# make install
# cd ..
4). 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
# make install
# cd ..
5). 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
# make install
# cd ..
6). libvpx
# git clone http://git.chromium.org/webm/libvpx.git
# cd libvpx
# ./configure --enable-shared
# make
# make install
# cd ..
7). 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
# make install
# cd ..
8). FAAC
# wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
# tar zxvf faac-1.28.tar.gz
# cd faac-1.28# ./configure
# make
# make install
# cd ..
9). Xvid
# wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
# tar zxvf xvidcore-1.3.2.tar.gz
# cd xvidcore/build/generic
# ./configure
# make
# make install
# cd ..
10). ffmpeg
# git clone git://source.ffmpeg.org/ffmpeg
# cd ffmpeg
# ./configure --prefix=/opt/ffmpeg/ --enable-version3
--enable-libvpx --enable-libfaac --enable-libmp3lame
--enable-libvorbis --enable-libx264 --enable-libxvid
--enable-shared --enable-gpl --enable-postproc --enable-nonfree
--enable-avfilter --enable-pthreads
# make && make install# cd ..
修改/etc/ld.so.conf以下:
include ld.so.conf.d/*.conf
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/ffmpeg/lib
# ldconfig
2、安裝Nginx相關模塊
1. 模塊安裝
# wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
# tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
# git clone git://github.com/arut/nginx-rtmp-module.git
2. 建立用戶和組
# groupadd www
# useradd -g www www
3. nginx安裝# wget http://nginx.org/download/nginx-1.6.0.tar.gz# tar zxvf nginx-1.6.0.tar.gz# cd nginx-1.6.0