Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyvirtualcam does not detect OBS on macOS 14: 'obs' backend: OBS Virtual Camera is not installed #111

Open
agilebean opened this issue Oct 9, 2023 · 26 comments
Labels
bug Something isn't working help wanted Extra attention is needed macOS This issue appears on macOS

Comments

@agilebean
Copy link

agilebean commented Oct 9, 2023

  • Operating system: macOS 14.0
  • Python version: 3.10
  • pyvirtualcam version: 0.10.2
  • Virtual camera (OBS, v4l2loopback, UnityCapture): OBS
  • Virtual camera version: 30.0.0-beta3

Describe the bug
OBS in 30.0.0 beta versions changed its implementation of the virtualcam to make it compatible for macOS 14 Sonoma. Now, the pyvirtualcam code does not detect the OBS virtualcam even though it is detected by Zoom or Google Meet.

The following error is thrown:

RuntimeError: 'obs' backend: OBS Virtual Camera is not installed in your system. Use the Virtual Camera function in OBS to trigger installation.

To Reproduce

The OBS virtualcam is detected by pyvirtualcam by the following Python script:

        self.virtualcam = pyvirtualcam.Camera(
            # set standard dimensions, see https://github.com/letmaik/pyvirtualcam/issues/110#issuecomment-1624273288
            width=1280,
            height=720,
            fps=30,
            device="OBS Virtual Camera",
            fmt=pyvirtualcam.PixelFormat.BGR
        )

@agilebean
Copy link
Author

agilebean commented Oct 9, 2023

After digging into the code, I narrowed down to two areas in camera.py:

                self._backend = clazz(
                    width=width, height=height, fps=fps,
                    fourcc=encode_fourcc(fmt.value),
                    device=device,
                    **kw)

and

elif platform.system() == 'Darwin':
    from pyvirtualcam import _native_macos_obs
    register_backend('obs', _native_macos_obs.Camera)

Could it be that the _native_macos_obs module must be adapted to macOS 14 changes?

The last idea I had was to look at the OBS mac-virtualcam plugin

Here I reached my limits -
Hope that helps in any way to solve this issue for macOS Sonoma!

@letmaik letmaik added bug Something isn't working macOS This issue appears on macOS help wanted Extra attention is needed labels Oct 9, 2023
@letmaik
Copy link
Owner

letmaik commented Oct 9, 2023

Thanks for reporting this, I will need a bit of time to look into it though. Is there any reason you're using a beta version of OBS? Does it work with the previous one (29)?

@agilebean
Copy link
Author

Yes, definitely.
Any version below 30.0 does not work on macOS Sonoma at all! Must have been big changes...

@lillekemiker
Copy link

I am having this same problem and I have tried OBS 28.1, 29 and 30.
Python: 3.10.12
macOS: 13.6 (22G120) Ventura
pyvirtualcam version: 0.10.2

Not sure if it's relevant to this but I am on an M2 Apple chip set, so Arm rather than Intel.

@agilebean
Copy link
Author

agilebean commented Oct 11, 2023

I am having this same problem and I have tried OBS 28.1, 29 and 30. Python: 3.10.12 macOS: 13.6 (22G120) Ventura pyvirtualcam version: 0.10.2

Not sure if it's relevant to this but I am on an M2 Apple chip set, so Arm rather than Intel.

@lillekemiker Interesting!
Officially, OBS lists Ventura as supported MacOS version.
However, there is a github issue for Ventura.

@letmaik
I went a step further and filed a github issue on obsstudio.
But they were very unsupportive as you can see.
The only hint is to look at the changes of their macos plugin, which might have direct impact on how you can change your macos plugin. Especially their macos plugin's history of changes might be insightful.

Again, here I reached my limits how I could help to expedite fixing this issue, apologies.
But it seems it is very relevant for all future macOS versions, and as Sonoma is being installed as we speak, would be wise to give it some higher priority.
If I can help by testing, let me know and @lillekemiker !

@lillekemiker
Copy link

Just to be clear, the mentioned github issue with Ventura says that they can't run OBS. I have no issue running OBS. Pyvirtualcam just can't seem to connect to it

@letmaik
Copy link
Owner

letmaik commented Oct 15, 2023

I had a quick look and here are some notes:

  • When using OBS 30 on macOS 13 or newer then OBS uses a new virtual cam method based on a Core Media camera extension instead of using the legacy DAL plugin.
  • OBS 30 still contains the DAL plugin which is used when running on macOS 12 and older.
  • pyvirtualcam has code that specifically supports the old DAL plugin method only.
  • pyvirtualcam will keep working when using macOS 12 (and older) even with OBS 30.
  • pyvirtualcam needs code changes to use the new camera extension method when running on macOS 13 and newer.
  • The relevant code that has to be integrated in pyvirtualcam is in plugin-main.mm.

