上篇文章完成了 mingw下使用vs2015编译器编译FFMPEG(http://blog.csdn.net/anbinger2013/article/details/49387377),那么如何进一步 支持x264的。显然直接使用mingw下用gcc生成的静态库(libx264.a)文件是不妥的,会导致很多linker错误,提示许多未定义的函数。而且gcc产生的静态库兼容性不好,经常出现莫名其妙的运行死机错误。
另一种思路是在mingw下用vs来编译x264,但是x264的工具链没有ffmpeg的完善,不知道如何实现,网上的资料也比较少。
此处的方案是使用mingw下gcc生成的DLL来实现对X264的支持。
步骤如何:
1.参考 ffmpeg官网 http://ffmpeg.org/platform.html,
make sure any other headers and libs you want to use, such as zlib, are located in a spot that the compiler can see. Do so by modifying the LIB
and INCLUDE
environment variables to include the Windows-style paths to these directories. Alternatively, you can try and use the --extra-cflags
/--extra-ldflags
意思是在WIN7的我的电脑里创建LIB和INCLUDE变量或者使用mingw的--extra-cflags和--extra-ldfags,我没有使用第一种方法,总觉得添加这样的全局环境变量不合适,第二种方法试了,但是总是提示找不到 x264库。所以本人直接修改 msys.bat文件,在call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"语句下面加上:
set INCLUDE=d:\mingw\msys\1.0\local\include;%INCLUDE%
set LIB=d:\mingw\msys\1.0\local\lib;%LIB%
2.下载x264源代码,使用mingw gcc编译生成动态库并make install
3. 参考 mingw 下编译的libx264 DLL 如何在vs2010里使用 (http://blog.csdn.net/anbinger2013/article/details/48998289), 制作x264.lib并放到D:\MinGW\msys\1.0\local\lib
4.进入ffmpeg源代码目录, ./configure --enable-libx264 --enable-encoder=aac --enable-static --enable-nonfree --enable-memalign-hack --enable-gpl --enable-version3 --toolchain=msvc
然后make -j12, make install
至此,mingw下vs编译的ffmpeg就完成了对x264的支持。可以在vs2015里调用了,引用的lib如下:
#pragma comment(lib,"libavcodec.a")
#pragma comment(lib,"libavformat.a")
#pragma comment(lib,"libavutil.a")
#pragma comment(lib,"libswscale.a")
#pragma comment(lib,"libswresample.a")
#pragma comment(lib,"libpostproc.a")
#pragma comment(lib,"libavfilter.a")
#pragma comment(lib,"libavdevice.a")
#pragma comment(lib,"x264.lib")
#pragma comment( lib, "wsock32.lib")
#pragma comment( lib, "ws2_32.lib")