使用 MinGW 编译 FFmpeg

步骤:

1、搭建 MinGW 的编译环境

下载yasm,地址:http://yasm.tortall.net/Download.html

改名为yasm.exe放到C:\WINDOWS\system32 或者 C:\MinGW\msys\1.0\bin文件夹下。

下载 mingw-get-inst-20101030.exe , 点击这里下载 http://sourceforge.net/projects/mingw/files/ 。

安装时选择如下 

 

安装过程中,需要联网。安装程序会去网上下载对应的程序。这一过程耗时较长,请耐心等候。

注意:如果安装过程中,网络断开或是无法出现了下载某些组建失败,不用担心,等安装程序运行完成后,再次运行安装程序,选择如上,安装程序会继续下载没有成功的软件。

打开C:\MinGW\msys\1.0\msys.bat文件,在文件头部加上

call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"

这句话的作用就是: 设置 2008 x86 的开发环境。我们主要是使用它的 lib.exe 生成 *.lib 文件。

运行msys.bat, 程序会根据你当前的用户名,在目录(C:\MinGW\msys\1.0\home)下建一个工作目录。

目录的名称和你的用户名一样。如果当前你的系统用户名是 administer, 那么你的工作目录就是(C:\MinGW\msys\1.0\home\administer)

2、编译 FFmpeg

解压缩 ffmpeg代码 到 MinGW 的工作目录。例如(C:\MinGW\msys\1.0\home\administer)

运行  C:\MinGW\msys\1.0\msys.bat,即可进入 MinGW 的工作目录了。

他和cmd命令有区别,右斜杠需要换成左斜杠,盘符D:也要改成/d

输入命令 "ls" , 这等价于 "dir"。列出当前目录下的文件。

输入 cd ffmpeg,进入ffmpeg 目录。

在命令行下输入如下命令:

./configure --enable-memalign-hack --enable-shared
make
make install 

成功后,编译生成的文件保存在 (C:\MinGW\msys\1.0\local\bin),头文件保存在 (C:\MinGW\msys\1.0\local\include)。

./configure --disable-debug --enable-static --enable-memalign-hack --enable-swscale --disable-avformat --disable-avfilter --enable-pthreads  --enable-runtime-cpudetect --disable-w32threads --disable-ffprobe --enable-version3 --disable-everything --enable-decoder=h264 --enable-decoder=mpeg4 --disable-ffmpeg --enable-parser=h264 --enable-parser=mpeg4video --enable-parser=mpegvideo

3、在VC中使用FFmpeg静态库

If you need it, you must also add libavdevice.a.
If your build has enabled the software scaler, you must also add libswscale.a.
Additionally, for static libraries, you must add libgcc.a, which belongs to MinGW. It must be the same library as the gcc version used to compile FFmpeg.
If you get an unresolved symbol to _snprint, you must also link to libmingwex.a, found in the MinGW lib folder.
If you get an unresolved symbol to _strcasecmp, you must also link to libcoldname.a, found in the MinGW lib folder.
Obviously, if you used any external library, you must also link to them (e.g. libxvidcore.a, libz.a).
static pthreads-w32 libraries must also be linked to wsock32.lib (from MSVC).
static x264 libraries must also be linked to pthreads-w32 (which in their turn need wsock32.lib).
If avisynth was enabled, you must also link to vfw32.lib.
If you get an unresolved symbol to *_lc_codepage, you must either use a non-DLL runtime library (in C/C++->Code Generation->Runtime Library), or also link to libmsvcrt.a, found in the MinGW lib folder, which is probably an incredibly stupid idea (I should investigate further).

Additional Dependencies
libavcodec.a libavformat.a libavutil.a libswscale.a libz.a libdts.a libfaac.a
libfaad.a libgsm.a libmp3lame.a libnut.a libogg.a libtheora.a libvorbis.a
libvorbisenc.a libx264.a libxvidcore.a libpthreadGC2.a libgcc.a libmingwex.a
wsock32.lib vfw32.lib

要使用ffmpeg的静态库,必须把ffmpeg用到的其他静态库也链接到VC的工程中。这些库主要包括

libgcc.a:gcc的函数库,一般在C:\MinGW\lib\gcc\mingw32\4.x.x\
libmingwex.a:_snprint函数所在,一般在C:\MinGW\lib\
libcoldname.a:_strcasecmp的实现,也在C:\MinGW\lib\
wsock32.lib:Windows socket库
libz.a:zip压缩库
libfaad、libx264等额外编解码库

静态库的链接顺序一定不能错,否则运行时会出现一些莫名其妙的问题。建议的链接顺序是
libgcc.a libmingwex.a libcoldname.a
libavcodec.a libavformat.a libavutil.a libswscale.a libz.a libdts.a libfaac.a
libfaad.a libgsm.a libmp3lame.a libnut.a libogg.a libtheora.a libvorbis.a
libvorbisenc.a libx264.a libxvidcore.a libpthreadGC2.a 
wsock32.lib vfw32.lib

posted @ 2012-07-26 15:33  神の日记  阅读(2320)  评论(0编辑  收藏  举报