Running multiple USB cam on nano | Error: Failed to allocate required memory

Hi I am trying to below simple gstreamer command to run usbcam.
1 camera runs fine.
More than 1 camera, it throws error.

gst-launch-1.0  v4l2src device=/dev/video1 io-mode=2 ! image/jpeg,width=640,height=480 ! jpegdec ! 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 required memory.
Additional debug info:
gstv4l2src.c(658): gst_v4l2src_decide_allocation (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
Execution ended after 0:00:00.044375661
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
nano@nano:~$

Below is my cameras property

nano@nano:~$ v4l2-ctl -d1 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'MJPG' (compressed)
	Name        : Motion-JPEG
		Size: Discrete 1920x1080
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.017s (60.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'YUYV'
	Name        : YUYV 4:2:2
		Size: Discrete 1920x1080
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 640x480
			Interval: Discrete 0.017s (60.000 fps)

My all cameras are same company make and model.

If this a problem in nano itself, I wonder how can attach 4-5 usb cam on jetson xavier?

Hi jai.prakask,

I haven’t tested several USB cameras on Nano or Xavier but I remember a similar issue on one project, I will refer your question to the team that faced a similar issues with several USB cam to provide you more details about a possible solution.

Regarding your question on Xavier, a USB Hub (use USB3.0 due to bandwith and power consumption of cameras) will help you to connect several USB cameras but I cannot guarantee that this case works because I haven’t tested too many USB cameras.

Is there a reason to use USB connection?
In similar cases we have develop projects using the CSI camera port to connect 6 cameras on TX2 or Xavier, we also used a SerDes configuration with D3 to enable 8 cameras on Xavier (D3 used 16 cameras simultaneously).

Example here (8x cam): NVIDIA Jetson Xavier | Multi-camera AI demo | RidgeRun

FPD Link III (16x cam): FPD-Link III Virtual Channel ID | FPD-Link III | MIPI CSI-2 | RidgeRun

I am mentioning these examples because I have never seen several USB cameras running simultaneously on any Jetson board (maybe there are bandwidth or USB power problems but I’m not sure), for those cases I saw CSI or SerDes solutions.

Just in case, the SATA port on Xavier devkit is also USB, and there is a USB-C port that may help to connect several USB devices.

Greivin F.

Hi,
Please check

Suggest you use USB3 cameras.

I have 4 USB3.0 cams, ELP SUSB1080P01-L170.

What I can infer is, Nano has 1 USB3.0 controller. So, only 1 high speed channel.

But, if I try to stream only MJPEG. Then also more than 1 MJPEG stream throwing error(below). I figured out 640x480 MJPEG needs ~5MB/s (MegaBytes). I am wondering, why in MJPEG also more than one camera can’t work!!

gst-launch-1.0  v4l2src device=/dev/video1 io-mode=2 ! image/jpeg,width=640,height=480 ! jpegdec ! 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 required memory.
Additional debug info:
gstv4l2src.c(658): gst_v4l2src_decide_allocation (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
Execution ended after 0:00:00.046144432
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

Since I have bought all 5 cameras for my project. I guess workaround for jetson xavier would be using 2 USB-C and 1 eSATA and arrange below PCIe card for more USB controller.
E.g. https://www.amazon.it/Sedna-Adattatore-compatibile-supporto-UPD720201-chipset/dp/B0183H6D4I

Not sure, but does one of the following work ?

gst-launch-1.0 -v v4l2src device=/dev/video1 ! image/jpeg, width=640, height=480, framerate=60/1, format=MJPG ! jpegdec ! xvimagesink

gst-launch-1.0 -v v4l2src device=/dev/video1 ! image/jpeg, width=640, height=480, framerate=60/1, format=MJPG ! jpegparse ! jpegdec ! xvimagesink

Actually both of your pipeline worked well.

Problem is when I try to use them with 2 cam simultaneously, I throws ‘v4l2src0: Failed to allocate required memory error’

I even tried very simple pipeline:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! image/jpeg, width=640, height=480,
framerate=60/1, format=MJPG ! fakesink   ✔

gst-launch-1.0 -v v4l2src device=/dev/video1 ! image/jpeg, width=640, height=480,
framerate=60/1, format=MJPG ! fakesink  ✖ {Simultaneous}

Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = image/jpeg, width=(int)640, height=(int)480, framerate=(fraction)60/1, format=(string)MJPG, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:7:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = image/jpeg, width=(int)640, height=(int)480, framerate=(fraction)60/1, format=(string)MJPG, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:7:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = image/jpeg, width=(int)640, height=(int)480, framerate=(fraction)60/1, format=(string)MJPG, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:7:1, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = image/jpeg, width=(int)640, height=(int)480, framerate=(fraction)60/1, format=(string)MJPG, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)2:4:7:1, interlace-mode=(string)progressive
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed to allocate required memory.
Additional debug info:
gstv4l2src.c(658): gst_v4l2src_decide_allocation (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
Execution ended after 0:00:00.045476816
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
nano@nano:~

To be honest, once I saw it was working by luck. Then double checked by re-plugging USB. But, then after it stopped working. :(

You would try to update your cameras firmware if any (on host, maybe Windows is required).

Furthermore, you may post the output of :

lsusb
lsusb -t

While testing, I’d suggest to monitor kernel messages in another terminal with:
dmesg --follow
If you see bad faults, it would be better to reboot than continuing in unknown state.

Is it the same with cam1 and cam2 (say not using cam0) ? And using only one gst-launch ?

gst-launch-1.0 -v v4l2src device=/dev/video1 ! image/jpeg, width=640, height=480, framerate=60/1, format=MJPG ! fakesink      v4l2src device=/dev/video2 ! image/jpeg, width=640, height=480, framerate=60/1, format=MJPG ! fakesink  

Less and less probable, you may try to set sync to false or async to true.
Or adding queue or tee or identity drop-allocation=true before fakesink.

Last, you would set GST_DEBUG=*:3 to get debug level 3 (or more, but may be very verbose) and check for first errors.

image

I tried all combination of two possiblew with 3 camera. But than one working simultaneously, throws same error.

I tried sync property false of fakesink, but no luck.
I tried queue, identity drop-allocation=true before fakesink, again same error.

I tried to set GST_DEBUG=*:3 and then I ran camera pipelines in same terminal. I found same length of error. No extra verbose.

I know this basic v4l2 utility cmd
v4l2-ctl -d0 --set-fmt-video=width=1280,height=720,pixelformat=MJPG --stream-mmap
image

As is indicated, simultaneous MJPG streaming is throwing error.

In dmesg --follow. It reflects similar issue as before…

Not enough bandwidth for new device state.
Not enough bandwidth for altsetting 17

Does this improve ?

sudo rmmod uvcvideo
sudo modprobe uvcvideo quirks=640

[EDIT: This would not work for a MJPG stream. Sorry for the confusion].

Sorry, I am confused. Shall I try this suggestion?

No, it would not work for MJPG streams.

But what you could try could be using a USB2 hub for connecting 2 cameras. I suspect a driver issue.
USB2 bandwith is lower, but it may be enough for 2 cameras or more with very low resolution and framerate… In your case, not sure you can really down the framerate.

yea, me too