如何在 Qt4 中使用 libavcodec 访问单个视频帧?

在通过编译 this example 验证视频流可以被 libavcodec 解码后,我将源代码移动到我的 C++ 程序中。现在 av_open_input_file() 突然无法打开我的视频文件(返回错误代码:-2)。

调用现在看起来像这样:

...
// Register all formats and codecs
avcodec_register_all();

// Open video file
QString videoFileName("/absolute/path/to/video.avi"); // from somewhere else in the application
const char* fileName = videoFileName.toStdString().c_str();
int err = 0;
if((err = av_open_input_file(&pFormatCtx, fileName, NULL, 0, NULL)) != 0)
{
    doErrorHandling(err, fileName); // err = -2
}

当我在调试器中查看 const char* fileName 时,它​​看起来是正确的。我在混合 C 和 C++ 代码时是否犯了一些基本错误(第一次尝试时,我只是将示例中的代码转储到类的构造函数中)?

注意 :为了让应用程序编译,我包含了这样的头文件:
extern "C"
{
#define __STDC_CONSTANT_MACROS // for UINT64_C
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}

我还尝试将视频文件的路径硬编码到应用程序中,但没有成功:
av_open_input_file(&pFormatCtx, "/home/bjoernz/video.avi", NULL, 0, NULL);

我能够使用 g++ 编译和执行示例 (avcodec_sample.0.5.0.c)。

最佳答案

错误 -2 表示 No such file or directory 。在运行应用程序时,我很确定您尝试打开的文件不在“当前工作目录”中。

关于c++ - 如何在 Qt4 中使用 libavcodec?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4184789/

10-11 18:45