Raspberry PI camera not working in containers

I’m trying to get the raspberry pi camera to work with my Jetson Nano in order to run video through a custom yolov5 model. I’ve managed to set the feed up and working by running this in the terminal:

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=3820, height=2464, framerate=21/1, format=NV12’ ! nvvidconv flip-method=2 ! ‘video/x-raw,width=960, height=616’ ! nvvidconv ! nvegltransform ! nveglglessink -e

However, when I run a docker container with the arguments:

sudo docker run -it --runtime nvidia --network host -v /tmp/argus_socket:/tmp/argus_socket --device=/dev/video0:/dev/video0 9b952481df12

and then run the same gst-launch-1.0… command, I get the following error:

Setting pipeline to PAUSED …

Using winsys: x11
Pipeline is live and does not need PREROLL …
Got context from element ‘eglglessink0’: gst.egl.EGLDisplay=context, display=(GstEGLDisplay)NULL;
Setting pipeline to PLAYING …
New clock: GstSystemClock
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 0
Output Stream W = 3264 H = 2464
seconds to Run = 0
Frame Rate = 21.000000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
ERROR: from element /GstPipeline:pipeline0/GstNvArgusCameraSrc:nvarguscamerasrc0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:pipeline0/GstNvArgusCameraSrc:nvarguscamerasrc0:
streaming stopped, reason error (-5)
EOS on shutdown enabled – waiting for EOS after Error
Waiting for EOS…

Does anybody have any suggestions? Also I eventually want to pass the feed into opencv using cv2.videocapture(), and so would appreciate any tips on that. Thanks a lot!

My recommendation is to try running the camera at a lower resolution (say 1920x1080 or 1280x720) since you are downsampling to 960x616 anyhow. I don’t think the rPI camera actually works at 3820x2464 in reality (for video).

Can you try one of these pipelines instead?

gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=1280, height=720, format=NV12’ ! nvvidconv flip-method=2 ! ‘video/x-raw,width=960, height=616’ ! nvvidconv ! nvegltransform ! nveglglessink -e
gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM),width=1920, height=1080, format=NV12’ ! nvvidconv flip-method=2 ! ‘video/x-raw,width=960, height=616’ ! nvvidconv ! nvegltransform ! nveglglessink -e

Hi Dusty, I tried that but it doesn’t seem to help (although it can’t hurt to have it set to that).

However I found that changing from nveglglesink to nvoverlaysink seems to allow the video to work within the container. It doesn’t pop up in a nice window and I can’t seem to resize the image on screen but seeing as the end goal is passing it to openCV this shouldn’t be an issue