用minGW编译ffmpeg(供替换opencv中引用的ffmpeg库)

在安装好的opencv目录下找到路径:opencv245\opencv\3rdparty\ffmpeg,此路径下有一个readme.txt文件,内容如下所示:

The build script is to be fixed.
Right now it assumes that 32-bit MinGW is in the system path and
64-bit mingw is installed to c:\Apps\MinGW64.


It is important that gcc is used, not g++!
Otherwise the produced DLL will likely be dependent on libgcc_s_dw2-1.dll or similar DLL.
While we want to make the DLLs with minimum dependencies: Win32 libraries + msvcrt.dll.


ffopencv.c is really a C++ source, hence -x c++ is used.


How to update opencv_ffmpeg.dll and opencv_ffmpeg_64.dll when a new version of FFMPEG is release?


1. Install 32-bit MinGW + MSYS from
   http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/
   Let's assume, it's installed in C:\MSYS32.
2. Install 64-bit MinGW. http://mingw-w64.sourceforge.net/
   Let's assume, it's installed in C:\MSYS64
3. Copy C:\MSYS32\msys to C:\MSYS64\msys. Edit C:\MSYS64\msys\etc\fstab, change C:\MSYS32 to C:\MSYS64.
   
4. Now you have working MSYS32 and MSYS64 environments.
   Launch, one by one, C:\MSYS32\msys\msys.bat and C:\MSYS64\msys\msys.bat to create your home directories.


4. Download ffmpeg-x.y.z.tar.gz (where x.y.z denotes the actual ffmpeg version).
   Copy it to C:\MSYS{32|64}\msys\home\<loginname> directory.


5. To build 32-bit ffmpeg libraries, run C:\MSYS32\msys\msys.bat and type the following commands:


   5.1. tar -xzf ffmpeg-x.y.z.tar.gz
   5.2. mkdir build
   5.3. cd build
   5.4. ../ffmpeg-x.y.z/configure --enable-w32threads
   5.5. make
   5.6. make install
   5.7. cd /local/lib
   5.8. strip -g *.a


6. Then repeat the same for 64-bit case. The output libs: libavcodec.a etc. need to be renamed to libavcodec64.a etc.


7. Then, copy all those libs to <opencv>\3rdparty\lib\, copy the headers to <opencv>\3rdparty\include\ffmpeg_.


8. Then, go to <opencv>\3rdparty\ffmpeg, edit make.bat
   (change paths to the actual paths to your msys32 and msys64 distributions) and then run make.bat


在使用minGW32编译ffmpeg过程中,遇到了以下几个问题:

1、 在输入命令5.4后,出现了提示”yasm is old ...",提示输入“--disable-yasm”

       其实是重新输入../ffmpeg-x.y.z/configure --enable-w32threads --disable-yasm。

2、 5.5和5.6的执行过程较长,请耐心等待。

3、 5.7 strip -g *.a 的意思是跳过debug编译,编译生成release版本。

4、 第7步中的编译好的lib和头文件,其实是存放在 local 目录下(存放release版本)。开始没注意到,我一个个搜索,复制粘贴过去的,这些是我从"C:\MSYS32\msys\1.0\home\Administrator\bulid" 目录下搜索的,而这边生成的.a库版本是debug版本的。

5、 第8步中修改msys32的路径即可,就可以运行make.dat文件。

      或者是在命令行中,转到”opencv\3rdparty\ffmpeg"这个目录下,从gcc处开始” gcc -Wall -shared -o opencv_ffmpeg.dll -O2 -x c++ -I../include -I../include/ffmpeg_ -I../../modules/highgui/src ffopencv.c -L../lib -lavformat -lavcodec -lavdevice -lswscale -lavutil -lwsock32“   输入以上语句,运行后会出现

” libiconv“的相关错误提示;

 解决方法:在C:\MSYS32 目录下找到libiconv.a文件复制到 " opencv\3rdparty\ffmpeg\lib" 目录下。

在运行命令时,在后加 -liconv 运行即可生成文件 opencv_ffmpeg.dll。

6、 ffmpeg-x.y.z.tar.gz的下载地址为:http://www.ffmpeg.org/download.html,在该页面中选择最新版本的Download gzip tarball 这一项下载。

7、在命令行中书写路径中,不能用"\", 而用"/"。

8、加yasm编译:

在1的处理过程中,没有使用yasm这种汇编器,这使得在使用编译生成的opencv_ffmpeg.dll时,文件编解码的速度较慢。网上查到说,如果不用yasm编译的话,速度的确是会变慢的。所以第二次尝试使用yasm编码。

处理方法:首先下载yasm的win32版本的文件,将文件名改为yasm.exe,放入C:\MSYS32\bin 目录下。执行5.4的原命令。

执行到 5.8. strip -g *.a 时,出现了以下提示:


为了解决这个问题,重新下载了strip.exe文件,并覆盖到对应的目录下。重新执行该命令,如果本机没有安装cygwin的话,会提示缺少cygwin1.dll,所以还需下载安装cygwin程序,再添加其bin地址到系统环境变量中,再重新运行5.8命令,就OK了。


如需转载,请注明文章出处:http://blog.csdn.net/wsbeibei


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值