Switching between webcams during runtime - Works on Windows, not OSX

We’re using ofVideoGrabber to get webcam streams. The intent is to use GUI elements to switch between connected cams. In switching, we close the initialized one, set the ID, then initialize the new one:

cam.close();
cam.setDeviceID(num);
cam.setup(w, h);

This works on Windows 10, but not in OSX. We’re able to switch once, but not again after that.

I’m attempting to initialize multiple VideoGrabber objects to switch between, but that’s giving unhandled exceptions I can’t seem to track down.

Is there a commonly accepted way to do this that works cross platform?

Here is something I hacked together a year ago which seems to work
Tried with a Logitec USB cam and the inbuilt cam on my macbook.(OSX 10.11.6)

1 Like

Same issue here on El Capitan, I ended up creating a vector of videoGrabber and use a videoGrabber pointer to choose which one I update to grab the texture.

Looks like yours and steely’s solutions are similar.

Was hoping to avoid initializing and running all cameras simultaneously, to avoid conflicts with other software that may be using them.

Will try doing it that way though.

Yes, that’s what I want to do in the futur too !
I know this block the camera for the other apps. I did try with Photobooth to use a camera that was initialized in my app but not updated, and this wasn’t possible.

I would have thought that multiple apps trying to control the same physical camera at the same time
could cause problems.

Another idea is to use a streamer/server app. that just rebroadcasts from each camera
and other apps can tap into the stream as needed.

I posted about this the other day, there is a work around with ofVideoGrabber pointer.

So what ended up working was creating a pointer for the active cam, and a vector of ofVideoGrabbers.
Initialize one available device on each grabber.
Switching is just changing which index of the vector we’re pointing to.

That means all cameras are held by the software. This seems to only be a problem in Windows - no other software will be able to use the cameras. In OSX we were able to have multiple programs using cameras simultaneously, so maybe it’s a driver limitation.