Opencv Unable to stop the stream: Inappropriate ioctl for device

I follow the guide " Cross compiling OpenCV 3.4.0 on PDK 5.0.5.0 - FAQ - NVIDIA Developer Forums ".
After cross-compiling and copy it to PX2 AutoChauffeur, I run the simple opencv program in PX2, which opens the mp4, read and display the frame ( successfully build with cross-compiling opencv ). There is an error of " OpenCV Unable to stop the stream: Inappropriate ioctl for device ".

Hi Quang,

can you verify this bug persists by using PDK 5.0.10.x?

If you provide a minimal sample code for me to compile, I will do some triage on your issue.

  • Fabian

Hi Fabian, I found out that the guide " Cross compiling OpenCV 3.4.0 on PDK 5.0.5.0 - FAQ - NVIDIA Developer Forums " only for PDK 5.0.5.0. I’m using PDK 5.0.10.3. It make Opencv does not compile with FFMPEG.

How can we cross-compile opencv with PDK 5.0.10.3 and also with FFMPEG and Gstreamer support. Many Thx

Thanh

Hi @FabianWeise, is there any news to update about this ?

Hi Quang,

I am on it. Will come back to you as soon as I have a solution and an update for the deprecated article.

  • Fabian

Hi Quang,

this works for me, I have just tested it a today.

Following modules from Opencv are cross-compiled:

  • [b]core
  • imgproc
  • imgcodecs[/b]
  1. Clone the OpenCV github repo
git clone https://github.com/opencv/opencv.git
  1. Change to opencv directory
cd opencv
  1. Checkout the 3.4.2 branch
git checkout 3.4.2
  1. Make a directory for build
mkdir build && cd build
  1. Configure the cmake
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$PWD/../platforms/linux/aarch64-gnu.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=./install \
-DBUILD_LIST=core,improc,imgcodecs \
-DBUILD_PNG=ON \
-DBUILD_TIFF=OFF \
-DBUILD_TBB=OFF \
-DBUILD_WEBP=OFF \
-DBUILD_JPEG=ON \
-DBUILD_JASPER=OFF \
-DBUILD_ZLIB=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_FFMPEG=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=OFF \
-DENABLE_NEON=OFF \
-DWITH_PROTOBUF=OFF \
-DWITH_PTHREADS_PF=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=OFF \
-DWITH_GTK=OFF \
-DWITH_VTK=OFF \
-DWITH_TBB=OFF \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DINSTALL_C_EXAMPLES=OFF \
-DINSTALL_TESTS=OFF \
-DVIBRANTE=TRUE \
VERBOSE=1 \
../
  1. Compile
make -j install

Also check out https://docs.opencv.org/4.0.0/d6/d15/tutorial_building_tegra_cuda.html.

Have fun and let me know if something is still striking.

  • Fabian

Hi Fabian, I look at your build step. It look like you dont enable support CUDA for openCV and does not use Toolchain-V5L.cmake. Could I ask why ?
Thx you

This is a general approach for x-compiling on aarch64. For CUDA support set WITH_CUDA=ON plus toolchain and the architecture definitions.

I will come up with a guide for this too.

  • Fabian

Hi Quang,

so here is an update for the x-compilation with CUDA support. I think it’s good to have both on this thread now.

  1. Clone the OpenCV github repo
git clone https://github.com/opencv/opencv.git
  1. Change to opencv directory
cd opencv
  1. Checkout the 3.4.0 branch
git checkout 3.4.0
  1. Make a directory for build
mkdir build && cd build
  1. Replace out-dated cmake files with files from our DW stack
// Find your DW installation folder, let it be 'usr/local/driveworks' here
cp /usr/local/driveworks/samples/cmake/FindCUDA.cmake ../cmake
cp /usr/local/driveworks/samples/cmake/FindCUDA/* ../cmake/FindCUDA
cp /usr/local/driveworks/samples/cmake/FindPackageHandleStandardArgs.cmake ../cmake
cp /usr/local/driveworks/samples/cmake/FindPackageMessage.cmake ../cmake
  1. Link all of our NPP libraries to the build process of OpenCV by changing l.898 in FindCUDA.cmake (copied in #5) to
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
  1. Un-comment ll.68-76 in /usr/local/driveworks/samples/cmake/Toolchain-V5L.cmake, so it does not print our the current SDK/PDK version on the terminal. The VIBRANTE_PDK variable is just not compatible for entering a path in a later step. So then you have:
# determine target device and pdk branch
#if(NOT DEFINED VIBRANTE_PDK_DEVICE AND VIBRANTE_PDK)
#    if(${VIBRANTE_PDK} MATCHES "(vibrante|drive)-(t.+)-linux$")
#        set(VIBRANTE_PDK_DEVICE ${CMAKE_MATCH_2} CACHE STRING "Cross-compilation target device")
#        message(STATUS "VIBRANTE_PDK_DEVICE = ${VIBRANTE_PDK_DEVICE}")
#    else()
#        message(FATAL_ERROR "Can't determine target device for PDK: ${VIBRANTE_PDK}")
#    endif()
#endif()
  1. Turn off all modules which are not supported from OpenCV side for x-compiling or give warnings that there might be issues if so. In order to do so call
CC=gcc-4.9 CXX=g++-4.9 cmake \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.2 \
-DCUDA_64_BIT_DEVICE_CODE=ON \
-DCUDA_ARCH_BIN=6.2 \
-DCUDA_ARCH_PTX="" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/driveworks/samples/cmake/Toolchain-V5L.cmake \
-DCMAKE_INSTALL_PREFIX=./install \
-DVIBRANTE_PDK:STRING=/home/fweise/nvidia/nvidia_sdk/DRIVE/Linux/5.0.10.3/OSPDK/DrivePDK/drive-t186ref-linux/ \
-DOPENCV_EXTRA_MODULES_PATH=/home/fweise/opencv/opencv_contrib/modules/ \
-DBUILD_PNG=ON \
-DBUILD_TIFF=ON \
-DBUILD_TBB=OFF \
-DBUILD_WEBP=OFF \
-DBUILD_JPEG=ON \
-DBUILD_JASPER=ON \
-DBUILD_ZLIB=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_FFMPEG=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=OFF \
-DBUILD_opencv_videoio=OFF \
-DBUILD_opencv_cudaimgproc=OFF \
-DBUILD_opencv_highgui=OFF \
-DBUILD_opencv_freetype=OFF \
-DENABLE_NEON=ON \
-DWITH_PROTOBUF=OFF \
-DWITH_PTHREADS_PF=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=ON \
-DWITH_GTK=OFF \
-DWITH_VTK=OFF \
-DWITH_TBB=OFF \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DINSTALL_C_EXAMPLES=OFF \
-DINSTALL_TESTS=OFF \
-DVIBRANTE=TRUE \
VERBOSE=1 \
../
  1. Finally, call
make -j && make install
  1. Done, that’s it.

Let me know if it works or if I missed a thing. I will also talk with the OpenCV guys and commit to their code or doc base for public availability.

Have fun!

  • Fabian