1

I have downloaded OpenCV-python sourcecode from https://pypi.org/project/opencv-python/ and am trying to build it on OpenSuse.

I have ffmpeg already installed as shown here and I wish to use this installed version and not build my own ffmpeg:

/home/adminlinux/Downloads/build # ffmpeg -version
ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (SUSE Linux)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg 
--extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --disable-htmlpages --enable-pic --disable-stripping --enable-shared --disable-static --enable-gpl --disable-openssl --enable-avresample --enable-libcdio --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcelt --enable-libcdio --enable-libdc1394 --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-vaapi --enable-vdpau --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libx264 --enable-libx265 --enable-libxvid
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100

When I build using the following cmake command:

cmake ../opencv-python-4.4.0.46/opencv/

I see that FFMPEG is not detected:

Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)

This link is indicating that I need to indicate where my ffmpeg libraries are: Configure and Build OpenCV to Custom FFMPEG Install

So I have tried the following flags but still got the same output:

cmake -DHAVE_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64"  -DFFMPEG_INCLUDE_DIRS="/usr/lib64" ../opencv-python-4.4.0.46/opencv/

I then tried the following flags (OPENCV_FFMPEG_SKIP_BUILD_CHECK and BUILD_SHARED_LIBS):

cmake -DHAVE_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64"  -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON -D BUILD_SHARED_LIBS=OFF ../opencv-python-4.4.0.46/opencv/

And this time I notice that FFMPEG is now ON but the libs are NO:

Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)

What else can I do to enable the codecs? I am stabbing in the dark at this stage.

EDIT

I downloaded the source code for open-cv (not opencv-python) from https://opencv.org/opencv-4-4-0/

Each of the following cmake commands resulted in the same output:

cmake ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64/" ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64"  -DFFMPEG_INCLUDE_DIRS="/usr/lib64/" ../opencv-4.4.0

Result:

Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)

And the following commands:

cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64"  -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON  ../opencv-4.4.0

cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64"  -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON -D BUILD_SHARED_LIBS=OFF ../opencv-4.4.0

Result

Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)

Is there any other flags etc that I need/could use? Or any way to debug why its not detecting my ffmpeg?

Community
  • 1
  • 1
Harry Boy
  • 4,159
  • 17
  • 71
  • 122
  • 1
    the "opencv-python" package is a convenience. it uses some "build recipes" but basically OpenCV **itself** contains the python bindings. build OpenCV itself, then you get python bindings. you don't need opencv-python's build scripts. – Christoph Rackwitz Sep 02 '21 at 12:19
  • @ChristophRackwitz see my edit. – Harry Boy Sep 02 '21 at 13:58
  • 1
    browse the issues on opencv's github. the "invalid tracker" ones often contain build issues resulting from lack of documentation. you need to set some cmake variables specific to how opencv finds ffmpeg, which aren't obvious. – Christoph Rackwitz Sep 02 '21 at 18:06

2 Answers2

2

this worked for me (Ubuntu 22 Server)

sudo apt install pkg-config     
sudo apt install ffmpeg libavformat-dev libavcodec-dev libswscale-dev 

ffmpeg alone was not enough

Werner
  • 196
  • 2
  • 5
1

OpenCV looks for ffmpeg by checking its .pc files (used for pkg-config). If you installed ffmpeg using package manager (e.g. apt on Ubuntu) and did not install pkg-config, try sudo apt install pkg-config and reinstall ffmepg sudo apt install ffmpeg. This solved the problem in my case.

fytao
  • 181
  • 3
  • 14