letmaik / pyvirtualcam

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

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

Open agilebean opened 12 months ago

agilebean commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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

lillekemiker commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

I had a quick look and here are some notes:

~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 commented 11 months ago

@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 commented 11 months ago

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 commented 10 months ago

@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 commented 10 months ago

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 https://github.com/letmaik/pyvirtualcam/pull/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 commented 10 months ago

@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 commented 10 months ago

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

agilebean commented 8 months ago

@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 commented 7 months ago

I tried to port, and figured this out:

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

@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 commented 4 months ago

@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 commented 4 months ago

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 commented 4 months ago

@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 commented 1 month ago

@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.

agilebean commented 1 month ago

@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 commented 1 month ago

@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 commented 1 day ago

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.