Not able to access 4 usb2.0 camera using gstreamer

I am trying to run gstreamer command to access 4 usb 2.0 cameras but I get an error “v4l2src2 failed to allocate memory” and the pipeline closes. But I am able to access 2 cameras. Below is the pipeline

gst-launch1.0 v4l2src device= /dev/video0 ! video/x-raw, width=320, height=240 ! compositor name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::width=400 sink_0::height=250 sink_1::xpos=400 sink_1::ypos=0 sink_1::width=400 sink_1::height=250 sink_2::xpos=0 sink_2::ypos=-250 sink_2::width=400 sink_2:: height=250 sink_3::xpos=400 sink_3::ypos=-250 sink_3::width=400 sink_3::height=250 v4l2src device=/dev/video2 ! video/x-raw, width=320, height=240 ! mix.sink_1 v4l2src device=/dev/video4 ! video/x-raw, width=320, height=240 ! mix.sink_2 v4l2src device=/dev/video6 ! video/x-raw, width=320, height=240 ! mix.sink_3 mix. ! videoconvert ! autovideosink sync=false.

Below is the command for two cameras:-

gst-launch1.0 v4l2src device= /dev/video0 ! video/x-raw, width=320, height=240 ! compositor name=mix sink_0::xpos=0 sink_0::ypos=0 sink_0::width=400 sink_0::height=250 sink_1::xpos=400 sink_1::ypos=0 sink_1::width=400 sink_1::height=250 v4l2src device=/dev/video2 ! video/x-raw, width=320, height=240 ! mix.sink_1 mix. ! videoconvert ! autovideosink sync=false

This command for two cameras is working fine but when I connect four cameras and run command it is crashing with error cannot allocate memory.

Please let me know how can I resolve this issue.

How can I use 4 usb 2.0 cameras with gstreamer?

Thanks & regards,
Yash

Not sure if it is a gstreamer or USB issue.
In your 4 cams pipeline, you have some wrong ypos parameters set to negative values.

First try your compositor layout and display with videotestsrc:

gst-launch-1.0 -v \
compositor name=comp \
 sink_0::xpos=0   sink_0::ypos=0   sink_0::width=400 sink_0::height=250 \
 sink_1::xpos=400 sink_1::ypos=0   sink_1::width=400 sink_1::height=250 \
 sink_2::xpos=0   sink_2::ypos=250 sink_2::width=400 sink_2::height=250 \
 sink_3::xpos=400 sink_3::ypos=250 sink_3::width=400 sink_3::height=250 \
videotestsrc pattern=0  is-live=1 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_0 \
videotestsrc pattern=18 is-live=1 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_1 \
videotestsrc pattern=22 is-live=1 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_2 \
videotestsrc pattern=1  is-live=1 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_3 \
comp. ! videoconvert ! autovideosink

If this gives the expected layout, try replacing sources one by one up to:

gst-launch-1.0 -v \
compositor name=comp \
 sink_0::xpos=0   sink_0::ypos=0   sink_0::width=400 sink_0::height=250 \
 sink_1::xpos=400 sink_1::ypos=0   sink_1::width=400 sink_1::height=250 \
 sink_2::xpos=0   sink_2::ypos=250 sink_2::width=400 sink_2::height=250 \
 sink_3::xpos=400 sink_3::ypos=250 sink_3::width=400 sink_3::height=250 \
v4l2src device=/dev/video0 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_0 \
v4l2src device=/dev/video2 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_1 \
v4l2src device=/dev/video4 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_2 \
v4l2src device=/dev/video6 ! video/x-raw, width=320, height=240 ! queue ! comp.sink_3 \
comp. ! videoconvert ! autovideosink sync=false

When you see failure, you may check last kernel error messages with:

sudo dmesg

and check if last lines mention USB issues.
You may also post the output of :

lsusb -tv

Also note that it would be better to specify a framerate and format, especially for v4l2src, check the ones available for 320x240 from your camera with:

v4l2-ctl --device=/dev/video0 --list-formats-ext

If 30 fps is supported, try:

gst-launch-1.0 -v \
compositor name=comp \
 sink_0::xpos=0   sink_0::ypos=0   sink_0::width=400 sink_0::height=250 \
 sink_1::xpos=400 sink_1::ypos=0   sink_1::width=400 sink_1::height=250 \
 sink_2::xpos=0   sink_2::ypos=250 sink_2::width=400 sink_2::height=250 \
 sink_3::xpos=400 sink_3::ypos=250 sink_3::width=400 sink_3::height=250 \
v4l2src device=/dev/video0 ! video/x-raw, width=320, height=240, framerate=30/1 ! queue ! comp.sink_0 \
v4l2src device=/dev/video2 ! video/x-raw, width=320, height=240, framerate=30/1 ! queue ! comp.sink_1 \
v4l2src device=/dev/video4 ! video/x-raw, width=320, height=240, framerate=30/1 ! queue ! comp.sink_2 \
v4l2src device=/dev/video6 ! video/x-raw, width=320, height=240, framerate=30/1 ! queue ! comp.sink_3 \
comp. ! videoconvert ! autovideosink sync=false

You may also try to specify mmap for v4l2src:

v4l2src device=/dev/video0 io-mode=2 ! ...

Last, your pipeline may be further optimized using Jetson HW rather than CPU. You may try something like:

gst-launch-1.0 -v \
nvcompositor name=comp \
 sink_0::xpos=0   sink_0::ypos=0   sink_0::width=400 sink_0::height=250 \
 sink_1::xpos=400 sink_1::ypos=0   sink_1::width=400 sink_1::height=250 \
 sink_2::xpos=0   sink_2::ypos=250 sink_2::width=400 sink_2::height=250 \
 sink_3::xpos=400 sink_3::ypos=250 sink_3::width=400 sink_3::height=250 \
videotestsrc pattern=0  is-live=1 ! video/x-raw, width=320, height=240 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=400,height=250,pixel-aspect-ratio=1/1' ! queue ! comp.sink_0 \
videotestsrc pattern=18 is-live=1 ! video/x-raw, width=320, height=240 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=400,height=250,pixel-aspect-ratio=1/1' ! queue ! comp.sink_1 \
videotestsrc pattern=22 is-live=1 ! video/x-raw, width=320, height=240 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=400,height=250,pixel-aspect-ratio=1/1' ! queue ! comp.sink_2 \
videotestsrc pattern=1  is-live=1 ! video/x-raw, width=320, height=240 ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12,width=400,height=250,pixel-aspect-ratio=1/1' ! queue ! comp.sink_3 \
comp. ! nvvidconv ! autovideosink

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