ffmepg以及x264的編譯

Windows環境:

MSYS2以及MinGW:

1、從​http://msys2.github.io獲取並安裝Msys2
2、使用pacman -S 安裝必須的包,如:make、 gcc(64位請安裝:mingw-w64-x86_64-gcc)、diffutils
3、如果使用visual studio編譯,請將msys2安裝目錄下的/usr/bin/link.exe替換爲vc的link.exe
4、下載yasm,將其放在msys的路徑下或者window路徑下均可,如:[msys安裝目錄]/usr/bin/
5、啓動MSYS2,可以從菜單或者找到msys2的安裝目錄,直接執行msys2_shell.bat,如果需要MINGW環境,則執行mingw64_shell.bat(64位),或者mingw32_shell.bat

X264編譯:

工程不支持採用msvc編譯,採用前面安裝的MinGW編譯器
2、運行configure,我使用的配置項爲:
./configure --disable-cli --enable-shared --enable-win32thread --extra-ldflags=-Wl,--output-def=libx264.def --prefix=../builds  --host=mingw64
注意--host選項,如果沒有指定mingw*(只要是以mingw開頭即可),會報錯:
Unknown system unknown-msys, edit the configure
按照提示更新config.guess文件在我的系統中是沒起作用。
3、進入visual studio的命令提示符,運行:
lib /def:x264.def /machine:x64 (如果是32位系統,則爲/machine:X86)
注意:生成的lib文件,採用msvc編譯ffmpeg工程時,前綴:“lib"得去掉,要不會報錯
ERROR: libx264 not found
開是以爲路徑不對,查看config.log日誌文件才能找到原因:
LINK : fatal error LNK1181: cannot open input file 'x264.lib'
ERROR: libx264 not found

FFMpeg的編譯:

FFMpeg支持MinGW以及visual studio編譯,兩者的configure選項在指定鏈接庫的路徑時有差異:
msvc:
--extra-ldflags=-LIBPATH:../builds/lib
mingw:
--extra-ldflags=-L../builds/lib
我使用MSVC的配置項爲(保留調試信息,以動態庫方式鏈接,64位系統):
./configure --toolchain=msvc --enable-yasm --enable-asm --enable-shared --disable-static --disable-stripping --arch=x86_64 --enable-debug --enable-libx264 --enable-gpl --prefix=../builds --extra-cflags=-I../builds/include --extra-ldflags=-LIBPATH:../builds/lib

注意:--disable-optimizations配置會產生錯誤:(vs2013、2015,x86\x86_64、windows 2012 R2):
cpu.o : error LNK2019: unresolved external symbol ff_get_cpu_flags_aarch64 referenced in function av_get_cpu_flags
cpu.o : error LNK2019: unresolved external symbol ff_get_cpu_flags_arm referenced in function av_get_cpu_flags
cpu.o : error LNK2019: unresolved external symbol ff_get_cpu_flags_ppc referenced in function av_get_cpu_flags
float_dsp.o : error LNK2019: unresolved external symbol ff_float_dsp_init_aarch64 referenced in function avpriv_float_dsp_init
float_dsp.o : error LNK2019: unresolved external symbol ff_float_dsp_init_arm referenced in function avpriv_float_dsp_init
float_dsp.o : error LNK2019: unresolved external symbol ff_float_dsp_init_ppc referenced in function avpriv_float_dsp_init
float_dsp.o : error LNK2019: unresolved external symbol ff_float_dsp_init_mips referenced in function avpriv_float_dsp_init</span>

Linux環境:

在ubuntu15.04下,yasm以及x264庫都能通過apt來安裝:
sudo apt-get install yasm libx264-dev
如果需要調試信息,在配置ffmpeg前先執行:
export CFLAGS=-g
然後:
./configure --toolchain=msvc --enable-yasm --enable-asm --enable-shared --disable-static --enable-debug --disable-optimizations --enable-libx264 --enable-gpl --disable-stripping  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章