一个解决OpenCV ffmpeg的链接错误的解决方法

来源:互联网 发布:中国农大网络远程教育 编辑:程序博客网 时间:2024/05/19 04:04


Visual Studio 2008 Win64: FFmpeg support

Description

Currently, when you try to compile OpenCV under Visual Studio 2008 Win64, there is no FFmpeg support. Here's what I did to add it in:

In "opencv\modules\CMakeLists.txt", the "if(NOT CMAKE_CL_64)" block surrounding "add_subdirectory(ffmpeg)" must be commented out. That way, when you run CMake, the "opencv_ffmpeg" project will show up.

However, when you try to compile the "opencv_ffmpeg" project, you'll get 37 unresolved externals (av_free_packet, av_close_input_file, etc). I believe the fundamental problem is that the calling convention between 64-bit Windows and 64-bit Unix systems are different, so MSVC can not link to the 64-bit .a file.


This means that FFmpeg must be compiled as a MSVC-importable .lib. Here is the build process I used:

1. Follow the steps on this page to install Ubuntu 64-bit on a virtual box:

http://ffmpeg.arrozcru.org/wiki/index.php?title=Installing_Ubuntu_in_VirtualBox

2. Execute the "script" file I've attached, which is based on the steps from this page:

http://ffmpeg.arrozcru.org/wiki/index.php?title=Cross-compiling


Assuming the script executes successfully (let me know if it doesn't), you'll end up with a few .lib and .dll files. You can use the virtual box extensions to copy these files to the correct Windows folder: "opencv\3rdparty\lib".


Finally, in ffopencv.cpp, the following lines:
#pragma comment(lib, "libavformat64.a")
#pragma comment(lib, "libavcodec64.a")
#pragma comment(lib, "libavutil64.a")


...should be changed to:
#pragma comment(lib, "avformat-52.lib")
#pragma comment(lib, "avcodec-52.lib")
#pragma comment(lib, "avutil-50.lib")
#pragma comment(lib, "swscale-0.lib")

Now, everything will compile. However, you'll need the 5 ffmpeg dlls at runtime.



Could the above changes be integrated into the trunk, so that we'll have FFmpeg support on 64-bit Windows platforms?



链接: http://blog.sina.com.cn/s/blog_aac28bf201018vq1.html



0 0