Build X264/ffMpeg under MinGW/MS…

来源:互联网 发布:失落沙洲知乎 编辑:程序博客网 时间:2024/06/13 07:30

 Build X264/ffMpeg under MinGW/MSYS

    --拔剑

 

鉴于在Cygwin下编译的程序必须依赖与cygwin1.dll, 改用MinGW/MSYS编译

ffmpeg/x264. BTW, as known, Visual C++ doesn't support somestandard

C++ feature, so we choose gcc to build it.

 

1.准备工作,安装MinGW/MSYS

  最新的MinGW已经集成了MSYS, URL:http://sourceforge.net/projects/mingw/

  安装时,把gcc等都选上就可以。系统会自动安装MSYS.

 

  SupposeMinGW is installed in C:\MinGW, then generallyMSYS will be installed

  in C:\MinGW\msys\1.0.

 

  1.1) go to C:\MinGW\msys\1.0

  1.2) runmsys.bat   

 

1.编译x264

  1.1) 下载x264, from www.videolan.org/developers/x264.html

   1.2) $./configure --enable-win32thread--enable-shared --disable-asm

      $make

  After that, you will find lib/dll iscreated and x264.exe is created.

 1.3) test using x264 in windowscmd

     c:\x264\x264 -0 test.flvtest1.y4m  

     转化test1.y4m为flash媒体文件。y4m媒体文件can be downloadin

             http://media.xiph.org/video/derf/

 

  说明:如果不用win32thread, pthread will beused defautly.

 1.4) if you find *.lib is not created, usingthe folowing method to manually create it:

            pexports your_dll.dll>your_dll.def  #pexports is an openSource tool, search in web

            $   lib/machine:i386 /def:your_dll.def  # lib.exe is fromVisual studio

    执行上述命令便生成了your_dll.lib文件 

  

2.编译ffmpeg

  2.1) using git or http protocol downloadffmpeg

  2.2)in MinGW/msys, go to ffmpeg dir

       $./configure--enable-memalign-hack --enable-ffserver --enable-network

            --enable-protocols --enable-muxers --disable-yasm --enable-shared--enable-w32threads

      $make

      $make install

  说明:

      1)我没有碰到网上说的一大堆问题,但是如果不加--enable-w32threads开关时,出现如下错误:

          In file included fromc:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/
               pthread.h:288:0,
                from libavcodec/pthread.c:32:
          c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/sched.h:152:53:error:
               expected ')' before 'pid'
          c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/sched.h:154:53:error:
                expected ')' before 'pid'
           make: *** [libavcodec/pthread.o] Error 1

         增加开关:--enable-w32threads,弃用pthread, 采用windows native thread, 问题消失

       (原因,可能安装MinGW时pthread包没有下好,下次重试看看。)

     2)在cygwin下,下了个yasm, 可是每次仍旧都报错,这次仍旧采用了disable-asm, 下次在msys

        下试试enable-asm.

     3)网上有的地方说,要生成lib,需要修改msys.bat, 在msys.bat的第一行加入
          call "C:\Program Files\Microsoft Visual Studio8\VC\bin\vcvars32.bat"

       [说明]:加了上句后,声称动态库(--enable-shared)时确实自动生成了lib文件,上面的语句要和VisualStudio

              目录一致,不能生搬。

     4) 如果MinGW/msys没有安装pkg-config, configure会抱错,但是不影响make。 解决的办法

        是下载pkg-config forMinGW/msys.

       pkg-config: http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.23-3_win32.zip

       依赖的DLL:http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.18/glib_2.18.4-1_win32.zip              (只需要libglib-2.0-0.DLL)

     图方便,直接把他们放在 ../msys/1.0/bin/目录即可。


参考文献:

       http://www.ffmpeg.org/general.html#SEC24

    http://blog.csdn.net/chaosllgao/archive/2009/03/12/3984462.aspx


        


 

0 0