void ofGstUtils::setDeviceID(unsigned id){ if(!camData.bInited) get_video_devices(camData); if(camData.webcam_devices.size()>id){ deviceID = id; }else{ ofLog(OF_LOG_WARNING,"ofGstUtils: selected device doesn't exist, selecting device 0"); } }
void ofGstUtils::setDeviceID(int id) { if(!camData.bInited) get_video_devices(camData); if(camData.num_webcam_devices>id) { deviceID = id; } else { // ofLog(OF_LOG_WARNING,"ofGstUtils: selected device doesn't exist, selecting device 0"); } }
bool ofGstUtils::initGrabber(int w, int h, int framerate){ bpp = 3; if(!camData.bInited) get_video_devices(camData); if(camData.webcam_devices.size()==0){ ofLog(OF_LOG_ERROR,"ofGstUtils: no devices found exiting without initializing"); return false; } ofGstVideoFormat & format = selectFormat(w, h, framerate); ofLog(OF_LOG_NOTICE,"ofGstUtils: selected format: " + ofToString(format.width) + "x" + ofToString(format.height) + " " + format.mimetype + " framerate: " + ofToString(format.choosen_framerate.numerator) + "/" + ofToString(format.choosen_framerate.denominator)); bIsCamera = true; bHavePixelsChanged = false; width = w; height = h; gstData.loop = g_main_loop_new (NULL, FALSE); const char * decodebin = ""; if(format.mimetype != "video/x-raw-yuv" && format.mimetype != "video/x-raw-rgb") decodebin = "decodebin !"; const char * scale = ""; if( format.mimetype != "video/x-raw-rgb" ) scale = "ffmpegcolorspace !"; if( w!=format.width || h!=format.height ) scale = "ffvideoscale method=2 !"; string format_str_pipeline = string("%s name=video_source device=%s ! ") + "%s,width=%d,height=%d,framerate=%d/%d ! " + "%s %s " + "video/x-raw-rgb, width=%d, height=%d, depth=24 ! appsink name=sink caps=video/x-raw-rgb"; gchar* pipeline_string =g_strdup_printf ( format_str_pipeline.c_str(), camData.webcam_devices[deviceID].gstreamer_src.c_str(), camData.webcam_devices[deviceID].video_device.c_str(), format.mimetype.c_str(), format.width, format.height, format.choosen_framerate.numerator, format.choosen_framerate.denominator, decodebin, scale, w,h); ofLog(OF_LOG_NOTICE, "gstreamer pipeline: %s", pipeline_string); GError * error = NULL; gstPipeline = gst_parse_launch (pipeline_string, &error); gstSink = gst_bin_get_by_name(GST_BIN(gstPipeline),"sink"); gst_base_sink_set_sync(GST_BASE_SINK(gstSink), true); if(startPipeline()){ play(); return true; }else{ return false; } }
void ofGstUtils::listDevices(){ if(!camData.bInited) get_video_devices(camData); for(unsigned i=0; i<camData.webcam_devices.size(); i++){ cout << "device " << i << ": " + camData.webcam_devices[i].video_device + ": " + camData.webcam_devices[i].product_name << endl; } }
bool ofGstVideoGrabber::initGrabber(int w, int h){ if(!camData.bInited) get_video_devices(camData); if(camData.webcam_devices.size()==0){ ofLog(OF_LOG_ERROR,"ofGstUtils: no devices found exiting without initializing"); return false; } ofGstVideoFormat & format = selectFormat(w, h, attemptFramerate); ofLog(OF_LOG_NOTICE,"ofGstUtils: selected device: " + camData.webcam_devices[deviceID].product_name); ofLog(OF_LOG_NOTICE,"ofGstUtils: selected format: " + ofToString(format.width) + "x" + ofToString(format.height) + " " + format.mimetype + " framerate: " + ofToString(format.choosen_framerate.numerator) + "/" + ofToString(format.choosen_framerate.denominator)); bIsCamera = true; const char * decodebin = ""; if(format.mimetype == "video/x-raw-bayer") decodebin = "bayer2rgb !"; else if(format.mimetype != "video/x-raw-yuv" && format.mimetype != "video/x-raw-rgb") decodebin = "decodebin2 !"; const char * scale = "ffmpegcolorspace "; if( w!=format.width || h!=format.height ) scale = "ffvideoscale method=2 !"; string format_str_pipeline = string("%s name=video_source device=%s ! ") + "%s,width=%d,height=%d,framerate=%d/%d ! " + "%s %s "; gchar* pipeline_string =g_strdup_printf ( format_str_pipeline.c_str(), camData.webcam_devices[deviceID].gstreamer_src.c_str(), camData.webcam_devices[deviceID].video_device.c_str(), format.mimetype.c_str(), format.width, format.height, format.choosen_framerate.numerator, format.choosen_framerate.denominator, decodebin, scale, w,h); int bpp; switch(internalPixelFormat){ case OF_PIXELS_MONO: bpp = 8; break; case OF_PIXELS_RGB: bpp = 24; break; case OF_PIXELS_RGBA: case OF_PIXELS_BGRA: bpp = 32; break; default: bpp=24; break; } if( videoUtils.setPipeline(pipeline_string,bpp,false,w,h) ){ videoUtils.play(); return true; }else{ return false; } }
void ofGstUtils::listDevices() { if(!camData.bInited) get_video_devices(camData); for(int i=0; i<camData.num_webcam_devices; i++) { // cout << "device " + ofToString(i) + ": " + camData.webcam_devices[i].video_device + ": " + camData.webcam_devices[i].product_name << endl; } }