OpenCV VideoWriter does not open using GStreamer pipeline in Docker Container

Hi, i’ve got an application written in C++ that streams frames to a Windows machine via UDP. I do this using GStreamer. This works correctly doing it directly in the Jetson AGX Xavier, by using the following pipeline:

std::string gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw, format=RGBA "
                "! nvvidconv ! video/x-raw(memory:NVMM), width=640, height=480 ! omxh264enc insert-vui=true insert-sps-pps=1 "
                "! h264parse ! rtph264pay config-interval=1 ! udpsink host=172.16.x.x port=10000 ";

cv::VideoWriter writer;
writer.open(gst_out, cv::CAP_GSTREAMER, 0, 60, cv::Size(640, 480 ), true);

if (!writer.isOpened()) {
   printf("=ERR= can't create video writer\n");
   return -1;
 }

I created a CUDA-Docker container using “FROM nvcr.io/nvidia/l4t-base:r32.4.3” as the base, installed OpenCV 4.5.3 and GStreamer, and replicated the application I mention above, with the same code.

However, when running it in the Docker container, when opening the VideoWriter, I get the following error, when checking the “writer.isOpened()”: =ERR= can’t create video writer

I checked if GStreamer was working by using the following in the cmd:

gst-launch-1.0 videotestsrc ! nvvidconv ! "video/x-raw(memory:NVMM), width=640, height=480, framerate=60/1" ! omxh264enc insert-vui=true insert-sps-pps=1 ! h264parse ! rtph264pay config-interval=1 ! udpsink host=172.16.x.x port=10000

This works in both the Jetson AGX Xavier (Linux) and the CUDA-Docker container.

I compiled OpenCV in the Container with the following flags:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D WITH_CUDA=OFF \
    -D ENABLE_CXX11=ON \
    -D BUILD_opencv_legacy=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
    -D WITH_GSTREAMER=ON \
    -D WITH_GSTREAMER_0_10=OFF \
    -D WITH_FFMPEG=ON ..

Does anybody know if I’m missing something that must be done (in the Container) so this works?

Hi,
Please check if you can successfully run this python sample:
Stream processed video with OpenCV on Jetson TX2 - #5 by DaneLLL

You may check this repository.

Hi, I ran the python sample. It worked correctly when running it in the Xavier itself. However, when running it in th eDocker container, I get the following output:

[ERROR:0] global /root/opencv_build/opencv/modules/videoio/src/cap.cpp (162) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.3-dev) /root/opencv_build/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): filesrc location=/home/nvidia/Documents/test2.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink   in function 'icvExtractPattern'


Src opened, 0x0 @ 0 fps
Failed to open output

As far as I know, that error may be due to a) the path of the video source being incorrect (which I’ve made sure to be right) or b) not having compiled OpenCV with FFMPEG (which, as you can see in the flags, I did).

Any further ideas on this?

Thanks for your help.

Hi,
The error shows it uses OpenCV libs which are not built with WITH_GSTREAMER=ON. Are you able to try the default 4.1.1 installed through SDKManager? Please refer to
L4T Docker Container OpenCV issue - #2 by dusty_nv

Or build OpenCV inside docker. It is suggested in
Jetson docker image opencv

Hi, thanks for your help. I will try this as soon as I can, but I’m not sure when. Once I’ve done it, I’ll let you know.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.