Crosscompile OpenCV with FFMPEG support - c++

I am trying to cross compile opencv with ffmpeg support for an arm board with a buildroot based custom linux. The host is an ubuntu PC.
I want static opencv libraries.
I have downloaded ffmpeg source and crosscompiled it with the following configuration
./configure \
--enable-cross-compile \
--cross-prefix=arm-linux-gnueabihf- \
--target-os=linux \
--arch=arm \
--disable-static \
--enable-shared \
--enable-nonfree \
--enable-ffmpeg \
--enable-gpl \
--enable-swscale \
--enable-pthreads \
--disable-yasm \
--disable-stripping \
--prefix=../build \
--extra-cflags=-I../build/include --extra-ldflags=-L../build/lib
The paths are all correct and ffmpeg is built successfully. Then when I try to configure opencv with cmake-gui, I have to manually specify all paths.
But despite this, opencv configuration is unable to resolve FFMPEG correctly
I have attached the screen shot below
It cannot resolve ffmpeg versions. I tried to ignore it and build but it fails with linker error
Linking CXX static library ../../lib/libopencv_features2d.a
[ 49%] Built target opencv_features2d
make: *** [all] Error 2

Related

Link error when compiling opencv from source when including ffmpeg compiled from source

I've been stuck on this problem for weeks.
I'm trying to build opencv on a raspberry pi 4 with x264 support. To do this I need to include ffmpeg, and also build that from source.
However when compiling opencv, I'm consistently getting these linker errors:
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `avcodec_get_context_defaults3'
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `av_lockmgr_register'
/usr/bin/ld: ../../lib/libopencv_videoio.so.4.5.3: undefined reference to `av_register_all'
I'm new to Linux, so I'm not exactly sure how to get started troubleshooting this. I believe I have ffmpeg correctly compiled and installed.
Here's the steps I use:
Configure ffmpeg:
sudo ./configure \
--prefix=/usr \
--extra-ldflags="-latomic" \
--enable-shared \
--extra-libs='-lpthread -lm' \
--ld=g++ \
--enable-gpl \
--disable-debug \
--enable-nonfree \
--enable-libx264 \
--enable-omx \
--enable-omx-rpi \
--enable-gnutls \
--enable-libfreetype \
--enable-libmp3lame
Then build it:
sudo make -j4
Then install it as a package: (so opencv cmake will detect it)
sudo checkinstall -y --deldoc=yes --pkgversion=9999 --pkgname=ffmpeg
Then configure opencv (ffmpeg is detected)
sudo cmake ../opencv_sources -D CMAKE_BUILD_TYPE=RELEASE \
-D OPENCV_EXTRA_MODULES_PATH= $PWD/../opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS='-latomic -L/usr/lib' \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D BUILD_EXAMPLES=OFF \
-D CPU_BASELINE=NATIVE \
-D CMAKE_INSTALL_PREFIX="$HOME/opencv_build" \
-D BUILD_opencv_apps=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_SHARED_LIBS=ON \
-D WITH_FFMPEG=ON
Then build opencv:
sudo make -j4
And this is where I get linking errors.
I checked in /usr/lib and the .so files appear to be there:
ls /usr/lib | grep libav
libavcodec.a
libavcodec.so
libavcodec.so.59
libavcodec.so.59.4.101
libavdevice.a
libavdevice.so
libavdevice.so.59
libavdevice.so.59.0.100
libavfilter.a
libavfilter.so
libavfilter.so.8
libavfilter.so.8.1.103
libavformat.a
libavformat.so
libavformat.so.59
libavformat.so.59.4.101
libavutil.a
libavutil.so
libavutil.so.57
libavutil.so.57.3.100
How do check where opencv is looking when linking? And is there a way I can check the shared libraries that ffmpeg generated to make sure they work?
The ffmpeg version is: git-2021-08-10-c245963
And opencv is 4.5.3-dev
TL;DR:
I was compiling the master branch of ffmpeg. This version removed some deprecated functions and was incompatible with my opencv version. Or at least the build tests failed. By switching to the release/4.4 branch and repeating my previous build steps I was able to successfully build opencv.
Details:
I was able to determine that it's not a linking problem. I wrote a short program that calls avcodec_get_context_defaults3(...), as well as avcodec_version(), which is another function that should be in there. Upon linking libavcodec.so, the avcodec_version() is found, but avcodec_get_context_defaults3() is not. Therefore I believe this is a version compatibility issue between ffmpeg and opencv.
I then confirmed that the function was removed from ffmpeg. The latest version does not have it, old versions do. I used git's search function and found this commit:
Author: Andreas Rheinhardt <andreas.rheinhardt#gmail.com>
Date: Thu Feb 25 20:37:24 2021 +0100
avcodec: Remove deprecated avcodec_get_context_defaults3
Deprecated in 04fc8e24a091ed1d77d7a3c0cbcfe60baec19a9f.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt#gmail.com>
Signed-off-by: James Almer <jamrial#gmail.com>
I switched to the release/3.4 branch of FFMPEG and repeated the steps. But that was missing some other things. I repeated the steps a 3rd time with release/4.4 and that worked.
The command I used to download the correct branch was this:
sudo git clone https://github.com/FFmpeg/FFmpeg --branch release/4.4 --depth 1 ffmpeg_sources

building c++ opencv 4 with cuda ubuntu 16/04

I'm trying to build opencv' with cuda 10.2. When the following command :
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DWITH_TBB=ON -DWITH_CUDA=ON \
-DBUILD_opencv_cudacodec=OFF \
-DENABLE_FAST_MATH=1 \
-DWITH_CUBLAS=1 \
-DWITH_V4L=ON \
-DWITH_OPENGL=ON \
-DWITH_GSTREAMER=ON \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DOPENCV_ENABLE_NONFREE=ON \
-DBUILD_EXAMPLES=TRUE \
-DBUILD_PERF_TESTS=FALSE \
-DEBUILD_TESTS=FALSE ../../opencv
I have the following issue :
Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR) (Required is at least version "6")
of course I have installed cudnn7 corresponding to cuda 10.2, I the installation test passed.
Can someone help ?
To fix the problem I added the following options for cmake :
-DCUDNN_INCLUDE_DIR=/usr/local/cuda/include \
-DCUDNN_LIBRARY=/usr/local/cuda/lib64/libcudnn.so.7.6.5 \
You may also need to add:
-DCUDNN_VERSION='7.6'
Or in my case it was:
-DCUDNN_VERSION='8.0'

centos 7 make FFmpeg /libavutil/common.h:33:19: fatal error: errno.h: No such file or directory

ndk build ffmpeg 3.4.2 configure success ,but when I make it .fatal error like this
configure script is
I make it in CentOS Linux release 7.4.1708 (Core)
similar, I make fdkaac fatal error too like this
I don't know I what is the problem of system
I think you should change android ndk version
I use the ndk r16b I get the problem also
so I use the ndk r15c
I success
I holp this can help you
this is my .sh file
#!/bin/bash
rm -rf android/arm
echo "stone"
NDK=/xxxxxxx/android-ndk-r15c
NDK_VERSION=android-14
ARCH=arm
SYSROOT=$NDK/platforms/$NDK_VERSION/arch-$ARCH
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-symver \
--cross-prefix=$CROSS_COMPILE \
--target-os=android \
--arch=$ARCH \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j8
make install
}
build_one
~~~~~~~~~~~~

Compiling OpenCV with Contrib and C++11 Support?

I want to compile opencv from source on ubuntu 16.04.
I already did this successfully a couple of times before.
I am following this tutorial from pyimagesearch.
Normally this works very well, but this time I am getting the following error for the contrib module text.
[ 27%] Generating precomp.hpp.gch/opencv_text_RELEASE.gch In file
included from /usr/include/c++/5/cinttypes:35:0,
from /usr/local/include/tesseract/host.h:30,
from /usr/local/include/tesseract/serialis.h:26,
from /usr/local/include/tesseract/baseapi.h:37,
from /home/rvq/github/opencv-3.2.0/build/modules/text/precomp.hpp:51:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file
requires compiler and library support for the ISO C++ 2011 standard.
This support must be enabled with the -std=c++11 or -std=gnu++11
compiler options. #error This file requires compiler and library
support \ ^
[ 27%] Built target pch_Generate_opencv_saliency
Does somebody know how to resolve this?
Adding -D ENABLE_PRECOMPILED_HEADERS=OFF \ to CMake command resolved the issue.
Complete CMake Command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/github/opencv_contrib-3.2.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D BUILD_EXAMPLES=ON ..

Compiling PDCurses on Windows with MinGW

I'm getting the weirdest error when I do ./configure when building nmcurses-5.9
The issue is when I try to run
CC="gcc -m32" LD="ld -m32" ./configure \
--prefix=/mingw \
--without-cxx-binding \
--without-ada \
--enable-warnings \
--enable-assertions \
--enable-reentrant \
--with-debug \
--with-normal \
--disable-home-terminfo \
--enable-sp-funcs \
--enable-term-driver \
--enable-interop \
--with-pthread
and the error I get is
./configure: line 21016: D:\Program: No such file or directory
on that line is
${MAKE:-make} preinstall
I am building this in MinGW using msys.
any help would be apreciated.
In ${MAKE:-make} preinstall, the expression ${MAKE:-make} expands to the
value of the shell variable MAKE, if it is set, and otherwise to make.
So MAKE is set and expands to something probably of the form D:\Program Files\...,
i.e. a path with embedded spaces, which is construed as distinct tokens
D:\Program and Files\... by the shell when attempting to execute the
intended command:
\path\to\make preinstall
Instead it attempts to execute a program D:\Program with arguments Files\... preinstall
and complains that no such program exists.
With GNU autotools is advisable to install tools in paths that are free of
embedded spaces.