windows下编译FFMPEG篇----之一(MingW)

转自https://blog.csdn.net/listener51/article/details/81604443

  在网上关于ffmpeg在windows下的编译有很多方法,有的可行,有的不可行。本文着重介绍windows下怎么用Mingw编译32位及64位的库。

1、环境准备

  参考前文《windows下Eclipse调试ffmpeg》“”windows下mingw编译ffmpeg“”这一章节。 
  由于mingw安装的时候只有32位的工具可选,所以只能编译32位的库,需要编译64位的库需要安装mingw64,本文为了在Mingw下既能编译32位的库,又能编译64位的库,使用vs自带的编译器cl\link等。鉴于ffmpeg是用c99标准写的,vs2010不支持,因此需要额外的下载:(本文示例使用的是vs2010)

1.1 c99toc89安装

  下载地址:https://github.com/libav/c99-to-c89/releases,将压缩包里的c99conv.exe和c99wrap.exe复制到 C:/Mingw/bin下(注意这里看自己Mingw实际安装目录)。

1.2 c99头文件inttypes.h和stdint.h安装

  下载地址:https://code.google.com/p/msinttypes/downloads/list,注意此处需要翻墙,或者在网上下现成的,下载好后,将压缩包里的inttypes.h和stdint.h拷贝到C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include

1.3 修改link文件

  如果c:/Mingw/msys/1.0/bin/下有link.exe,需要将link.exe重命名为别的名字,防止和vs自带的link冲突。

1.4 修改configure 

  由于cl_major_ver的值为0,所以cc_default默认为cl,由于vs2010不支持c99语法,所以需要c99wrap(前面已经下载)作转换,将

<span style="color:#000000"><code> msvc)
        <span style="color:#880000"># Check whether the current MSVC version needs the C99 converter.</span>
        <span style="color:#880000"># From MSVC 2013 (compiler major version 18) onwards, it does actually</span>
        <span style="color:#880000"># support enough of C99 to build ffmpeg. Default to the new</span>
        <span style="color:#880000"># behaviour if the regexp was unable to match anything, since this</span>
        <span style="color:#880000"># successfully parses the version number of existing supported</span>
        <span style="color:#880000"># versions that require the converter (MSVC 2010 and 2012).</span>
        cl_major_ver=$(cl <span style="color:#006666">2</span>>&<span style="color:#006666">1</span> | sed -n <span style="color:#009900">'s/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p'</span>)
        <span style="color:#000088">if</span> [ -z <span style="color:#009900">"<span style="color:#009900">$cl_major_ver</span>"</span> ] || [ <span style="color:#009900">$cl_major_ver</span> -ge <span style="color:#006666">18</span> ]; <span style="color:#000088">then</span>
            cc_default=<span style="color:#009900">"cl"</span>
        <span style="color:#000088">else</span>
            cc_default=<span style="color:#009900">"c99wrap cl"</span>
        <span style="color:#000088">fi</span></code></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

修改为

<span style="color:#000000"><code> msvc)
        <span style="color:#880000"># Check whether the current MSVC version needs the C99 converter.</span>
        <span style="color:#880000"># From MSVC 2013 (compiler major version 18) onwards, it does actually</span>
        <span style="color:#880000"># support enough of C99 to build ffmpeg. Default to the new</span>
        <span style="color:#880000"># behaviour if the regexp was unable to match anything, since this</span>
        <span style="color:#880000"># successfully parses the version number of existing supported</span>
        <span style="color:#880000"># versions that require the converter (MSVC 2010 and 2012).</span>
        cl_major_ver=$(cl <span style="color:#006666">2</span>>&<span style="color:#006666">1</span> | sed -n <span style="color:#009900">'s/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p'</span>)
        <span style="color:#000088">if</span> [ -z <span style="color:#009900">"<span style="color:#009900">$cl_major_ver</span>"</span> ] || [ <span style="color:#009900">$cl_major_ver</span> -ge <span style="color:#006666">18</span> ]; <span style="color:#000088">then</span>
            cc_default=<span style="color:#009900">"c99wrap cl"</span>
        <span style="color:#000088">else</span>
            cc_default=<span style="color:#009900">"c99wrap cl"</span>
        <span style="color:#000088">fi</span></code></span>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2、编译

2.1 编译32位的库

  1、将C:\MinGW\msys\1.0下的msys.bat复制一份,并重命名为msys_win32.bat,打开它,并在开头处加上

<span style="color:#000000"><code>call "C:<span style="color:#009900">\Program</span> Files (x86)<span style="color:#009900">\Microsoft</span> Visual Studio 10.0<span style="color:#009900">\VC</span><span style="color:#009900">\bin</span><span style="color:#009900">\vcvars</span>32.bat"
  </code></span>
  • 1
  • 2

  2、运行msys_win32.bat, 其后,cd到ffmpeg的源码目录,敲入ffmpeg的配置命令:

<span style="color:#000000"><code><span style="color:#009900">.</span><span style="color:#880000">/configure</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">shared</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">toolchain=msvc</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">disable</span><span style="color:#006666">-</span><span style="color:#880000">everything</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">decoder=h264</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">parser=h264</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">arch=x86_32</span></code></span>
  • 1

  3、等待一段时间后,分步骤执行

<span style="color:#000000"><code><span style="color:#4f4f4f">make</span>
<span style="color:#4f4f4f">make</span> install</code></span>
  • 1
  • 2

  注意:make是执行编译操作,make install是将编译后的库拷贝到Home目录(即:C:\MinGW\msys\1.0\local)。


ISSUE1: 

undeclared ‘ERROR_NOT_ENOUGH_MEMORY’) 

