Ask Your Question
0

Cannot build OpenCV 3.1.0 from source with FFMPEG

asked 2016-05-26 14:51:33 -0600

GrantRVD gravatar image

updated 2016-05-28 14:34:43 -0600

Short version

UPDATED MAY 28: I've tried several more build configurations with FFMPEG. What I've discovered is that when configured with the --enable-static option, make generates all the necessary .a files (e.g. libavcodec.a), but I get an error to the effect of "relocation against symbol cannot be used when making a shared object; recompile with fPIC." I already have --enable-pic as an option. Then, when I try the configuration with --disable-static instead, no .a files are generated, which the OpenCV build says are required. How do I direct make to use the shared object files instead of looking for the .a libraries?

Long version

I've been trying all week to build OpenCV 3.1.0 from sourcefor Python3.5 and Python2.7 on my local computer (Ubuntu 15.04 Vivid 64-bit), since there does not appear to be a compatible version available through aptitude. However, FFMPEG and libav are the impasses I cannot solve - several other issues with not finding HDF5 or Eigen3 I was able to fix relatively easily. Some of the tutorials and lessons I want to do use video as input, so I need to be the video tools working for OpenCV. I have been able to build OpenCV 3.1.0 successfully using the option WITH_FFMPEG=OFF and confirmed I could import cv2 and use all of its non-video functions without a problem. I have tried installing ffmpeg and the libav dev libraries using aptitude as well as building FFMPEG from source. For the messages below, I'm using the FFMPEG I built myself.

The error I get is the following after calling make in the ~/github/opencv/build directory:

make[2]: *** No rule to make target `/home/grant/github/ffmpeg/libavcodec.a`, needed by 'lib/libopencv_videoio.so.3.1.0'.  Stop.
CMakeFiles/Makefile2:6038: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Makefile:147: recipe for target 'all' failed
make: *** [all] Error 2

This is the error I want to solve. The rest of this post provides more information on what I've done and my setup. Note that FFMPEG I built from source (as well as libavcodec, libavfilter, libavutils, etc.) is in the ~/github/ffmpeg directory.

When looking up this error, the most common suggestions involved static libraries and shared objects, namely that ffmpeg needed to be compiled with --enable-shared and --disable-static for the opencv build to work. This is why I built FFMPEG from source. Here's the output when I call ./ffmpeg from the appropriate directory, confirming it was built with those options enabled: see the configuration line.

ffmpeg version N-80096-gdefab08 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
  configuration: --enable-shared --disable-static
  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.100 / 57. 37.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100 ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-30 04:39:55 -0600

mshabunin gravatar image

updated 2016-05-30 05:01:02 -0600

Install pkg-config package. I was able to build OpenCV with ffmpeg in Ubuntu 16.04 using the following Docker config:

FROM ubuntu:16.04

RUN apt-get update -y

RUN apt-get install \
    libtiff-dev \
    gcc \
    g++ \
    cmake \
    ninja-build \
    -y

RUN apt-get install \
    libavutil-dev \
    libavcodec-dev \
    libavfilter-dev \
    libavformat-dev \
    libavdevice-dev \
    pkg-config \
    -y

RUN mkdir -p /build
VOLUME /opencv

CMD cd /build && rm -rf * && cmake -GNinja ../opencv && ninja
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-26 14:51:33 -0600

Seen: 4,733 times

Last updated: May 30 '16