在Windows上的qt项目中包含ffmpeg会导致程序意外完成 [英] Including ffmpeg in qt project on windows causes the program to unexpectedly finish

查看:1091
本文介绍了在Windows上的qt项目中包含ffmpeg会导致程序意外完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在Windows的qt项目中加入ffmpeg。我正在运行QT4,并在32位Windows 7上使用微软可视化编译器2010进行编译。我正在尝试包含ffmpeg 2.8,我得到了 dev 共享 zeranoe 下载。当我运行它时,我得到以下输出:

 启动(可执行路径)... 
程序意外完了。
(可执行路径)退出代码-1073741819

我可以使用以下内容生成此输出: / p>

ffmpeg_test.pro:

  QT + = core 
TARGET = ffmpeg_test

INCLUDEPATH + =(ffmpeg dev path)/ include
LIBS + = -L(ffmpeg dev path)/ lib
LIBS + = -lavformat

SOURCES + = main.cpp

main.cpp:

  externC
{
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include< libavformat / avformat.h>
}

int main(int argc,char * argv [])
{
av_register_all();
return 0;
}

我将ffmpeg共享bin中的.dll文件放入同一个文件夹该QT生成ffmpeg_test.exe。我也确认使用依赖关系Walker找到它们,当它们不在该目录中时显示问号,当它们是avformat-56.dll文件路径时(发现.dll文件不会影响输出的程序)。



依赖性助行器确实显示出一些奇怪的事情,因为没有预期的功能,但在avformat-56.dll中找到的功能看起来正确。我也运行了Dumpbin.exe / EXPORTS在avformat.lib,它也看起来不错(我可以发布输出,如果这将是有用的)。值得注意的是,我将这个版本的ffmpeg包含在这台机器上的不同应用程序中,但这不是一个qt项目。该项目使用CMake而不是QMake生成其make文件,并使用Microsoft Visual C ++ 2010而不是QT Creator构建。



我还包括其他.lib / .dll对在qt他们没有问题。我注意到这两个差异。首先在ffmpeg-dev lib文件夹中,而不是只有.lib文件(如我所有其他.lib / .dll对的情况),我也为每个库都有一个.def和.dll.a文件。第二个ffmpeg是ac库,而所有其他包含的库都是c ++。



更新3/29



我已经尝试用以下两个代替我的.pro中的LIBS行:



LIBS + =(ffmpeg dev路径)/lib/avformat.lib



LIBS + =(ffmpeg dev path)/lib/libavformat.dll .a



两者都提供相同的错误消息。我还尝试将以下内容添加到我的.pro文件中也不起作用。



DEFINES + = __STDC_CONSTANT_MACROS
QMAKE_CXX_FLAGS + = -D_STDC_CONSTANT_MACROS



此外,我尝试添加 #define inline __inline根据ffmpeg rel = nofollow的>网站。任何想要尝试的想法将非常感谢!



更新3/31



我试图重新启动一个新的Windows构建环境,但结果保持不变,上面的测试代码。 (新环境能够运行一个你好的世界程序)。



我的设置此环境的过程是安装新版本的32位Windows 7.从 Visual Studio 2010 Express All-in-one ISO 。安装 Qt 4.8 .6为32位窗口和Visual Studio 2010 。最后安装 Qt Creator 2.5.2 。要设置Qt创建者,我进入了工具 - >选项,并告诉它在哪里可以找到Qt 4.8.6 qmake。我下载了 dev 共享从Zeranoe为ffmpeg 2.8构建。我缺少 stdint。 h和inttypes ,所以我下载它们并将文件放在/ include / libavutil中。然后我将任何投诉的头文件更正为stdint.h等等。然后将ffmpeg-2.8-win32-shared / bin中的dll文件放入qt正在构建的文件夹ffmpeg_test ffmpeg_test-build-desktop-Qt_4_8_6__4_8_6__Release / release。

解决方案

问题是ffmpeg是使用 MinGW编译器编译的,有时候使用不同编译器编译的图书馆可能并不总是兼容。我能够通过获取MinGW编译器并为MinGW设置Qt来使我的测试程序正常运行。此外,我的ffmpeg版本不需要涉及stdint.h或inttypes.h的更改。这个版本的ffmpeg是否能够使用MSVC和cmake进行编译对我来说仍然是一个谜。对于前进的路径,问题是如果切换到MinGW编译器是一个选项,或者我需要编译ffmpeg为MSVC。


