Usb webcams compressed format linux

Hi,

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: http://stackoverflow.com/questions/9781770/capturing-multiple-webcams-uvcvideo-with-opencv-on-linux

"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(){


test.allocate(320,240);
test2.allocate(320,240);
test3.allocate(320,240);

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[0]->startPipeline();
gst[0]->play();


sleep(1);
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);
gst[1]->startPipeline();
gst[1]->play();






}

//--------------------------------------------------------------
void ofApp::update(){

 gst[0]->update();
if(gst[0]->isFrameNew()){

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

}


 gst[1]->update();
if(gst[1]->isFrameNew()){

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

}

if(last){
 gst[2]->update();
if(gst[2]->isFrameNew()){

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

}


}

}

//--------------------------------------------------------------
void ofApp::draw(){



test.draw(0,0);
test2.draw(320,0);
if(last)test3.draw(640,0);



}

void ofApp::exit(){

gst[0]->close();
delete gst[0];

gst[1]->close();
delete gst[1];

gst[2]->close();
delete gst[2];



}


//--------------------------------------------------------------
void ofApp::keyReleased(int key){

        sleep(0.5);
        last=true;
        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);
        sleep(0.1);
        gst[2]->startPipeline();
        sleep(0.2);
        gst[2]->play();


}