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();
}