From bbba5e81d5212e88bf64a14e3dd80155c8e56c60 Mon Sep 17 00:00:00 2001 From: ofTheo Date: Sat, 19 Apr 2025 14:44:33 -0700 Subject: [PATCH 1/2] added static function to set preferred subtype for Directshow capture / Windows --- libs/openFrameworks/video/ofDirectShowGrabber.cpp | 11 +++++++++++ libs/openFrameworks/video/ofDirectShowGrabber.h | 11 ++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libs/openFrameworks/video/ofDirectShowGrabber.cpp b/libs/openFrameworks/video/ofDirectShowGrabber.cpp index a29428d8604..e135bd83df6 100644 --- a/libs/openFrameworks/video/ofDirectShowGrabber.cpp +++ b/libs/openFrameworks/video/ofDirectShowGrabber.cpp @@ -1,6 +1,17 @@ #include "ofDirectShowGrabber.h" #include "ofUtils.h" #ifdef TARGET_WIN32 + +//-------------------------------------------------------------------- +//Static members / functions + +int ofDirectShowGrabber::preferredFormat = -1; + +void ofDirectShowGrabber::setPreferredFormat(int aPreferredFormat) { + preferredFormat = aPreferredFormat; +} + + //-------------------------------------------------------------------- ofDirectShowGrabber::ofDirectShowGrabber(){ diff --git a/libs/openFrameworks/video/ofDirectShowGrabber.h b/libs/openFrameworks/video/ofDirectShowGrabber.h index 96545e48dcb..bacdbc21b5f 100644 --- a/libs/openFrameworks/video/ofDirectShowGrabber.h +++ b/libs/openFrameworks/video/ofDirectShowGrabber.h @@ -32,6 +32,13 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{ ofDirectShowGrabber(); virtual ~ofDirectShowGrabber(); + /// \brief Sets the preffered DirectShow media subtype - MJPG / H264 can provide faster framerates + /// + /// /use formats like: MEDIASUBTYPE_H264, MEDIASUBTYPE_MJPG, MEDIASUBTYPE_Y800 etc, default is: MEDIASUBTYPE_RGB24 + /// /use -1 to revert to the default behavior + /// + static void setPreferredFormat(int aPreferredFormat); + std::vector listDevices() const; bool setup(int w, int h); void update(); @@ -56,9 +63,6 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{ void setDeviceID(int _deviceID); void setDesiredFrameRate(int framerate); - - - protected: bool bChooseDevice; @@ -70,6 +74,7 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{ bool bIsFrameNew; int width, height; + static int preferredFormat; //--------------------------------- directshow #ifdef OF_VIDEO_CAPTURE_DIRECTSHOW int device; From 48354aebefb554635c814e69878cec8db8ab34ec Mon Sep 17 00:00:00 2001 From: ofTheo Date: Sat, 19 Apr 2025 14:47:32 -0700 Subject: [PATCH 2/2] missing implementation --- libs/openFrameworks/video/ofDirectShowGrabber.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/openFrameworks/video/ofDirectShowGrabber.cpp b/libs/openFrameworks/video/ofDirectShowGrabber.cpp index e135bd83df6..39f4e486a2a 100644 --- a/libs/openFrameworks/video/ofDirectShowGrabber.cpp +++ b/libs/openFrameworks/video/ofDirectShowGrabber.cpp @@ -62,6 +62,9 @@ bool ofDirectShowGrabber::setup(int w, int h){ height = h; bGrabberInited = false; + if (preferredFormat >= 0) { + VI.setRequestedMediaSubType(preferredFormat); + } if( attemptFramerate >= 0){ VI.setIdealFramerate(device, attemptFramerate); }