0

I am using MAC OSx and OpenCv 2.4.8. I am trying to compile a program which includes:

avformat.h and avcodec.h

I have looked for those files in my computer and they exist (in OpenCv folder).

When I compile like this:

g++ track.cpp -o track -I /Desktop/opencv-2.4.8/include/opencv -L /Desktop/opencv-2.4.8/3rdparty/include/ffmpeg_/libavcodec /Desktop/opencv-2.4.8/3rdparty/include/ffmpeg_/libavformat -lopencv_highgui -lopencv_core -lavcodec -lavformat

I get the following error:

fatal error: 'avformat.h' file not found fatal error: 'avcodec.h' file not found

What's wrong??

THANKS A LOT!!

user3369375
  • 21
  • 1
  • 5
  • Those are headers from libavcodec and libavformat. If the libraries aren't installed, install them, add the proper paths to your compilation command using the `-I` switch and add `-lavcodec -lavformat` – photoionized Apr 07 '14 at 22:06
  • thanks for your answer, so it would be like this? I have this libraries in two folders: Desktop/opencv-2.4.8/3rdparty/include/ffmpeg_/libavformat and also in: Desktop/opencv-2.4.8/include/opencv/ , so how would the whole command be? g++ track.cpp -i Desktop/opencv-2.4.8/3rdparty/include/ffmpeg_/libavformat -o track `pkg-config --cflags --libs opencv`? THANKS – user3369375 Apr 07 '14 at 22:32
  • I don't have a copy of the OpenCV zip in front of me. Does it generally package libavcodec and libavformat? If so, add `-L library_directory_name_here` with library_directory_name_here being the path to the directory containing libavcodec.dylib and libavformat.dylib. you'll also need `-I header_directory_name_here` with header_directory_name_here being the directory containing avformat.h and avcodec.h, – photoionized Apr 08 '14 at 00:40
  • If they're in multiple directories add multiple `-L` or `-I` switches.... it would be something like `g++ -o track -I header_directory_name_here -I opencv_header_directory_here -L opencv_library_directory_here -L library_directory_name_here -lopencv_core -lwhatever_other_opencv_libraries -lavcodec -lavformat` – photoionized Apr 08 '14 at 00:42

2 Answers2

2

I fixed it by building ffmpeg from source.

brew uninstall ffmpeg
brew install ffmpeg --build-from-source
aquagremlin
  • 3,515
  • 2
  • 29
  • 51
0

These headers are part of ffmpeg package. Get the path to ffmpeg installation by running 'brew info' command.

   brew info ffmpeg

ffmpeg: stable 5.0.1 (bottled), HEAD
Play, record, convert, and stream audio and video
https://ffmpeg.org/
/opt/homebrew/Cellar/ffmpeg/5.0.1_2 (272 files, 48.4MB) *


"/opt/homebrew/Cellar/ffmpeg/5.0.1_2/include" should have the required headers.
Manoj Mohan
  • 5,654
  • 1
  • 17
  • 21