windows下用到ffmpeg

前段时间帮同学做一个项目,需要在windows下用到ffmpeg。ffmpeg是Linux下的很流行的一个开源解码器,在windows下编译,很自然的想到了使用mingw+msys来模拟Linux环境,于是开始进行配置,没想到遇到的问题还挺多的,在这里和大家一起探讨一下。

    1.首先是mingw+msys环境的配置,现在mingw做的很好了,不用两个分开安装了,直接从sourceforge上下一个git的安装。

   http://sourceforge.net/projects/mingw/files/ 下载 mingw-get-inst-20110313.exe 。

    2. 安装需要勾选MSYS选项

      

MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

 

  3.如果需要用MSVC++编译程序,需要有.lib文件才能链接到FFmpeg的库,这些.lib文件可以使用微软的工具链中lib命令产生。在安装完成后修改msys.bat (<%mingw_path%>/msys/1.0/msys.bat),在文件的最前面添加

“call "D:/Program Files/Microsoft Visual Studio 10.0/VC/bin/vcvars32.bat"”  

(根据vs版本和路径的不同,配置对应的路径)

  4.播放MP4需要X264解码库支持,需要到videolan (http://www.videolan.org/developers/x264.html)下载源码进行编译。编译命令:

./configure --prefix=/mingw   

make  

make install   

5.在编译ffmpeg 是出现“expected '')'' before ''pid''”错误,而libx264运行需要pthreads 支持,所以需要pthread的lib 支持,到fmpeg.arrozcru.org下载一个pthread动态库。(http://ffmpeg.arrozcru.org/autobuilds/extra/mingw32/pthreads-w32-CVS_10012009_0211-mingw32.tar.bz2) 。解压文件,将mingw文件夹下的目录分别放到mingw安装文件夹下对应得目录。

6.进入ffmpeg 目录,编译,configure 能够顺利完成,但是make 时报错,“implicit declaration of function ''strcasecmp''”,需要对mingw进行patch。下载strcasecmp.diff (http://fate.arrozcru.org/mingw32/patches/),然后patch:

patch –p2 strcasecmp.diff   

7.生成ffmpeg 需要yasm(开源汇编器)支持,去http://www.tortall.net 下载对应的yasm(http://www.tortall.net/projects/yasm/releases/yasm-1.1.0-win32.exe ),重命名为yasm.exe 将其放到<%mingw_path%>/bin文件夹下。

8.这样配置完后可以生成ffmpeg.exe , ffprobe.exe,但是没有ffplay.exe,没有播放器。要生成ffplay.exe需要SDL的支持,在ffmpeg configure 时如果提示sdl support yes ,那么生成结果就有ffplay.exe。

9.SDL(Simple DirectMedia Layer)需要glib的支持, GLib是GTK+和GNOME工程的基础底层核心程序库,是一个综合用途的实用的轻量级的C程序库。我们到GTK+官网下载glib (http://www.gtk.org/download-windows.html) ,同时下载它的依赖项zlib(也在相同页面下载)。这样,我们再到sdl官网下载最新版本的SDL-devel-1.2.14-mingw32.tar.gz(http://www.libsdl.org/release/SDL-devel-1.2.14-mingw32.tar.gz),解压后按照目录将文件分别放进对应的mingw文件夹中。

10.终于,可以开始编译ffmpeg了,先下载ffmpeg,首先得先安装git(http://www.kernel.org/pub/software/scm/git/),Git 是用于 Linux 内核开发的版本控制工具,它采用了分布式版本库的方式,不必服务器端软件支持。找到ffmpeg官网,进入download页面,选择git://github.com/lu-zero/ffmpeg.git 源下载。当然,首先得新建一个文件夹来存放下载的源代码:

git clone git://github.com/lu-zero/ffmpeg.git  

MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

 

注意:截图可能有点问题,ffmpeg.org的源可能有点老了,不支持新版的SDL,这问题让我搞了半天,还有videolan.org的源不是稳定版本,会出现“implicit declaration of function ''strdup''”错误。

11.Configure

./configure --enable-memalign-hack --enable-pthreads –-enable-libxvid --enable-libx264 --enable-gpl –-disable-debug –-prefix=/mingw  

  

MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

 memalign-hack:是mingw平台配置下必须的

pthreads:libx264要用到的,如果不配置libx264,可以使用w32threads

libxvid, libx264:播放高清mp4需要的解码库

gpl:配置libxvid, libx264 同时需要配置支持GPL

disable-debug:减少编译产生的调试信息

 

12.configure结果

  MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

13.make

这是一个漫长的过程。。。

14.make 结果

生成了ffmpeg.exe ffplay.exe ffprobe.exe


MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

 

 

15.测试ffplay,我随便找一个MP4文件来播放,这里选了一个1280p的辛普森一家的片段播放,效果还是很理想的。

 


MinGw 下编译 FFMPEG - cgq_i - cgq_i的博客

 


具体编译前的准备就不多啰嗦了,还是一样mingw准好就OK了。

下载ffmpeg的源码后,Mingw下编译,出现错误:“libavformat/metadata.c:133:17: error: implicit declaration of function 'strcasecmp'”,

(strcasecmp声明不确切。)
自己实现了两个函数。

  1. #ifndef __STRCASECMP_H____  
  2. #define __STRCASECMP_H____  
  3.   
  4. static inline char __hack_charget( char c )  
  5. {  
  6.     if(c >= 'a' && c <= 'z')  
  7.         c += 'A' - 'a';  
  8.     return c;  
  9. }  
  10.   
  11. static inline int hack_strcasecmp( char const *a, char const *b )  
  12. {  
  13.     char ac, bc;  
  14.     int r;  
  15.     for(;;) {  
  16.         ac = __hack_charget(*a++);  
  17.         bc = __hack_charget(*b++);  
  18.         r = (int)ac - (int)bc;  
  19.         if(r)  
  20.             return r;  
  21.   
  22.         if(!ac)  
  23.             return 0;  
  24.     }  
  25. }  
  26.   
  27. static inline int hack_strncasecmp( char const *a, char const *b, int n )  
  28. {  
  29.     char ac, bc;  
  30.     int r, i;  
  31.   
  32.     for(i = 0; i < n; ++i) {  
  33.         ac = __hack_charget(*a++);  
  34.         bc = __hack_charget(*b++);  
  35.         r = (int)ac - (int)bc;  
  36.         if(r)  
  37.             return r;  
  38.   
  39.         if(!ac)  
  40.             return 0;  
  41.     }  
  42.     return 0;  
  43. }  
  44.   
  45. #define strcasecmp hack_strcasecmp  
  46. #define strncasecmp hack_strncasecmp  
  47.   
  48. #endif  


存储成strcasecmp.h于mingw include目录下。
将这个文件include进avstring.h和metadata.h中,问题解决。


在编译最新版本ffmpeg时遇到上述问题。

通过网上搜索发现解决该问题的方法。

参考

http://comments.gmane.org/gmane.comp.video.ffmpeg.libav.user/10325


[plain]  view plain copy
  1. Re: makefile problem on win32 MinGW  
  2.   
  3. Thomas Sharpless <tksharpless <at> ...> writes:  
  4.   
  5. > ./configure: line 4652: git: command not found  
  6. >   
  7. > The very last part of the configure script fails but   
  8. > it looks to me like all it is trying to do is make   
  9. > sure the source code is totally current.  
  10.   
  11. It looks if the repository you are using is   
  12. current, you don't have to worry about the warnings.  
  13.   
  14. > But then, horrors!  
  15. > $ makecommon.mak:139: *** missing separator.  Stop.  
  16.   
  17. This indicates that your checkout is broken, use:  
  18. $ git config --global core.autocrlf false  
  19. and checkout again.  
  20.   
  21. Carl Eugen  
https://help.github.com/articles/dealing-with-line-endings#platform-windows
解决方法

运行

git config --global core.autocrlf false
#然后运行下面的命令删除ffmpeg代码,并重新获取一下即可
git rm --cached -r .
git reset --hard




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值