Use GStreamer for OpenCV video source with USB camera video from Docker container

Hi

I created a container as below.

export DISPLAY=:1
xhost +
sudo docker run -it --runtime nvidia --network myappnet --device=/dev/video0:/dev/video0:rwm -e DISPLAY=$DISPLAY -v /tmp/X11-unix:/tmp/X11-unix:rw -v /home/usr/Desktop/work:/work nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3 bash

The following error is output when running cv2.VideoCapture from a Pytorch container obtained from the NGC catalog.
It works outside the container.
Please tell me the measures.

cap = cv2.VideoCapture ('v4l2src device=/dev/video0 io-mode=2 ! image/jpeg, width=(int)1920, height=(int)1080, framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink', cv2.CAP_GSTREAMER)

error content

No EGL Display 
nvbufsurftransform: Could not get EGL display connection
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: Could not get EGL display connection
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 277 
NVMEDIA: Reading vendor.tegra.display-size : status: 6 
NvMMLiteBlockCreate : Block : BlockType = 277 
NVJPGInit 553: Host1x channel open failed
NvJpeg_NvVideo_Error: tegraNvjpgMJPEGDecoderCreate: 181: NVJPGInit failed for NVJPG1 engine
NVMEDIA: cbBeginSequence: 610: NVMEDIAVideoDecoderCreate failed!
NVMEDIA: NvMMLiteNVMEDIAProcessVES: 1824: NvMediaParserParse Unsupported Codec 
Stream format not found, dropping the frame
Stream format not found, dropping the frame
NVMEDIA: NvMMLiteNVMEDIADecDoWork: 2228: NVMEDIA Video Dec Unsupported Stream 

(python3:32): GStreamer-CRITICAL **: 01:54:31.840: 
Trying to dispose element capsfilter2, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.


(python3:32): GStreamer-CRITICAL **: 01:54:31.840: 
Trying to dispose element capsfilter1, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

please help me

Would you mid to share how it’s resolved? Thanks

I agree with @kayccc , since you’ve been publicly asking for community’s help, it would be fair that you would provide your solution to community.

@kayccc @Honey_Patouceul

Hi

But I’m not sure if this is the best solution.
Please let me know if there is another best method based on this result.

Command used when error occurs.

sudo docker run -it --runtime nvidia --network myappnet --device=/dev/video0:/dev/video0:rwm -e DISPLAY=$DISPLAY -v /tmp/X11-unix:/tmp/X11-unix:rw -v /home/usr/Desktop/work:/work nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3 bash

I changed this to:

sudo docker run -it --runtime nvidia --network host --privileged=true --device=/dev/video0:/dev/video0 -e DISPLAY=$DISPLAY -v /tmp/X11-unix:/tmp/X11-unix -v /home/tes/Desktop/work/tesyolo:/tesyolo nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3 bash

Then, I was able to display the video via GStreamer on the GUI from within the container.

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