SOLUTION1: 

In win10, many error code definitions, include ERROR_NOT_ENOUGH_MEMORY, are written in winerror.h. 
Add winerror.h header in your os_support.h will solve the problem.

参考网址:https://stackoverflow.com/questions/49572350/a-strange-error-undeclared-error-not-enough-memory-occurred-while-i-compling 

ISSUE2: 

LD ffmpeg_g.exe 
ffmpeg_dxva2.o : error LNK2019: 无法解析的外部符号 __imp__GetShellWindow@0,该符号在函数 _dxva2_alloc 中被引用. 

SOLUTION2: 

It seems as your installation are good but you are not actually linking to user32.lib 
Check your project settings under linker input. Is user32.lib included?

解决方法:在ffmpeg的源码目录,找到config.mak 打开它,在LIBS-ffmpeg后添加 user32.lib

<span style="color:#000000"><code>LIBS-ffmpeg=ole32.<span style="color:#000088">lib</span> user32.<span style="color:#000088">lib</span></code></span>
  • 1

参考网址:https://social.msdn.microsoft.com/Forums/en-US/8d637070-b413-43e9-aff3-6d12e8fa5dfb/linker-errors-when-building-samples?forum=Vsexpressinstall

2.2 编译64位的库

  1、将C:\MinGW\msys\1.0下的msys.bat复制一份,并重命名为msys_win64.bat,打开它,并在开头处加上

<span style="color:#000000"><code>call "C:<span style="color:#009900">\Program</span> Files (x86)<span style="color:#009900">\Microsoft</span> Visual Studio 10.0<span style="color:#009900">\VC</span><span style="color:#009900">\bin</span><span style="color:#009900">\amd</span>64<span style="color:#009900">\vcvars</span>64.bat"
  </code></span>
  • 1
  • 2

  2、运行msys_win64.bat, 其后,cd到ffmpeg的源码目录,敲入ffmpeg的配置命令:

<span style="color:#000000"><code><span style="color:#009900">.</span><span style="color:#880000">/configure</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">shared</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">toolchain=msvc</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">disable</span><span style="color:#006666">-</span><span style="color:#880000">everything</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">decoder=h264</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">enable</span><span style="color:#006666">-</span><span style="color:#880000">parser=h264</span> <span style="color:#006666">-</span><span style="color:#006666">-</span><span style="color:#880000">arch=x86_64</span></code></span>
  • 1

  3、等待一段时间后,分步骤执行

<span style="color:#000000"><code><span style="color:#4f4f4f">make</span>
<span style="color:#4f4f4f">make</span> install</code></span>
  • 1
  • 2

  注意:make是执行编译操作,make install是将编译后的库拷贝到Home目录(即:C:\MinGW\msys\1.0\local)。 

ISSUE1: 

undeclared ‘ERROR_NOT_ENOUGH_MEMORY’) 

SOLUTION1: 

In win10, many error code definitions, include ERROR_NOT_ENOUGH_MEMORY, are written in winerror.h. 
Add winerror.h header in your os_support.h will solve the problem.

参考网址:https://stackoverflow.com/questions/49572350/a-strange-error-undeclared-error-not-enough-memory-occurred-while-i-compling

3、查看库的位数

<span style="color:#000000"><code>objdump -f xxxxx.dll</code></span>
  • 1

or

<span style="color:#000000"><code>dumpbin /headers xxxxx<span style="color:#009900">.dll</span></code></span>

猜你喜欢

转载自blog.csdn.net/NBA_1/article/details/82193685