ffmpeg第三方庫編譯記錄


最近在研究ffmpeg的編譯,之前使用的Ubuntu,需要安裝虛擬機,非常麻煩,所以后來改研究在Windows平台編譯。

一開始遇到很多挫折,參考了網上很多的帖子,但要么不全要么內容已過期,經過我的反復試驗或研究,最終搞定了。在此記錄一下,也希望能對編譯ffmpeg的朋友們有所幫助。

首先安裝Mingw和Msys平台,可以參考我其他幾篇轉載的帖子,基本都不會有問題

然后從ffmpeg官網下載源碼,可以選擇最新的Git測試版或穩定版(我下載的是ffmpeg-1.1),編譯方式都大同小異,如果不需要第三方庫的話,編譯選項如下(shared和static只能有一個為enable):

./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命令定位到庫文件夾下。

 

 

X264

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 

ffmpeg編譯參數:--enable-gpl --enable-libx264


LAME 3.99.5

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

 

libogg

 

供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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM