Opencv VideoCapture strange behavior on Docker L4T Image

I need to run several apps on a Jetson Orin Nano, each app on a docker container. The app needs to access an RTSP Stream and for that I use OpenCV VideoCapture class. I created a simple App that only opens the RTSP Stream (based on a gstreamer pipeline) gathers frames and prints out the FPS on the terminal every 100 frames.
It happens that when I launch multiple containers of the app when I am using the software decoder one of the containers cannot open the stream. In every experiment I did this happened. However If I use the Hardware decoder instead all the containers can make the connection. Just to see if the pipeline that uses the software decoder had any issue I run the app on the Jetson Nano without using docker and to my surprise I was able to run 13 apps at the same time, so it sounds like the issue comes from docker I guess.

Here is the zip folder with all you need to replicate the issue. (15.3 KB)

How to run multiple Apps on a Jetson Machine

Build the docker image first

  • ./

  • Create an RTSP server (Use VLC probably it is the easiest way)

  • Change the RTSP_URL env variables in the .envfile to match your RTSP url, leave the HW_DECODER=0 as it is (The App will use Software Decoder in the gstreamer pipeline)

Run 6 App instances:

  • start 6

Check logs on a different terminal

  • tail -f /var/log/syslog
    Look for a log that says: Error: Unable to open camera.
    If it shows this message means the container was not able to open the Stream

Run the App without using Docker
Open the file single_instance_no_docker.shand change the variables RTSP_URL and set HW_DECODER=0
to use the software decoder

Open several terminals and on each run:

You should see something like this:

Main Question
Why one of the containers when using Software decoder cannot connect to the RTSP Stream. And why does this not happen when using Hardware decoder or when not using docker?

Here are the Pipelines I am using in case you do not want to check the source code
Software decoder
"rtspsrc location=" + rtsp_url + " drop-on-latency=true ! rtph264depay ! h264parse ! queue ! avdec_h264 ! queue ! videoconvert ! appsink max-buffers=1 drop=true"

Hardware Decoder
"rtspsrc location=" + rtsp_url + " drop-on-latency=true ! \ rtph264depay ! \ h264parse config-interval=-1 ! \ queue ! \ nvv4l2decoder ! \ nvvidconv ! video/x-raw,format=BGRx ! \ videoconvert ! video/x-raw,format=BGR ! \ queue ! \ videorate ! video/x-raw,framerate= ! \ appsink max-buffers=1 drop=true"

We are uncertain why gstreamer avdec_h264 may fail in docker. One more thing for a try is to run like:
I got the RTSP video stream on the jetson nano and ran it for about 50 frames before returning false - #7 by DaneLLL

It is to set RTSP URL in cv2.VideoCapture() and use the software decoding in OpenCV.

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