-7

I downloaded the latest ffmpeg source code and successfully installed it on Ubuntu But I failed to compile a simple demo.(I did included proper headers)

Here are the error messages ,just to name a few:

error: unknown type name 'AVFrame'

error: 'NULL' undeclared (first use in this function)

error: request for member 'streams' in something not a structure or union

error: 'AVMEDIA_TYPE_VIDEO' undeclared (first use in this function)

error: expected expression before ')' token

Can you help me solve this problem?

Contents Added:

e.g this is my includes

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

int main(int argc, char *argv[]) {
AVFormatContext *pFormatCtx;
int i, videoStreamIdx;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVFrame *pFrameRGB;

e.g AVFormatContext is declared in /usr/include/libavformat/avformat.h error message box shows Unknown type name AVFormatContext But How could it possibly be?

David Tree
  • 11
  • 4
  • 4
    Need to see some code. – paxdiablo May 07 '13 at 12:54
  • Here are some additional info ffmpeg version 1.1.git Copyright (c) 2000-2013 the FFmpeg developers built on May 7 2013 14:10:58 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) configuration: --enable-gpl --prefix=/usr --enable-libx264 --enable-pthreads And this is the actuall CODE https://github.com/phamquy/FFmpeg-tu...r/tutorial01.c This is created in Qt and the Qt pro file. Quote: QT -= gui TEMPLATE = app SOURCES += \ ../tutorial01.c LIBS += -L/-lavcodec -lavformat -lswscale -lavutil – David Tree May 07 '13 at 12:54
  • possible duplicate of [compiling errors with ffmpeg on linux](http://stackoverflow.com/questions/16413368/compiling-errors-with-ffmpeg-on-linux) – Tadeusz Kopec for Ukraine May 07 '13 at 12:55
  • yep,the previous one was closed marked as "Not a real Question".But It bugs me and I need to fix it to continue the project.thank you. – David Tree May 07 '13 at 13:02
  • You say you're including proper headers, but the compiler doesn't seem to think you are. Perhaps you could post some code that fails to compile; otherwise it's just your word against the compiler's. – Mike Seymour May 07 '13 at 13:19
  • And add perhaps the `-H` option to the (`gcc` or `g++`) compiler flags, it will show you the actually included headers. – Basile Starynkevitch May 07 '13 at 13:34
  • Why can't you use the *ffmpeg* provided by your distribution, i.e. install the `libffms2-dev` package... – Basile Starynkevitch May 07 '13 at 13:36

2 Answers2

1

for C++ code ,

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/avutil.h"
}

for C code ,

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>

C and C++ compiles in different set of codes.

for more info refer this answer : https://stackoverflow.com/a/67930/6180077

in main() or very beginning of the program , ffmpeg libraries are need to be initialized

av_register_all()  /*Initializes libavformat and registers all the muxers, demuxers and protocols. */

while compiling the program (say Ubuntu)

-L/$HOME/ffmpeg_build/lib/ -L/usr/lib/x86_64-linux-gnu/ -I/$HOME/ffmpeg_build/include/ myprogram.cpp -o executableFile -lavdevice -lavfilter -lswscale -lavformat -lavcodec -lavutil -lswresample
Community
  • 1
  • 1
Abdullah Farweez
  • 851
  • 2
  • 11
  • 25
0

In Qt you can add this line to your .pro file to force the compiler to look there for header files. Change it to the folder where your header files are stored.

INCLUDEPATH += <your path>

Omega
  • 1,101
  • 9
  • 14
  • I solved the issue. the project is compiled with g++ while the suffix of the source file is .c so the solution is change it to .cpp – David Tree May 08 '13 at 08:34