- Build opencv with gstreamer support
lets build gstremer and opencv independantly first.
Research learnings
WITH_GSTREAMER
defaults toON
anyway- No need to compile gstreamer from source (yay!)
- Reproducible steps below, based on https://docs.opencv.org/4.11.0/d2/de6/tutorial_py_setup_in_ubuntu.html
- TODO: wrap in debian/ubuntu based image if needed/wanted etc
Look for CAP_GSTREAMER
in cv2
eg:
import cv2
print(cv2.CAP_GSTREAMER)
See:
https://docs.opencv.org/3.4/d4/d15/group__videoio__flags__base.html#:~:text=gPhoto2%20connection-,CAP_GSTREAMER,-Python%3A%20cv.CAP_GSTREAMER which is read by the OCV_OPTION macro. Remember, WITH_GSTREAMER is defaulted to ON anyway...
git clone https://gitlab.freedesktop.org/gstreamer/cerbero.git cd cerbero git checkout 1.26.1 apt install -y python3-distro python3.12-venv curl git ./cerbero-uninstalled bootstrap
Following: https://docs.opencv.org/4.11.0/d2/de6/tutorial_py_setup_in_ubuntu.html
System dependencies:
sudo apt-get install -y cmake git
sudo apt-get install -y python3-dev python3-numpy
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y libgtk-3-dev
Opensv itself
git clone https://github.com/opencv/opencv.git
mkdir build
cd build
# Configure it (see opencv notes for happy output)
cmake ../opencv/
# Build it
make -j
# Install built bins!
make install
import cv2 as cv
print(cv.__version__)
print(cv.CAP_GSTREAMER)
If you see 1800
, woopie, you've got opencv with gstreamer support built in yay!
>>> import cv2 as cv
>>> cv.CAP_GSTREAMER
1800
The OpenCV configuration options reference is located at: OpenCV configuration options reference, for example WITH_GSTREAMER
is actually defaulted to ON
.
The following NEW packages will be installed:
alsa-topology-conf alsa-ucm-conf autoconf automake autopoint autotools-dev binutils binutils-common binutils-x86-64-linux-gnu bison build-essential bzip2 ccache cmake cmake-data cpp
cpp-13 cpp-13-x86-64-linux-gnu cpp-x86-64-linux-gnu dirmngr dpkg-dev fakeroot file flex fontconfig-config fonts-dejavu-core fonts-dejavu-mono g++ g++-13 g++-13-x86-64-linux-gnu
g++-x86-64-linux-gnu gcc gcc-13 gcc-13-base gcc-13-x86-64-linux-gnu gcc-x86-64-linux-gnu gettext gettext-base gnupg gnupg-l10n gnupg-utils gperf gpg gpg-agent gpg-wks-client gpgconf
gpgsm javascript-common keyboxd libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libaom3 libarchive13t64 libasan8 libasound2-data libasound2-dev libasound2t64
libasyncns0 libatomic1 libbinutils libblkid-dev libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libde265-0 libdeflate0 libdpkg-perl libdrm-amdgpu1
libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libegl-dev libegl-mesa0 libegl1 libegl1-mesa-dev libexpat1-dev libfakeroot libffi-dev libfile-fcntllock-perl libfl-dev
libfl2 libflac12t64 libfontconfig1 libfreetype6 libgbm1 libgcc-13-dev libgd3 libgirepository-2.0-0 libgl-dev libgl1 libgl1-amber-dri libgl1-mesa-dev libgl1-mesa-dri libglapi-mesa
libgles-dev libgles1 libgles2 libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin libglu1-mesa libglu1-mesa-dev libglvnd-core-dev libglvnd-dev libglvnd0 libglx-dev libglx-mesa0 libglx0
libgomp1 libgprofng0 libheif-plugin-aomdec libheif-plugin-aomenc libheif-plugin-libde265 libheif1 libhiredis1.1.0 libhwasan0 libisl23 libitm1 libjansson4 libjbig0 libjpeg-turbo8 libjpeg8
libjs-jquery libjs-sphinxdoc libjs-underscore libjsoncpp25 libksba8 liblerc4 libllvm19 liblsan0 libltdl-dev libltdl7 libmagic-mgc libmagic1t64 libmount-dev libmp3lame0 libmpc3 libmpfr6
libmpg123-0t64 libogg0 libopengl-dev libopengl0 libopus0 libpciaccess0 libpcre2-16-0 libpcre2-32-0 libpcre2-dev libpcre2-posix3 libpkgconf3 libpng16-16t64 libpthread-stubs0-dev
libpulse-dev libpulse-mainloop-glib0 libpulse0 libpython3-dev libpython3.12-dev libquadmath0 librhash0 libselinux1-dev libsensors-config libsensors5 libsepol-dev libsframe1 libsharpyuv0
libsndfile1 libssl-dev libstdc++-13-dev libtiff6 libtool libtsan2 libubsan1 libuv1t64 libvorbis0a libvorbisenc2 libvulkan1 libwayland-client0 libwayland-server0 libwebp7 libx11-dev
libx11-xcb-dev libx11-xcb1 libxau-dev libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-randr0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb1-dev libxcomposite-dev
libxcomposite1 libxdamage-dev libxdamage1 libxdmcp-dev libxext-dev libxfixes-dev libxfixes3 libxi-dev libxi6 libxpm4 libxrandr-dev libxrandr2 libxrender-dev libxrender1 libxshmfence1
libxtst-dev libxtst6 libxv-dev libxv1 libxxf86vm1 linux-libc-dev lto-disabled-list m4 make manpages manpages-dev mesa-libgallium mesa-vulkan-drivers nasm ninja-build pinentry-curses
pkg-config pkgconf pkgconf-bin python3-dev python3-packaging python3-setuptools python3.12-dev rpcsvc-proto uuid-dev wget x11-common x11proto-dev x11proto-record-dev x11proto-video-dev
xorg-sgml-doctools xtrans-dev xutils-dev xz-utils zlib1g-dev
0 upgraded, 249 newly installed, 0 to remove and 0 not upgraded.
Need to get 182 MB of archives.
After this operation, 718 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Note the happy cmake output:
-- OpenCV modules:
-- To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching ts video videoio
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: java python2
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI: GTK3
-- GTK+: YES (ver 3.24.41)
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.3)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: /usr/lib/x86_64-linux-gnu/libwebp.so (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
-- AVIF: NO
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.43)
-- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.5.1)
-- JPEG 2000: build (ver 2.5.3)
-- OpenEXR: build (ver 2.3.0)
-- GIF: YES
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- FFMPEG: YES
-- avcodec: YES (60.31.102)
-- avformat: YES (60.16.100)
-- avutil: YES (58.29.100)
-- swscale: YES (7.5.100)
-- avresample: NO
-- GStreamer: YES (1.24.2)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT(3.25.4))
--
-- Other third-party libraries:
-- Intel IPP: 2022.0.0 [2022.0.0]
-- at: /root/opencv-gstreamer-support/installing-opencv/build/3rdparty/ippicv/ippicv_lnx/icv
-- Intel IPP IW: sources (2022.0.0)
-- at: /root/opencv-gstreamer-support/installing-opencv/build/3rdparty/ippicv/ippicv_lnx/iw
-- VA: NO
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: YES (ipp (ver 0.0.1))
-- Protobuf: build (3.19.1)
-- Flatbuffers: builtin/3rdparty (23.5.9) --
-- OpenCL: YES (no extra features)
-- Include path: /root/opencv-gstreamer-support/installing-opencv/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load --
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.12.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.12.so (ver 3.12.3)
-- Limited API: NO
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.26.4)
-- install path: lib/python3.12/dist-packages/cv2/python-3.12
--
-- Python (for build): /usr/bin/python3
--
-- Java:
-- ant: NO
-- Java: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done (40.8s)
-- Generating done (0.6s)
-- Build files have been written to: /root/opencv-gstreamer-support/installing-opencv/build
...
-- Installing: /usr/local/lib/python3.12/dist-packages/cv2/ipp/__init__.pyi
-- Installing: /usr/local/lib/python3.12/dist-packages/cv2/python-3.12/cv2.cpython-312-x86_64-linux-gnu.so
-- Set non-toolchain portion of runtime path of "/usr/local/lib/python3.12/dist-packages/cv2/python-3.12/cv2.cpython-312-x86_64-linux-gnu.so" to "/usr/local/lib"
-- Installing: /usr/local/lib/python3.12/dist-packages/cv2/config-3.12.py
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_eye.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_eye_tree_eyeglasses.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalcatface.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalcatface_extended.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalface_alt.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalface_alt2.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalface_alt_tree.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_frontalface_default.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_fullbody.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_lefteye_2splits.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_license_plate_rus_16stages.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_lowerbody.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_profileface.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_righteye_2splits.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_russian_plate_number.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_smile.xml
-- Installing: /usr/local/share/opencv4/haarcascades/haarcascade_upperbody.xml
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_frontalcatface.xml
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_frontalface.xml
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_frontalface_improved.xml
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_profileface.xml
-- Installing: /usr/local/share/opencv4/lbpcascades/lbpcascade_silverware.xml
-- Installing: /usr/local/bin/opencv_annotation
-- Set non-toolchain portion of runtime path of "/usr/local/bin/opencv_annotation" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_visualisation
-- Set non-toolchain portion of runtime path of "/usr/local/bin/opencv_visualisation" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_interactive-calibration
-- Set non-toolchain portion of runtime path of "/usr/local/bin/opencv_interactive-calibration" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_version
-- Set non-toolchain portion of runtime path of "/usr/local/bin/opencv_version" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_model_diagnostics
-- Set non-toolchain portion of runtime path of "/usr/local/bin/opencv_model_diagnostics" to "/usr/local/lib"