How to use libavcodec in Qt4?

How to 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 it av_open_input_file()suddenly cannot open my video file (returning an error code: -2).

The call is as follows:

...
// 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 the const char* fileNameinside of the debugger, it looks right. Am I making some basic mistake when mixing C and C ++ code (for the first attempt, I just dumped the code from the example into the class constructor)?

Note . To get the compilation application, I include the headers as follows:

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);

(avcodec_sample.0.5.0.c) g++.

+3
2

, :

++, , , , av_register_all(); ... avcodec_register_all(), ...

: avcodec_register_all() av_register_all().

+2

-2 No such file or directory. , , , " " .

+2

Source: https://habr.com/ru/post/1774957/


All Articles