最近在研究ffmpeg的編譯,以前使用的Ubuntu,須要安裝虛擬機,很是麻煩,因此後來改研究在Windows平臺編譯。html
一開始遇到不少挫折,參考了網上不少的帖子,但要麼不全要麼內容已過時,通過個人反覆試驗或研究,最終搞定了。在此記錄一下,也但願能對編譯ffmpeg的朋友們有所幫助。git
首先安裝Mingw和Msys平臺,能夠參考我其餘幾篇轉載的帖子,基本都不會有問題shell
而後從ffmpeg官網下載源碼,能夠選擇最新的Git測試版或穩定版(我下載的是ffmpeg-1.1),編譯方式都大同小異,若是不須要第三方庫的話,編譯選項以下(shared和static只能有一個爲enable):windows
./configure --enable-static --disable-shared --enable-memalign-hack --arch=x86 --target-os=mingw32 --pkg-config=pkg-config --enable-runtime-cpudetect --disable-debug --enable-pthreads make make install
下面介紹各類第三方庫的編譯。爲了方便編譯,全部庫均先解壓到[mingw]/msys/1.0/home/[username]根目錄,而後在mingw shell中cd命令定位到庫文件夾下。frontend
X264ide
http://www.videolan.org/developers/x264.html,下載最新版本的git測試
編譯安裝:
./configure --enable-win32thread
make
make install
cp -iv x264.h x264_config.h /mingw/include
cp -iv libx264.a /mingw/lib
cp -iv x264.pc /mingw/lib/pkgconfig ui
ffmpeg編譯參數:--enable-gpl --enable-libx264.net
LAME 3.99.5debug
http://sourceforge.net/projects/lame/files/lame/,下載lame-3.99.5.tar.gz
編譯安裝:
./configure --enable-export=full --enable-static --disable-shared --disable-frontend
make
make install
ffmpeg編譯參數:--enable-libmp3lame
librtmp 2.3
http://rtmpdump.mplayerhq.hu/,下載rtmpdump-2.3.tgz(網上有帖子說是rtmpdump-2.3-windows.zip,但我下載了,裏面都沒有makefile)
librtmp依賴於zlib和openssl,因此要先編譯兩個庫,見下面:
Zlib 1.2.7
http://zlib.net/,下載zlib-1.2.7.tar.gz
make -f win32/Makefile.gcc
cp -iv zlib1.dll /mingw/bin
cp -iv zconf.h zlib.h /mingw/include
cp -iv libz.a /mingw/lib
cp win32/Makefile.gcc Makefile.gcc
ffmpeg編譯參數:--enable-zlib
OpenSSL 1.0.1
http://www.openssl.org/,下載openssl-1.0.1c.tar.gz
./configure mingw --prefix=`pwd`/win32libs -DL_ENDIAN -DOPENSSL_NO_HW
make
make install
編譯完成後,把當前目錄的win32libs子文件夾下的include和lib分別拷貝到mingw32,以供後面librtmp使用
注意:openssl的編譯須要在安裝Mingw時包含Perl 5環境,若是沒有的話,可到網上下載(我用的是5.16.2版,見http://www.cpan.org/src/README.html),下載後編譯參數以下:
./Configure -des -Dprefix=$HOME/localperl make make test make install
ffmpeg編譯參數:--enable-nonfree --enable libopenssl
librtmp的編譯命令以下:
make SYS=mingw
make SYS=mingw install
注意:編譯ffmpeg時會提示「ERROR: librtmp not found」錯誤,主要是由於一些library沒連接好,不知道是否爲ffmpeg的Bug。解決辦法是在configure文件中「enabled librtmp」一行最後要添加「 -lwinmm -lwsock32 -lgdi32」
ffmpeg編譯參數:--enable-librtmp
xvidcore 1.3.2
http://www.xvid.org,下載xvidcore-1.3.2.tar.gz
編譯安裝:
cd xvidcore/build/generic
./configure --prefix=/mingw
執行到這裏後,搜索xvidcore/build/generic 目錄下面全部文件(個人版本是platform.inc中有兩處)中的 -mno-cygwin 這個選項, 這個選項已經不被GCC支持,所有刪除後繼續。
make
make install
cp -iv \=build/xvidcore.dll.a /mingw/lib/libxvidcore.dll.a
ffmpeg編譯參數:--enable-libxvid
libgsm 1.0.13-3
http://libgsm.sourcearchive.com/,下載libgsm_1.0.13.orig.tar.gz
編譯安裝:
make
mkdir /mingw/include/gsm
cp inc/gsm.h /mingw/include/gsm
cp lib/libgsm.a /mingw/lib
ffmpeg編譯參數:--enable-libgsm
供libvorbis和libtheora用
http://www.xiph.org/downloads/,下載libogg-1.1.4.tar.gz
解壓,編譯安裝:
./configure –prefix=/olibs –disable-shared
make
make install
LIBVorbis 1.3.3
http://xiph.org/downloads/,下載libvorbis-1.3.3.tar.gz
編譯安裝:
./configure
make
make install
ffmpeg編譯參數:--enable-libvorbis
LIBTheora 1.1.1
http://xiph.org/downloads/,下載libtheora-1.1.1.tar.bz2
編譯安裝:
./configure
make
make install
ffmpeg編譯參數:--enable-libtheora
LIBSpeex 1.2rc1
http://xiph.org/downloads/,下載speex-1.2rc1.tar.gz
./configure
make
make install
ffmpeg編譯參數:--enable-libspeex
加入以上第三方庫之後,在ffmpeg中就能夠下面的參數進行編譯:
./configure --enable-static --disable-shared --enable-memalign-hack --arch=x86 --target-os=mingw32 --pkg-config=pkg-config --enable-runtime-cpudetect --disable-debug --enable-pthreads --enable-gpl --enable-bzlib --enable-libx264 --enable-libgsm --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libxvid --enable-zlib--enable-openssl --enable-librtmp --enable-nonfree --enable-libspeex
make
make install