2015年2月3日

CentOS 5/6 編譯安裝 ffmpeg

由於我需要 ffmpeg +faststart 的參數,讓 flash player 播放 mp4 時能馬上播放影片,但該參數只有在新版上才支援,看了一下 FFMpeg 官網的編譯手冊,決定自己編譯一套來用

※以下筆記是編譯 h264 、Theora 的影像編碼及 mp3、aac、ogg、libvorbis 聲音編碼格式,若有其他編碼需求的話就需要額外編譯套件


必要套件
shell># yum install autoconf automake gcc gcc-c++ git  libtool make nasm pkgconfig zlib-devel
shell># mkdir ~/ffmpeg_source
shell># cd ~/ffmpeg_source


編譯 yasm
shell># git clone --depth 1 git://github.com/yasm/yasm.git
shell># cd yasm
shell># autoreconf -fiv
shell># ./configure --prefix=/usr/local/ffmpeg
shell># make && make install

※若是 CentOS5 這種比較舊的系統會因為 autoconf 版本太舊無法用 git 下載的版本
請到 http://www.tortall.net/projects/yasm/releases 下載 tarball 編譯

編譯x264
設定環境變數,否則編譯 x264 會有問題
shell># export PATH="$PATH:/usr/local/ffmpeg/bin"
shell># cd ~/ffmpeg_source
shell># git clone --depth 1 git://git.videolan.org/x264
shell># cd x264
shell># ./configure --prefix=/usr/local/ffmpeg --enable-static
shell># make && make install

編譯 libfdk_aac
shell># cd ~/ffmpeg_source
shell># git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
shell># cd fdk-aac
shell># autoreconf -fiv
shell># ./configure --prefix=/usr/local/ffmpeg --disable-shared
shell># make && make install

※CentOS5 會出現 ./configure: line 3399: LT_INIT: command not found 錯誤
請下載 tarball 編譯
下載點:http://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-0.1.4.tar.gz

編譯 libmp3lame
shell># cd ~/ffmpeg_source
shell># curl -L -O http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz
shell># tar xzvf lame-3.99.5.tar.gz
shell># cd lame-3.99.5
shell># ./configure --prefix=/usr/local/ffmpeg --disable-shared --enable-nasm
shell># make && make install

※若連結失效請到 http://sourceforge.net/projects/lame 下載

編譯 libogg
shell># cd ~/ffmpeg_source
shell># curl -L -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
shell># tar xzvf libogg-1.3.2.tar.gz
shell># cd libogg-1.3.2
shell># ./configure --prefix=/usr/local/ffmpeg --disable-shared
shell># make && make install

※若連結失效請到 http://downloads.xiph.org/ 下載

編譯 libvorbis
shell># cd ~/ffmpeg_source
shell># curl -L -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
shell># tar xzvf libvorbis-1.3.4.tar.gz
shell># cd libvorbis-1.3.4
shell># ./configure --prefix=/usr/local/ffmpeg --disable-shared
shell># make && make install

編譯 libtheora
shell># cd ~/ffmpeg_source
shell># curl -O http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
shell># tar xzvf libtheora-1.1.1.tar.gz
shell># cd libtheora-1.1.1
shell># ./configure --prefix=/usr/local/ffmpeg --with-ogg=/usr/local/ffmpeg --disable-examples --disable-shared --disable-sdltest --disable-vorbistest
shell># make && make install

編譯 ffmpeg
shell># cd ~/ffmpeg_source
shell># git clone --depth 1 git://source.ffmpeg.org/ffmpeg
shell># cd ffmpeg
PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig" ./configure --prefix=/usr/local/ffmpeg --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libtheora
shell># make && make install

測試轉檔
shell>#  ffmpeg -i test-orig.mp4 -c:v libx264 -preset veryfast -b:v 250k -c:a libfdk_aac -b:a 64k -movflags +faststart test-output.mp4


沒有留言:

張貼留言