List available webcam resolutions?

Did my due diligence, apologies if I am missing an existing question like this.

In Processing, I’m used to the printArray(capture.list()); function which gives me all available resolutions and framerates of the webcam. Is there any way to get the available resolutions of the webcam? I’d like to offer the user the ability to change the resolution at runtime. To a lesser degree, I’m also interested in this for framerate.

vidgrabber.listDevices() just gives me the singular device, #0, while running in Processing gives me 8+ devices.


For me this code shows my two available devices:

auto devs = webcam.listDevices();
for(auto & d : devs) {
    std::cout << << ": " << d.deviceName << " // " <<
              d.formats.size() << " formats" << std::endl;
    for(auto & f : d.formats) {
        std::cout << "  " << f.width << "x" << f.height << std::endl;
        for(auto & fps : f.framerates) {
            std::cout << "    " << fps << std::endl;

But I just discovered something a few days ago: if I do not first call webcam.setup(), then the formats and resolutions are empty. Which I find a bit odd, because I wanted to query the resolutions to decide which one to use (like in Processing). As it is, it seems like I should setup the webcam with a resolution of 640x480, get the list of formats and frame rates, close the webcam, and start it again with one of the resolutions I got previously.

I don’t know why it can happen that you don’t even receive the list of devices. Which OS? What kind of camera? Have you tried on a different USB port or rebooting?

Edit: re reading your question, maybe you do only have one device, in which case, you can try what I suggested: first setup the camera and then get the resolutions.

That seems to work, thank you!

Next up I will try to toss the available device resolutions into an array and make them selectable via ofxGui menu so that the user can change at-will


@hamoid, @prismspecs, can I you tell me what is your configuration ?
With OF 0.10.0 + qtcreator + windows 7, the list of avalaible resolution remains empty, even after grabber.setup().

@lilive I’m on Linux with OF 0.10.0, latest qtcreator. I didn’t try on Windows.

Thank you.
This must be a platform related problem indeed.
In the ofDirectShowGrabber::listDevices() method I can see:

		std::vector <std::string> devList = VI.getDeviceList(); 
        for(int i = 0; i < devList.size(); i++){
            ofVideoDevice vd; 
            vd.deviceName = devList[i]; 
   = i;  
            vd.bAvailable = true; 

The formats field of ofVideoDevice is not setup.

Perhaps I should open an issue for that. Can I ask you what do you think @theo ?
This is not really an issue because… it appear that it is just not implemented :slight_smile:

I just read some stuff about getting the resolution list with directshow, and I fear it is a little bit overwhelming for me to implement this feature. If someone can provide the directshow code to get the list of avalaible resolutions and how to bring it in the OF code, I can help to update the ofDirectShowGrabber class and take care of the PR work.
For example I’ve found this:

By the way, there is already a request to get the resolution list before initializing the grabber for ofGstVideoGrabber:

yes this is simply not implemented in windows yet, if you want to open an issue that would help tracking it in case someone wants to implement it at some point

Thanks @arturo.