Usb webcams compressed format linux


I would like to use 3 webcams. it’s works well with 2, but when I initialized 3 webcams
my application crash. Maybe be an usb bandwidth problem ?

the formats supported by my webcams :

Index : 0
Type : Video Capture
Pixel Format: ‘YUYV’
Name : YUV 4:2:2 (YUYV)

Index : 1
Type : Video Capture
Pixel Format: ‘MJPG’ (compressed)
Name : MJPEG

I would like to know if it’s possible to grab the “compressed” format ?
or if it’s not the problem ?

thanks in advance

it should work but never had the chance to test one, perhaps the easiest is to open that camera alone without the other 2 and see if it still crashes

I am trying to set a custom pipeline:

setPipeline("v4l2src name=video_source device=/dev/video1 ! video/x-raw,format=RGB,width=320,height=240,framerate=15/1 ", 24,false,320,240);

but I have the same probleme (it’s crash with 3)… how my cameras support “mjpg” I don’t know if it’s possible to change “video/x-raw” to get compressed image and get down the usb bandwidth?

yes, the videoplayer will always try to use a non compressed format to avoid the extra cpu usage from decompressing but something like:

setPipeline("v4l2src name=video_source device=/dev/video1 ! video/mpeg,width=320,height=240,framerate=15/1 ! decodebin ! videoconvert",24,false,320,240);

should work. i doubt though that at 320,240 the bandwidth is the problem. the bandwdth of 3 320x240 is around 10Mb/s while an HD stream at 30fps which usb2 is perfectly able to do is around 80Mb/s

About your pipeline I get nothing but no error, gst.isFrameNew() return false.

I think also that the problem about bandwidth it’s weird but I found this topic about opencv:

"I had this exact problem, using three logitech quickcam pro 9000
cameras (using ubuntu). I could read from two, but not three. In my
case, I wasn’t using opencv, but was accessing the cameras through V4L2
directly, using memory-mapped IO. Simply put, there was not enough USB
bandwidth to allocate three buffers.

I was reading in the uncompressed frames, however. As soon as I
switched the format to MJPEG, the data was small enough, and I could
read from the three cameras. I used libjpeg to decode the MJPEG stream.

I haven’t looked into how to change the image format using OpenCV, but I do know that it needs to be MJPEG to fit all that data.

Before I switched to MJPEG, I spent a lot of time trying to access
each camera one at a time, streaming a single frame before switching to
the next. Not recommended!"

I noticed that the application run with 3 webcams all of times, the first run after the reboot of ubuntu but the second run ubuntu freeze and I have to stop the machin.

it’s maybe the vidGrabber which didn’t close properly ?

I have find the pipeline to get compressed image with my webcam:

gst[0]->setPipeline(“v4l2src name=video_source device=/dev/video0 ! image/jpeg,width=320,height=240,framerate=15/1 ! decodebin ! videoconvert”, 24,false,320,240);

I have less crash with this code:

the last webcam is start with the keyboard
and I have add sleep but this version still instable.
and when I close the application I have messages of error:

“GStreamer-CRITICAL **: gst_mini_object_unref: assertion ‘mini_object-> refcount > 0’ failed”

the code:

#include "ofApp.h"

void ofApp::setup(){


gst[0]= new ofGstVideoUtils();
gst[1]= new ofGstVideoUtils();
gst[2]= new ofGstVideoUtils();

//v4l2-ctl --set-fmt-video=width=320,height=240,pixelformat=1 -d /dev/video0

gst[0]->setPipeline("v4l2src name=video_source device=/dev/video0 ! image/jpeg,width=320,height=240,framerate=15/1 ! decodebin ! videoconvert", 24,false,320,240);

gst[1]->setPipeline("v4l2src name=video_source device=/dev/video1 ! image/jpeg,width=320,height=240,framerate=15/1 ! decodebin ! videoconvert", 24,false,320,240);


void ofApp::update(){


 test.setFromPixels(gst[0]->getPixels(), 320, 240);



 test2.setFromPixels(gst[1]->getPixels(), 320, 240);



 test3.setFromPixels(gst[2]->getPixels(), 320, 240);




void ofApp::draw(){



void ofApp::exit(){

delete gst[0];

delete gst[1];

delete gst[2];


void ofApp::keyReleased(int key){

        gst[2]->setPipeline("v4l2src name=video_source device=/dev/video2 ! image/jpeg,width=320,height=240,framerate=15/1 ! decodebin ! videoconvert", 24,false,320,240);