How to use libavcodec in Qt4?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 20:20:54

问题


How do I use libavcodec in Qt4 to access individual video frames?

After verifying that the video stream can be decoded by libavcodec by compiling this example, I moved the source code to my C++ program. Now av_open_input_file() is suddenly unable to open my video file (returning an errorcode: -2).

The call looks like this right now:

...
// 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
}

When I look at const char* fileName inside the debugger it looks correct. Am I making some basic mistake in mixing C and C++ code (for a first attempt I just dumped the code from the example into the constructor of a class)?

Note: In order to get the application to compile I include the headers like this:

extern "C"
{
#define __STDC_CONSTANT_MACROS // for UINT64_C
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}

I have also tried to hard code the path to the video file into the application without any success:

av_open_input_file(&pFormatCtx, "/home/bjoernz/video.avi", NULL, 0, NULL);

I was able to compile and execute the example (avcodec_sample.0.5.0.c) using g++.


回答1:


Error -2 means No such file or directory. I'm pretty sure the file you're attempting to open isn't located in your "current working directory" when running the application.




回答2:


Well, this is embarrassing:

When I transfered the source code from the example to the c++ application I made a stupid mistake when I got linker errors, that told me that av_register_all(); was unavailable... and I renamed it to avcodec_register_all(), a little while later I fixed the linker problem and forgot about it...

Solution: avcodec_register_all() needs to be changed to av_register_all().



来源:https://stackoverflow.com/questions/4184789/how-to-use-libavcodec-in-qt4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!