4

I'm trying to install OpenCV in Ubuntu 14.10 according to instruction. I installed all mentioned dependencies, but when I'm trying to run make I get such errors:

/home/ilia/opencv-2.4.8/modules/highgui/src/ffmpeg_codecs.hpp:114:7: error: ‘CODEC_ID_H261’ was not declared in this scope
 { CODEC_ID_H261, MKTAG('H', '2', '6', '1') }

for all codecs, as I think. And these errors:

    In file included from /home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::getProperty(int)’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:773:33: error: ‘AVStream’ has no member named ‘r_frame_rate’
         return av_q2d(video_st->r_frame_rate);
                                 ^
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::get_fps()’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:820:49: error: ‘AVStream’ has no member named ‘r_frame_rate’
     double fps = r2d(ic->streams[video_stream]->r_frame_rate);
                                                 ^
In file included from /home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:1236:72: error: ‘avcodec_encode_video’ was not declared in this scope
         out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
                                                                        ^    

It looks like it can not find some header files, but I installed all necessary dev packages libswscale-dev, libavdevice-dev, libavfilter-dev, libavformat-dev, libavcodec-dev. What should I do to resolve these problems?

1
  • in Ubuntu 14.10, libav uses the API version 11. OpenCV still uses API version 9, contained in Ubuntu 14.04 LTS. I think they have to provide a patch for it
    – madduci
    Nov 1, 2014 at 12:07

3 Answers 3

17

Installing OpenCV from the Ubuntu repositories is a good choice for the most cases, but sometimes you need build OpenCV from sources yourself.

For example, if you need OpenCV's non-free functionality, or want to contribute to this project (you should use the latest version to create pull request), or want to change something (yes, OpenCV can also contain bugs).

Possible solution is building ffmpeg (it's rather simple) - I really don't understand why Debian/Ubuntu prefers libav without alternative.

For installing ffmpeg you should download its sources from official site or clone GIT repository (git://source.ffmpeg.org/ffmpeg.git), then enter source directory and run

./configure --enable-shared --disable-static
make
sudo make install

you can also add other parameters to configure. You can build static libraries too, but OpenCV can't be built with static ffmpeg libraries (now I don't know why).

After this you can download OpenCV sources from OpenCV site or clone GitHub repository (OpenCV repository), create build folder and run from it the following:

cmake PATH_TO_SOURCES -DCMAKE_BUILD_TYPE=Release
make
sudo make install

Of course, PATH_TO_SOURCES must be actual path to your OpenCV sources.

After these steps you have working latest OpenCV build in your system.

5
  • building ffmpeg from sources instead of using libav worked for me.
    – afenster
    Jan 19, 2015 at 21:50
  • it's exactly what I suggested in my answer
    – avtomaton
    Jan 21, 2015 at 5:38
  • I got this message: Is it ok to diable yasm? hyasm/nasm not found or too old. Use --disable-yasm for a crippled build. @avtomaton
    – MAS
    Nov 19, 2016 at 6:36
  • @avtomaton UPDATE: i tried it but I got the same error . I am using mac os
    – MAS
    Nov 19, 2016 at 6:53
  • 1
    @MAS possibly incompatible versions of opencv and ffmpeg. On Mac I prefer brew or port for installing ffmpeg instead of compiling from sources - should work with the latest opencv (3.1). If you prefer compiling from sources, please carefully check ffmpeg and opencv versions and their compatibility. Original question is relevant for ubuntu 14.10, where maintainers removed ffmpeg from repositories for the some reason.
    – avtomaton
    Nov 21, 2016 at 16:46
3

Unless you have special reasons I would suggest installing the OpenCV that are already in the Ubuntu repository: sudo apt-get install libopencv-dev

For video codecs I suggest simply trying to install all ffmpeg and gstreamer related codec packages.

2
  • 1
    Thank you. It was much easier than I thought.
    – Ilia
    Oct 27, 2014 at 19:37
  • 3
    well, that's not a solution. Especially if someone requires Qt, CUDA, OpenNI.
    – madduci
    Oct 31, 2014 at 17:57
3

You can try to build without a ffmpeg:

cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_FFMPEG=OFF ..
make
sudo make install
1
  • Without ffmpeg you will possibly get version without reading and writing video - it's OK only if you don't use them in your projects
    – avtomaton
    Aug 9, 2015 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.