Skip to content

Commit 4885e43

Browse files
authored
added static function to set preferred subtype for Directshow capture / Windows (#8433)
* added static function to set preferred subtype for Directshow capture / Windows * missing implementation
1 parent f727cb3 commit 4885e43

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

libs/openFrameworks/video/ofDirectShowGrabber.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include "ofDirectShowGrabber.h"
22
#include "ofUtils.h"
33
#ifdef TARGET_WIN32
4+
5+
//--------------------------------------------------------------------
6+
//Static members / functions
7+
8+
int ofDirectShowGrabber::preferredFormat = -1;
9+
10+
void ofDirectShowGrabber::setPreferredFormat(int aPreferredFormat) {
11+
preferredFormat = aPreferredFormat;
12+
}
13+
14+
415
//--------------------------------------------------------------------
516
ofDirectShowGrabber::ofDirectShowGrabber(){
617

@@ -51,6 +62,9 @@ bool ofDirectShowGrabber::setup(int w, int h){
5162
height = h;
5263
bGrabberInited = false;
5364

65+
if (preferredFormat >= 0) {
66+
VI.setRequestedMediaSubType(preferredFormat);
67+
}
5468
if( attemptFramerate >= 0){
5569
VI.setIdealFramerate(device, attemptFramerate);
5670
}

libs/openFrameworks/video/ofDirectShowGrabber.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{
3232
ofDirectShowGrabber();
3333
virtual ~ofDirectShowGrabber();
3434

35+
/// \brief Sets the preffered DirectShow media subtype - MJPG / H264 can provide faster framerates
36+
///
37+
/// /use formats like: MEDIASUBTYPE_H264, MEDIASUBTYPE_MJPG, MEDIASUBTYPE_Y800 etc, default is: MEDIASUBTYPE_RGB24
38+
/// /use -1 to revert to the default behavior
39+
///
40+
static void setPreferredFormat(int aPreferredFormat);
41+
3542
std::vector<ofVideoDevice> listDevices() const;
3643
bool setup(int w, int h);
3744
void update();
@@ -56,9 +63,6 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{
5663
void setDeviceID(int _deviceID);
5764
void setDesiredFrameRate(int framerate);
5865

59-
60-
61-
6266
protected:
6367

6468
bool bChooseDevice;
@@ -70,6 +74,7 @@ class ofDirectShowGrabber : public ofBaseVideoGrabber{
7074
bool bIsFrameNew;
7175

7276
int width, height;
77+
static int preferredFormat;
7378
//--------------------------------- directshow
7479
#ifdef OF_VIDEO_CAPTURE_DIRECTSHOW
7580
int device;

0 commit comments

Comments
 (0)