I am trying to include ffmpeg in my qt project on windows. I am running QT4 and compiling with microsoft visual compiler 2010 on 32 bit windows 7. I am trying to include ffmpeg 2.8 which I got the dev and shared downloads from zeranoe. When I run it I get the following output:

Starting (executable path)...
The program has unexpectedly finished.
(executable path) exited with code -1073741819

I am able to produce this output with the following:

ffmpeg_test.pro:

QT += core
TARGET = ffmpeg_test

INCLUDEPATH += (ffmpeg dev path)/include
LIBS += -L(ffmpeg dev path)/lib
LIBS += -lavformat

SOURCES += main.cpp

main.cpp:

extern "C"
{
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavformat/avformat.h>
}

int main(int argc, char *argv[])
{
  av_register_all();
  return 0;
}

I have put the .dll files from the ffmpeg share bin into the same folder that QT builds ffmpeg_test.exe into. I have also confirmed that they are found using dependency walker which shows a question mark when they are not in that directory and the avformat-56.dll file path when they are (the fact that the .dll files are found does not effect the output of the program).

Dependency walker does reveal that something weird is going on as there are no expected functions, but the functions found in avformat-56.dll look correct. I also have ran Dumpbin.exe /EXPORTS on avformat.lib and it also looks fine (I can post output if it would be helpful). It is worth noting that I have included this version of ffmpeg in a different application on this machine, it was not a qt project however. That project generated its make file with CMake rather than QMake and was built with Microsoft Visual C++ 2010 rather than QT Creator.

I have also included other .lib/.dll pairs in qt and they have no problems. I am noticing two differences from those pairs. First in the ffmpeg-dev lib folder instead of having only .lib files (as is the case for all my other .lib/.dll pairs) I also have a .def and a .dll.a file for each library. Second ffmpeg is a c library whereas all my other included libraries are c++.

update 3/29:

I have tried replacing the LIBS lines in my .pro with both of the following:

LIBS += (ffmpeg dev path)/lib/avformat.lib

LIBS += (ffmpeg dev path)/lib/libavformat.dll.a

Both give the same error message. I have also tried adding the following to my .pro file also with no effect.

DEFINES += __STDC_CONSTANT_MACROS QMAKE_CXX_FLAGS += -D_STDC_CONSTANT_MACROS

Additionally I tried adding #define inline __inline to main.cpp as suggested on the ffmpeg website. Any ideas of things to try would be hugely appreciated!

update 3/31:

I have tried to start over with a new Windows build environment but the result remains unchanged with the test code above. (The new environment was able to run a hello world program).

My process for setting up this environment was to install a fresh version of 32 bit windows 7. Install Visual C++ 2010 Express from the Visual Studio 2010 Express All-in-one ISO. Install Qt 4.8.6 for 32 bit windows and Visual Studio 2010. And finally install Qt Creator 2.5.2. To set up Qt creator I went under tools->options and told it where to find the Qt 4.8.6 qmake. I downloaded the dev and shared builds for ffmpeg 2.8 from Zeranoe. I was missing stdint.h and inttypes so I downloaded them and put the files in /include/libavutil. Then I corrected any of the header files that complained from to "stdint.h" ect. I then put the dll files from ffmpeg-2.8-win32-shared/bin into the folder where qt was building ffmpeg_test ffmpeg_test-build-desktop-Qt_4_8_6__4_8_6__Release/release.

解决方案

The problem is that ffmpeg was compiled with the MinGW compiler and sometimes libraries compiled with different compilers may not always be compatible. I was able to make my test program run correctly by getting the MinGW compiler and setting up Qt for MinGW. Also my version of ffmpeg did not require the changes involving stdint.h or inttypes.h. How this version of ffmpeg was able to compile using MSVC and cmake is still a mystery to me. For a path forward the question is if switching to the MinGW compiler is a option or if I need to compile ffmpeg for MSVC.

这篇关于在Windows上的qt项目中包含ffmpeg会导致程序意外完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