letmaik / pyvirtualcam

🎥 Send frames to a virtual camera from Python
GNU General Public License v2.0
455 stars 49 forks source link

Virtual camera is not usable in OBS #19

Closed JayFoxRox closed 3 years ago

JayFoxRox commented 3 years ago

(Note: I never tried this package on Windows; but this is from experience with my macOS port from #16)

Because this package pretends to be OBS, it's not possible to use the virtual camera in OBS, to be fed into yet another virtual camera.

Instead of this package, I'll likely switch to creating a IP-based camera to be fed into OBS (which then creates the virtual-camera itself).

The design should be improved, so this package creates its own unique virtual webcam devices (which also work in OBS). This will also be important for supporting multiple virtual cameras at once.

letmaik commented 3 years ago

When you install the virtual camera on Windows you can select how many instances you want. This Python package is hard-coded to use the first instance. You can use any of the other remaining instances in OBS.

Note that low latency was one of the goals of this package (e.g. to enable things like webcam filters etc.), and after some experiments with IP-based cameras I settled on this approach, since it's based on a ring buffer in shared memory and the fastest I could achieve.

Creating your own ad-hoc virtual camera devices is pretty hard because (at least on Windows) registration requires admin rights, which are typically not available when running Python. There is also the danger of leaving garbage behind if Python crashes for some reason such that there isn't time to unregister the device.

JayFoxRox commented 3 years ago

When you install the virtual camera on Windows you can select how many instances you want. This Python package is hard-coded to use the first instance. You can use any of the other remaining instances in OBS.

Good to know! Still feels like something that should be improved. Among other things, I'd like to see multiple virtual cameras at once.

Note that low latency was one of the goals of this package (e.g. to enable things like webcam filters etc.), and after some experiments with IP-based cameras I settled on this approach

Interesting - I'd expect a localhost socket to be very fast, but I didn't try it yet either.

Creating your own ad-hoc virtual camera devices is pretty hard because (at least on Windows) registration requires admin rights

Yes, that's why I chose your package (it's relatively easy to install). I only did a quick search but was unable to find an existing cross-platform solution - hence my macOS port. I really hope we can also find someone to implement linux, and come up with our own DAL plugin or convince OBS to move their camera configuration into a config file (so it's enough to copy the package to create more camera instances).

letmaik commented 3 years ago

Can we maybe rename this issue to keep it more focused? I think being able to select a specific virtual camera device, if multiple are available, is probably the main thing you're asking here.

JayFoxRox commented 3 years ago

I think being able to select a specific virtual camera device, if multiple are available, is probably the main thing you're asking here.

Specifically the issue is on macOS where there is a single DAL plugin, with only a single camera instance.

This means this issue is currently a meta-issue for 3 problems:

Can we maybe rename this issue to keep it more focused?

Feel free to rename this issue (or close this and create new issues with clean history).

letmaik commented 3 years ago

One more note on Windows. OBS also recently added a built-in virtual cam plugin for Windows, and similarly to macOS it's only a single device, which kind of makes sense in the context of OBS. The old external plugin is https://github.com/CatxFish/obs-virtual-cam which is not maintained anymore. Probably the old and new built-in plugin are not compatible in terms of the ringbuffer interface. For the purpose of this Python package, the old plugin is currently the way to go. The main issue I have with that plugin is that it's really meant for OBS and the installer requires an OBS installation. There is a manual method of unzipping the non-setup zip package and invoking regsvr32 to register the camera, but it would be much better if it was a proper setup. I guess one way to go could be to fork obs-virtual-cam into a stand-alone thing that's not related to OBS anymore. The same is probably true for the macOS plugin. For Linux the situation is already fine, due to v4l.

EDIT: I changed my mind on this, see also https://github.com/letmaik/pyvirtualcam/pull/25.

letmaik commented 3 years ago

This means this issue is currently a meta-issue for 3 problems:

  • macOS only has a single virtual camera instance (should track an upstream issue in OBS).

Since this is not something I can solve in this package I'm going to punt on this for now. I don't think this will happen anytime soon in OBS.

  • API does not have a way to enumerate virtual devices to attach to (should be fixed in this package by improving the API; like getVirtualDevices).

I think being able to select a known device by name is probably good enough for now, especially since it would currently only apply to Linux and users are more aware of device names (/dev/video0 etc.). I opened https://github.com/letmaik/pyvirtualcam/issues/32 for this.

  • Can not select which instance to use on Windows (should be fixed in this package by improving the API; like virtualDevice.open()).

This is outdated now as I switched to supporting only the built-in virtual camera of OBS on Windows (which only has a single instance), same as what you've done for macOS.

I'm going to close this issue now and will focus on making the existing backends stable etc.