V4l2src Failed to allocate Buffer when running from camera

Hi all,

I’m trying to use the camera feed from my Jetson Nano in 2 applications at the same time, through the use of v4l2loopback, but I’m having some issues.

I have created 2 v4l2 devices with v4l2loopback, and can successfully run the producer pipeline:

PRODUCER:
gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1920, height=1080, format=NV12, framerate=(fraction)30/1' ! nvvidconv ! tee name=t ! queue ! v4l2sink device=/dev/video1 t. ! queue ! v4l2sink device=/dev/video2

I have successfully created an OpenCV application that uses /dev/video1, so that’s not an issue…

But when I try to view /dev/video2 with the below pipeline, it crashes after displaying the first frame

CONSUMER:
gst-launch-1.0 v4l2src device=/dev/video2 ! xvimagesink

Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
Setting pipeline to PLAYING …
New clock: GstSystemClock
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to allocate a buffer
Additional debug info:
gstv4l2src.c(998): gst_v4l2src_create (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0
Execution ended after 0:00:00.420358169
Setting pipeline to PAUSED …
Setting pipeline to READY …
Setting pipeline to NULL …
Freeing pipeline …

If I replace the producer with videotestsrc like so, the exact same error happens:
gst-launch-1.0 videotestsrc ! tee name=t ! queue ! v4l2sink device=/dev/video1 t. ! queue ! v4l2sink device=/dev/video2

Anyone have any idea how to fix this buffer issue?

Hi,
It looks like you hit constraint of USB bandwidth. Please check
connected more than two usb cameras problem on deepstream-app (Jetson Nano Dev Kit) - #12 by DaneLLL

Suggest use USB3 cameras.

Hi DaneLLL,

I’m using an IMX219 CSI camera

But the good news is I’ve found the problem!

Simply add a max_buffers=2 argument to v4l2loopback, and that fixes the problem! So the full command is:
sudo modprobe v4l2loopback video_nr=1,2 max_buffers=2

Not entirely sure why I don’t need that argument on PC, must be to do with the amount of available memory.

Also, curiously, if using a number higher than 2 for max_buffers, it throws the same Failed to allocate buffer error