Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT ffmpeg Setting

Tags:

ffmpeg

qt

I can't use the ffmpeg in QT.

My Steps :

-1. compile the ffmpeg as normal

-2. add lib/include path in QT .pro

LIBS += -L/home/kim/ffmpeg/lib -lavcodec -lavformat
INCLUDEPATH += /home/kim/ffmpeg/include

-3. in code

extern "C" { 
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}

and just call a function named av_register_all();

then I got the following bulid issues< many functions undefined reference >

in function `rl2_read_packet`: undefined reference to `av_free_packet`
in function `av_register_all`: ....

I search a solution of the problem but not work for me.

Any other solution? Thanks.

like image 438
user775668 Avatar asked May 30 '11 03:05

user775668


2 Answers

This is an old post and it is almost solved. By the way, I faced to the problem and I had lots of time struggling with

undefined reference to av_register_all

I am using Qt Creator 5.3.2 and this is my MYPROJECT.pro file

MYPROJECT.pro

QT       += core
QT       -= gui
TARGET = MYPROJECT
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -D__STDC_CONSTANT_MACROS
LIBS += -LC:\ffmpeg-20151219-git-2dba040-win32-dev\lib
LIBS += -lavcodec -lavformat -lavutil -lswscale
INCLUDEPATH +=C:\ffmpeg-20151219-git-2dba040-win32-dev\include
  • Setting up project.pro

It is recommended to build ffmpeg from scratch, but if you are on windows and if you are not willing to compile this masterpiece, then congrats! you are like me! Go for pre-built in zereanoe and download both the latest shared and dev win-32 versions. Extract the latter two packages in a place where there is no spaces in the path, i.e. mine is in: C:\ffmpeg-20151219-git-2dba040-win32-dev I recommend that don't rename the main folder because it is highly informative. Set the include folder of the [PATH TO ffmpg-YYYYMMDD-git-win32-dev]/include to your project's search space by the following line of code:

INCLUDEPATH +=C:\ffmpeg-20151219-git-2dba040-win32-dev\include

You should also use libraries in [PATH TO ffmpeg-YYYYMMDD-git-win32-dev]/lib to your project as below:

LIBS += -LC:\ffmpeg-20151219-git-2dba040-win32-dev\lib
    LIBS += -lavcodec -lavformat -lavutil

You can call libraries other than lavcodec, lavformat and lavutil. In your cpp file you should enclose headers corresponding to ffmpeg in extern "C" block.

  • DLLs should be added

The final step is to add all the dll files in the shared version of ffmpeg that you have recently downloaded. Copy *.dll files within

[PATH TO ffmpeg-YYYYMMDD-git-2dba040-win32-shared]/bin

and paste them wherever your executable exists. Fo instance, my project is located on C:/QtProjects/MYPROJECT, then my binaries are located on:

C:/QtProjects/build-MYPROJECT-Desktop_Qt_5_3_MinGW_32bit-Debug

Now, copy all the dlls to your project's debug or release folder.

  • My main.cpp This is my main.cpp :

main.cpp

#include <iostream>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>

}
using namespace std;
int main(int argc, char *argv[])
{
    cout<<"I have included FFMPEG in my project"<<endl;
    av_register_all();
    cout<<"If everything goes well you will see ME"<<endl;
    return 0;
}
like image 160
Davood Falahati Avatar answered Oct 01 '22 09:10

Davood Falahati


I had the same problems, it worked using the following trick.

In code cpp source:

#define __STDC_CONSTANT_MACROS

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
}

And in your .pro file:

LIBS += -LC:/Users/tom/bla/ffmpeg/lib/ -lavcodec -lavformat -lavutil

I think in your case, you need the -lavutil lib parameter.

like image 39
seattledirk Avatar answered Oct 01 '22 11:10

seattledirk