If OBS 29 works on macOS 14, then the old method and pyvirtualcam may still work, but that would be a temporary work-around.

Supporting the new camera extension method of OBS 30 in pyvirtualcam will require quite a bit of effort and testing. Since I don't own a mac myself it will be tricky to do it myself. Community contributions would be much appreciated here.

@agilebean
Copy link
Author

agilebean commented Oct 17, 2023

@letmaik
Thanks a lot for taking the effort to analyse the root problem. I really hope that someone can fix this on macOS so pyvirtualcam will continue to be used by Mac users in the future.

If OBS 29 works on macOS 14, then the old method and pyvirtualcam may still work, but that would be a temporary work-around.

Thanks for this tip, I'll try it.

If this doesn't work, is there a way to make the DAL plugin still work from OBS 30?
I looked at the code but couldn't figure out how you would activate it.

@agilebean
Copy link
Author

For those who are looking for more background info, here's a good explanation why the DAL plugin doesn't work any more with OBS on macOS 14 on the OBS github issue I filed there.

@agilebean
Copy link
Author

@letmaik @lillekemiker @JayFoxRox @Jaiaid
I'm politely asking all contributors of pyvirtualcam to make a call for action on solving this issue.

As you know, pyvirtualcam has become almost a standard library for implementing a virtual camera.
Many developers work on Macbooks because they will later deploy on Linux, or they just develop on MacOS which may represent half of all OS used for local development.
As for me, I would hate to see pyvirtualcam vanish from its current position for MacOS systems in the future. However, this is about to happen as MacOS 13 onwards does not support its current media plugin. As MacOS is already in version 14.1, more and more users will stop using pyvirtualcam. That would be really sad to see, and even more so in the future.

Dear Authors of pyvirtualcam,
Can you please reach out to the community?
I think the update to the new plugin is not a major implementation issue, and @letmaik already did the analysis in his previous comment. Doing so would save pyvirtualcam for future generations, which seems to be a worthwhile endeavor.
What do you think? Is pyvirtualcam worth saving?

@JayFoxRox
Copy link
Contributor

I've originally implemented the macOS support, but despite only being 2 years ago, I don't remember even doing it 🙊 .

From what I gather from my original message at #16 it should be as simple as copying the new files from the obs-plugin directory, then use the plugin-main.mm as main.mm, adapting it a slight bit.
As I've referenced the original revision it should be trivial to port it by doing a 3-way-compare (old OBS vs new OBS vs my changes → changes in OBS + my changes).

Personally, I don't plan to work on it.

@agilebean
Copy link
Author

@JayFoxRox Thanks so much for the info

@letmaik @lillekemiker @Jaiaid
Can any of you please make an urgent call for action to implement what @JayFoxRox suggested?

There must be someone else who cares about preventing the extinction of pyvirtualcam on MacOS...

@marco-mn
Copy link

Is there a way to upvote this bug? it's resolution would be super useful!!

@agilebean
Copy link
Author

@ykk648 Congratulations - that's a genius idea to use ChatGPT for porting the script!
I can't wait to try it out, please submit soon! Thanks.

@GermanWarez
Copy link

GermanWarez commented Mar 5, 2024

I tried to port, and figured this out:

  • There was already a PR for a fix, that was removed (and most likely some more comment here that got deleted). All I could find was this: https://zhuanlan.zhihu.com/p/681749715
  • The security in MacOS was improved. In MacOS 14 developers can't use kernel extensions but use system extensions, and these must be signed with the same signature as the application. The extensions are located in the application directory, and can not be used by any other application.
  • If you want to try yourself:
    brew install objc-run
    Save the code below as test.m and then execute it with objc-run test.m
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSBundle *obsBundle = [NSBundle bundleWithIdentifier:@"com.obsproject.mac-virtualcam"];
        if (obsBundle == nil) {
            NSLog(@"Error: OBS VirtualCam bundle not found");
            return 1;  // Or handle the error in some other way
        }

        NSString *OBSVirtualCamUUID = [obsBundle objectForInfoDictionaryKey:@"OBSCameraDeviceUUID"];
        if (OBSVirtualCamUUID == nil) {
            NSLog(@"Error: OBS VirtualCam UUID not found");
            return 1;  // Or handle the error in some other way
        }

        NSLog(@"%@", OBSVirtualCamUUID);
    }
    return 0;
}

It is not a bug. It is technically not possible to use other system extensions on macOS 14, and could be added somewhere to the documentation, and that's it.

I will use the following workaround: Streaming MJPEG images to OBS.

@simplyrohan
Copy link

