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  


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