以前隨手記的筆記,翻出來,整理下哈
ffmpeg 在windows上的編譯還是比較麻煩的,而且如果mingw-gcc編譯的話,是無法在vs下調試的
所以以前剛開始玩ffmpeg的時候,費了一些功夫,用vs編譯調試ffmpeg,當然在mingw下調試也是可以的。
由於是之前的筆記,所以有些地方不是很詳細,主要記錄了一些關鍵的地方。
也可以直接下載編譯配置好的vs2013工程。
一、准備工具
1. msysgit 環境,https://github.com/msysgit/msysgit/
2. 然后下載yasm,pkg_config,glib的windows版,放置於bin目錄下
yasm 可以直接從官網下載,下載Win64 .exe 版本(vs版本有問題). 下載后改名為yasm.exe
pkg_config, http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip
glib,http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.18/glib_2.18.4-1_win32.zip
二、編譯ffmpeg
1. 搜索mingw中的link.exe, 改名或刪掉,因為和vs的link沖突
2.
export PKG_CONFIG_PATH=/mingw/lib/pkgconfig:/usr/local/lib/pkgconfig call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
3. configure ffmpeg,默認的編譯參數是O2優化,這樣不太方便調試
./configure --enable-shared --enable-memalign-hack --enable-gpl --enable-libx264 --enable-postproc --prefix=./vs2013_build/Release --toolchain=msvc --extra-cflags=-Id:/code/libx264 --extra-ldflags=-LIBPATH:d:/code/libx264
嘗試禁用優化,編譯時會產生大量錯誤,所以使用O1優化,這樣調試的時候還是不會被優化太多
./configure --enable-shared --enable-memalign-hack --enable-gpl --enable-libx264 --enable-postproc --prefix=./vs2013_build/Debug --toolchain=msvc --disable-optimizations --disable-stripping --enable-debug --optflags='-O1 -Zo -arch:SSE2' --extra-cflags='-Gy -MDd -Id:/code/libx264' --extra-ldflags='-OPT:REF -DEBUG -VERBOSE -LIBPATH:d:/code/libx264'
O1 優化,會把local variable優化掉,其他應該沒太大影響
-Zo參數 (vs2012中是/d2Zi+) 允許運行在優化模式下調試(注意不能刪除config.mk中/Z7參數)
/Gy Enables function-level linking.
-arch::SSE2 解決SSE MMX等指令無法link.
四、 編譯好的lib嵌入到VS工程中,還需要做些修改
error C2054: expected '(' to follow 'inline'
error C2085: 'av_cmp_q' : not in formal parameter list
直接改project->[setting]->[c/c++]->Preprocessor definitions:編輯框里輸入inline=__inline即可。
inline=__inline
還需要定義
snprintf=_snprintf
ffplay.c 中cmdutils.c print_all_libs_info
注釋
//PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
//PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
修改 config.h
#define HAVE_STRUCT_POLLFD 1
五、編譯x264
msysgit 以-enable-win32thread 參數編譯就不會依賴libgcc 和pthread
./configure --enable-shared --host=i686-pc-mingw32 --enable-static --enable-win32thread pexports libx264-142.dll > libx264-142.def lib /machine:X86 /def:libx264-142.def
msys編譯的話,會有個問題是gcc版本太老了。
另外msysgit,中可能需要刪除configure中一些gcc編譯參數 -Wl,--nxcompat -Wl,--dynamicbase,否則可能導致gcc無法識別。報錯為 no working c compiler 的錯誤