pkot
January 12, 2024, 3:33pm
1
Setup info
• Hardware Platform (Jetson / GPU) Jetson AGX Orin
• DeepStream Version 6.2 (inside of docker)
• JetPack Version (valid for Jetson only) 5.1.1 (L4T 35.3.1)
Problem
In the thread: Cannot build opencv 4.8.0 with nvidia docker
I found the latest installation script for OpenCV 4.0 for nvidia jetson.
Host install_opencv4.8.0_Jetson.sh (2.5 KB)
After I started using it it appeared, that this build does not support FFMPEG
-- 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)
To ensure FFMPEG installation I also tried compiling with added flag `-d
Reproduction
Try to build docker:
FROM nvcr.io/nvidia/deepstream-l4t:6.2-samples
# Usefull tools, apps and libraries
RUN apt-get update && apt install -y \
g++ gcc git automake \
ffmpeg wget sudo htop x11-apps nano xonsh \
libopenmpt-dev python3-pip python3-gi
RUN useradd -ms /bin/bash -G sudo,audio,video,render myuser && echo "myuser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/ubuntu
ENV TERM=xterm-256color
USER myuser
WORKDIR /home/myuser
RUN sudo apt install -y \
build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
python3.8-dev python-dev python-numpy python3-numpy \
libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev \
libv4l-dev v4l-utils qv4l2 curl zip
RUN wget https://forums.developer.nvidia.com/uploads/short-url/iN2cxqmvZcUOA4YMpqH5b1G27nm.sh -O install_opencv4.8.0_Jetson.sh
RUN sudo chmod +x install_opencv4.8.0_Jetson.sh
# To check whether CUDA libs are availavle
RUN echo yes | sudo ./install_opencv4.8.0_Jetson.sh
RUN python3 -c "import cv2; print(cv2.getBuildInformation())"
#to ensure that build succeeds only when FFMPEG works
RUN python3 -c "import cv2; print(cv2.getBuildInformation())" | grep FFMPEG | grep YES
On jetson
pkot
January 12, 2024, 3:33pm
2
Hi,
By default FFMPEG is not enabled and you would need to manually enable it. Please try to enable it in non-docker environment first. To check what paths/packages are not included in docker.
pkot
January 15, 2024, 9:17am
5
Hi,
You are wrong, by default FFMPEG is enabled. Source: OpenCV: OpenCV configuration options reference
But even after enabling it manually by setting WITH_FFMPEG=ON
it did not compile.
Please try to enable it in non-docker environment first. To check what paths/packages are not included in docker.
During compilation there are no missing packages reported. You can easily reproduce this problem by yourself.
pkot
January 15, 2024, 9:33am
6
In general if there would be any problem with FFMPEG we should get warning-- WARNING: Can't build ffmpeg test code
, but I haven’t seen anything like that in logs
pkot
January 17, 2024, 11:50am
8
Hi,
I checked the resources you sent me.
As far as I could see, this is caused by some static libraries in the FFMPEG build. According to my tests, also the FFMPEG 4.2.2 version with hardware decoding support, that NVidia provides for Jetson (see description here: Jetson TX2 and FFmpeg - Can't initialize nvrm channel - #5 by DaneLLL ), results in an OpenCV build without FFMPEG support.
Can we expect fixing these packages by NVidia?
This fix is very old does not apply on newer JetPacks.
This repository does not work anymore and cannot be used. (check this issue )
Hi,
Could you help check further? Or would see if other users can share experience. Since OpenCV is a 3rdparty package, we don’t actually have much experience on it. Would be great if you can help check further and share the finding.
pkot
January 18, 2024, 9:30am
10
Hi,
I could help you with this problem.
I think, that nvidia should start including properly compiled opencv package in repositories for jetson (with enabled CUDA, FFMPEG, deepstreamer/gstreamer and other features compatible with jetson). It woyld save a lot of time for your customers (and also for you, because there a lot of issues about compiling CUDA on this forum).
DaneLLL
January 18, 2024, 10:14am
11
Hi,
We have pre-compiled OpenCV package. You can install it though SDKManager. Most features are enabled except WITH_CUDA=ON. Please check the explanation:
Trying to get OpenCV (built with CUDA) working with FFMPEG - #6 by DaneLLL
pkot
January 18, 2024, 10:52am
12
We have pre-compiled OpenCV package. You can install it though SDKManager.
I am not sure whether SDKManager can be used for installing packages in docker.
Most features are enabled except WITH_CUDA=ON.
This is very strange, because CUDA is one of the main selling points for Jetson, so not enabling it in the official OpenCV binaries form you does not make a lot of sense.
pkot
February 2, 2024, 10:15am
14
This is very strange, because I can have OpenCV compiled with some plugins to FFMPEG (like avcodec), but without FFMPEG itself.
-- Video I/O:
-- DC1394: NO
-- FFMPEG: NO
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: NO
-- GStreamer: YES (1.16.3)
-- v4l/v4l2: YES (linux/videodev2.h)
FULL Config
--
-- General configuration for OpenCV 4.8.1 =====================================
-- Version control: 4.8.1
--
-- Extra modules:
-- Location (extra): /home/wbuser/opencv-python/opencv_contrib/modules
-- Version control (extra): 4.8.1
--
-- Platform:
-- Timestamp: 2024-02-02T10:07:51Z
-- Host: Linux 6.5.0-15-generic x86_64
-- CMake: 3.28.1
-- CMake generator: Ninja
-- CMake build tool: /usr/bin/ninja
-- Configuration: RELEASE
--
-- CPU/HW features:
-- Baseline: SSE SSE2 SSE3
-- requested: SSE3
-- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
-- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
-- SSE4_1 (16 files): + SSSE3 SSE4_1
-- SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
-- FP16 (0 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
-- AVX (7 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
-- AVX2 (35 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- AVX512_SKX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
-- C/C++:
-- Built as dynamic libs?: NO
-- C++ standard: 11
-- C++ Compiler: /usr/bin/c++ (ver 9.4.0)
-- C++ flags (Release): -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
-- Linker flags (Debug): -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so Iconv::Iconv m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
-- 3rdparty dependencies: libprotobuf ade ittnotify libwebp libtiff libopenjp2 IlmImf quirc ippiw ippicv
--
-- OpenCV modules:
-- To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
-- Disabled: freetype world
-- Disabled by dependency: -
-- Unavailable: alphamat cvv hdf java julia matlab ovis python2 sfm ts viz
-- Applications: -
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI: GTK3
-- GTK+: YES (ver 3.24.20)
-- GThread : YES (ver 2.64.6)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: build (ver encoder: 0x020f)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
-- TIFF: build (ver 42 - 4.2.0)
-- JPEG 2000: build (ver 2.5.0)
-- OpenEXR: build (ver 2.3.0)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- DC1394: NO
-- FFMPEG: NO
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: NO
-- GStreamer: YES (1.16.3)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Intel IPP: 2021.8 [2021.8.0]
-- at: /home/wbuser/opencv-python/_skbuild/linux-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_lnx/icv
-- Intel IPP IW: sources (2021.8.0)
-- at: /home/wbuser/opencv-python/_skbuild/linux-x86_64-3.8/cmake-build/3rdparty/ippicv/ippicv_lnx/iw
-- VA: NO
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: NO
-- Protobuf: build (3.19.1)
-- Flatbuffers: builtin/3rdparty (23.5.9)
--
-- NVIDIA CUDA: YES (ver 11.8, CUFFT CUBLAS FAST_MATH)
-- NVIDIA GPU arch: 72 75 86 87 89
-- NVIDIA PTX archs:
--
-- cuDNN: YES (ver 8.7.0)
--
-- OpenCL: YES (no extra features)
-- Include path: /home/wbuser/opencv-python/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.8.10)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.10)
-- numpy: /tmp/pip-build-env-m9uykz96/overlay/lib/python3.8/site-packages/numpy/core/include (ver 1.17.5)
-- install path: python/cv2/python-3
--
-- Python (for build): /usr/bin/python3
--
-- Java:
-- ant: NO
-- Java: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /home/wbuser/opencv-python/_skbuild/linux-x86_64-3.8/cmake-install
-- -----------------------------------------------------------------
--
-- Configuring done (22.6s)
With docker
# This image requires logging to NGC docker registry
# https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_docker_containers.html
FROM nvcr.io/nvidia/deepstream:6.2-devel
ENV CPU_ARCHITECTURE=x86_64
# To get video driver libraries at runtime (libnvidia-encode.so/libnvcuvid.so)
ENV NVIDIA_DRIVER_CAPABILITIES $NVIDIA_DRIVER_CAPABILITIES,video
# Usefull tools, apps and libraries
RUN apt-get update && apt install -y \
g++ gcc git automake \
wget sudo htop x11-apps nano xonsh iputils-ping v4l-utils \
ffmpeg \
libopenmpt-dev python3-pip python3-gi
##################################
# INSTALL OpenCV for Python and C
##################################
RUN DEBIAN_FRONTEND=noninteractive sudo apt install -y \
cmake gcc g++ \
qtbase5-dev \
libavcodec-dev libavformat-dev libswscale-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev \
libgtk-3-dev libgtk2.0-dev \
python3-dev python3-numpy python3-pip
RUN python3 -m pip install --upgrade pip
RUN cd && \
git clone --recursive https://github.com/opencv/opencv-python.git --branch 78
# OpenCV build config reference: https://docs.opencv.org/4.x/db/d05/tutorial_config_reference.html
# CUDA_ARCH_BIN - depends on hardware https://developer.nvidia.com/cuda-gpus
ENV CMAKE_ARGS="-D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_CUDA=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_ARCH_BIN='7.2,7.5,8.6,8.7,8.9' \
-D WITH_CUBLAS=1 \
-D OPENCV_EXTRA_MODULES_PATH=/home/wbuser/opencv-python/opencv_contrib/modules"
# Ugly workaround for Exception: "Not found: 'python/cv2/py.typed'"
# from https://github.com/opencv/opencv-python/issues/871#issuecomment-1698297467
# waiting for new release without this bug
RUN sed -i '133s/.*//' ./opencv-python/setup.py && \
sed -i '134s/.*//' ./opencv-python/setup.py && \
sed -i '153s/.*//' ./opencv-python/setup.py && \
sed -i '154s/.*//' ./opencv-python/setup.py
RUN cd opencv-python && \
mkdir built_wheel && \
MAKEFLAGS="-j$(nproc)" pip wheel . --verbose --wheel-dir ./built_wheel
RUN cd opencv-python/built_wheel && \
python3 -m pip install `ls -1 | grep opencv | grep whl`
# install for C/C++
RUN cd opencv-python/opencv && \
mkdir build && \
cd build && \
cmake ${CMAKE_ARGS} CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=YES .. && \
make -j$(nproc) && \
sudo make install && \
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH/usr/local/lib: && \
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH/usr/local/lib:' >> ~/.bashrc
RUN export LD_LIBRARY_PATH=$LD_LIBRARY_PATH/opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdsosd: && \
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH/opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvdsosd:' >> ~/.bashrc
pkot
February 14, 2024, 2:15pm
15
@DaneLLL
I retested with script for building OpenCV 4.6, because script for 4.8 is broken: Unable to build OpenCV with CUDA in Docker on Jetson - #13 by pkot
And there is still lack of FFMPEG
-- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
-- Found libavcodec, version 58.54.100
-- Found libavformat, version 58.29.100
-- Found libavutil, version 56.31.100
-- Found libswscale, version 5.5.100
-- Checking for module 'libavresample'
-- No package 'libavresample' found
-- WARNING: Can't build ffmpeg test code
-- Checking for module 'gstreamer-base-1.0'
-- Video I/O:
-- DC1394: YES (2.2.5)
-- FFMPEG: NO
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: NO
pkot
March 1, 2024, 11:49am
16
Using docker image image nvcr.io/nvidia/l4t-cuda:11.4.19-devel
as base for building CUDA helps:
-- Video I/O:
-- DC1394: YES (2.2.5)
-- FFMPEG: YES
-- avcodec: YES (58.54.100)
-- avformat: YES (58.29.100)
-- avutil: YES (56.31.100)
-- swscale: YES (5.5.100)
-- avresample: NO
-- GStreamer: YES (1.16.3)
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: YES (carotene (ver 0.0.1))
-- Protobuf: build (3.19.1)
--
-- NVIDIA CUDA: YES (ver 11.4, CUFFT CUBLAS)
-- NVIDIA GPU arch: 72 87
-- NVIDIA PTX archs:
Source: Unable to build OpenCV with CUDA in Docker on Jetson - #16 by AastaLLL
This means that some depencensies are missing in the image nvcr.io/nvidia/deepstream-l4t:6.2-samples
Hi,
deepstream-l4t:6.2-samples is a runtime-based image.
So it won’t include headers and dev libraries which are required when building a CUDA app.
That’s why this can be fixed by switching to a dev container.
Thanks
pkot
March 14, 2024, 12:51pm
20
Hi @AastaLLL ,
But I need to build this OpenCV inside of a container with Deepstream.
deepstream-l4t:6.2-samples is a runtime-based image
Could I use a newer image nvcr.io/nvidia/deepstream:6.4-triton-multiarch
for this purpose?
Hi,
It is a runtime container.
We do have a deepstream:6.4-gc-triton-devel container but it only supports x86 environment.
Thanks.
pkot
March 18, 2024, 9:59am
22
We do have a deepstream:6.4-gc-triton-devel container but it only supports x86 environment.
This complicates things.
So how could I get properly compiled OpenCV build with enabled support to use with Deepstream?
Hi,
Do you know path of the ffmpeg files? If we can include the path in docker run command, it is supposed to work the same as the x86 docker.
pkot
March 18, 2024, 11:30am
24
FFMPEG seems to be placed in regular system paths:
/usr/bin/ffmpeg
/usr/bin/ffplay
/usr/bin/ffprobe
(you can check: https://ubuntu.pkgs.org/22.04/ubuntu-updates-universe-arm64/ffmpeg_4.4.2-0ubuntu0.22.04.1_arm64.deb.html )
Its dependencies also look like this:
/usr/lib/aarch64-linux-gnu/libavcodec.so.58.134.100
(source: https://ubuntu.pkgs.org/22.04/ubuntu-universe-arm64/libavcodec58_4.4.1-3ubuntu5_arm64.deb.html )