Have there been any developments on this? I have just heard of this library and want to use it on my Macbook. I may consider attempting to fix this, but my experience with Obj-C is limited. Other than downgrading OBS to 29, are there any other workarounds?

@GermanWarez
Copy link

It cannot be done.
If you have an Apple Developer Account (and the necessary rights) you can compile https://github.com/daily-co/daily-virtual-camera which provides a virtual camera that can ingest any video via gstreamer. With this camera installed it would be possible to create an interface in pyvirtualcam.

I didn't buy an Apple Developer Account, and that's what I did instead: I created a MJPEG server in my python application. Then I use OBS to read that stream, and use the OBS virtual camera in other apps. The delay by OBS is approx. 1 second. Or I just read the MJPEG stream in a browser, that's basically no delay.

@HughEdwards1
Copy link

I'm not clued into the specifics here -
But it seems the issue is with new security.

There's the ability with Sonoma to boot in recovery mode and enable legacy camera plugins.
I haven't seen this mentioned

This might be a temporary fix?
https://support.apple.com/en-au/108387

(along with some other code changes still required?).

@agilebean
Copy link
Author

agilebean commented May 5, 2024

@HughEdwards1 it works now!
it's really strange because i tested it a few months ago and it didn't work back then.
so finally, the solution is to activate the MacOS recovery mode, and then execute:

system-override legacy-camera-plugins-without-sw-camera-indication=on

in the terminal, then reboot.

@HughEdwards1
Copy link

@HughEdwards1 it works now! it's really strange because i tested it a few months ago and it didn't work back then. so finally, the solution is to activate the MacOS recovery mode, and then execute:

system-override legacy-camera-plugins-without-sw-camera-indication=on

in the terminal, then reboot.

Did you apply any of the additional fixes mentioned above?
Or literally just this with latest library version.

Reason I dropped into this thread is was I was curious to develop some stuff with mediapipe but couldn't get this working on my M2 mac

@kir3d
Copy link

kir3d commented May 11, 2024

Macos 14.4.1 (23E224)
OBS 30.1.2 binary for Apple Silicon from site

reboot in repair mode and execute

system-override legacy-camera-plugins-without-sw-camera-indication=on

but some error :(((

RuntimeError: 'obs' backend: OBS Virtual Camera is not installed in your system. Use the Virtual Camera function in OBS to trigger installation.

@agilebean
Copy link
Author

@kir3d
You need to open OBS Studio on Mac.
Then click on start virtual cam. Chick on stop.
Close OBS Studio.

This procedure "installs" the virtual camera feature.

@nilspo
Copy link

nilspo commented Aug 15, 2024

@agilebean
Did you do anything in addition to the system-override-command in recovery mode to make it work? For me, this did not solve the problem. I still get the error RuntimeError: 'obs' backend: OBS Virtual Camera is not installed in your system. Use the Virtual Camera function in OBS to trigger installation. even though the Virtual Camera is accessible in other applications like Webex.

  • Operating system: macOS 14.6.1
  • Python version: 3.9
  • pyvirtualcam version: 0.12
  • OBS version: 30.2.2

@agilebean
Copy link
Author

@nilspo
Sorry nothing else than that.
I don't remember if I also left the System Integrity Protection deactivated or not, but give it a try.

This may help to consider:
As this issue wasn't fixed for almost a year, I looked around at alternative solutions and I found one: WebRTC. This is open-source, and you can make a video chatroom without having to access the Unix kernel to install virtual audio and video devices which would deny the possibility of deploying everything in a serverless container. Even without that, WebRTC is really fast and you can tweak it much more easily as it's not dependent on OBS software. I asked the latter to accomodate an easier access to pyvirtualcam over a year ago but they were strictly rejecting any help.

@nilspo
Copy link

nilspo commented Aug 16, 2024

@agilebean
Thank you for your quick reply. Unfortunately, deactivating the SIP did not help either. So I will also have to look for alternatives. Thanks for the tip regarding WebRTC.

@Glyphack
Copy link

Glyphack commented Oct 2, 2024

I faced the same issue and was able to partially resolve it. I'm still continuing the path but some help guidance would be appreciated.

Firstly I could not use the mac os virtual cam because the system extension was not enabled. This was the solution after I upgraded to macos 15.

image

Then I wanted to debug the pyvirtualcam but I don't know anything about https://github.com/obsproject/obs-studio/tree/master/plugins/mac-virtualcam/src/obs-plugin. So I'm trying to see if I can use the websocket plugin(https://github.com/aatikturk/obsws-python) and set the virtual cam to output of a program and show the frames on that program or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed macOS This issue appears on macOS
Projects
None yet
Development

No branches or pull requests