pyvirtualcam icon indicating copy to clipboard operation
pyvirtualcam copied to clipboard

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

Open agilebean opened this issue 1 year ago • 26 comments

  • 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 avatar Oct 09 '23 10:10 agilebean

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!

agilebean avatar Oct 09 '23 10:10 agilebean

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)?

letmaik avatar Oct 09 '23 11:10 letmaik

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

agilebean avatar Oct 09 '23 11:10 agilebean

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 avatar Oct 10 '23 16:10 lillekemiker

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 !

agilebean avatar Oct 11 '23 00:10 agilebean

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

lillekemiker avatar Oct 11 '23 01:10 lillekemiker

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.

letmaik avatar Oct 15 '23 14:10 letmaik

@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 avatar Oct 17 '23 02:10 agilebean

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 avatar Oct 18 '23 12:10 agilebean

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

agilebean avatar Nov 17 '23 06:11 agilebean

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.

JayFoxRox avatar Nov 17 '23 15:11 JayFoxRox

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

agilebean avatar Nov 25 '23 08:11 agilebean

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

marco-mn avatar Nov 30 '23 18:11 marco-mn

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

agilebean avatar Feb 05 '24 10:02 agilebean

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.

GermanWarez avatar Mar 05 '24 17:03 GermanWarez

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?

simplyrohan avatar Apr 10 '24 23:04 simplyrohan

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.

GermanWarez avatar Apr 11 '24 19:04 GermanWarez

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?).

HughEdwards1 avatar Apr 16 '24 12:04 HughEdwards1

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

agilebean avatar May 05 '24 19:05 agilebean

@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

HughEdwards1 avatar May 07 '24 05:05 HughEdwards1

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.

kir3d avatar May 11 '24 18:05 kir3d

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

agilebean avatar May 11 '24 19:05 agilebean

@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

nilspo avatar Aug 15 '24 17:08 nilspo

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

agilebean avatar Aug 15 '24 20:08 agilebean

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

nilspo avatar Aug 16 '24 07:08 nilspo