letmaik / pyvirtualcam

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

Performance drop on M1 Mac #99

Closed IDDD-Dennis closed 1 year ago

IDDD-Dennis commented 1 year ago

Describe the bug Noticeable performance drop when using pyvirtualcam on M1 mac versus Intel mac. Output stream is laggy and has low FPS. Didn't change any of the source code so not sure where I am going wrong.

letmaik commented 1 year ago

Are you using an arm64 Python together with building pyvirtualcam from source? If so, then any performance drop is unexpected. If you're using an Intel (x86-64) Python together with the wheel from PyPI then it may be less surprising since that wouldn't be native.

Can you comment on how you observed the performance drop exactly?

IDDD-Dennis commented 1 year ago

Yes, using arm64 Python together with building from source. Followed these steps to build:

git clone https://github.com/letmaik/pyvirtualcam --recursive cd pyvirtualcam pip install

From the beginning when I use virtual camera in any video app (skype, zoom, etc) the output is very low FPS and laggy.

letmaik commented 1 year ago

Seems to be the same issue discussed here: https://github.com/letmaik/pyvirtualcam/discussions/94

EDIT: Would be good to confirm the exact apps you tested with. The referenced discussion says the issue only appears on Chromium/Electron-based apps, so not Zoom.

letmaik commented 1 year ago

Also, please check if you see the same issue using OBS directly without pyvirtualcam.

IDDD-Dennis commented 1 year ago

Works on Zoom and Webex (desktop app) Doesn't work on Teams, Meet, Skype, and Slack (both desktop and Chrome web apps) Tried with Meet on Safari and it worked.

No issue using OBS directly without pyvirtualcam in all cases.

avinashsureka commented 1 year ago

I have same issue on M1. on intel, no issue native_macos_obs/virtual_output.h

I have found this problem on line 162-164 of this file. I tried to change these lines. small changes are detected. This runloop part is not exist on obs-plugin source code. [letmaik] what's your idea about this?

letmaik commented 1 year ago

@avinashsureka Can you clarify what you mean by "on Intel"? Do you mean on an M1 mac but running an Intel Python?

avinashsureka commented 1 year ago

@avinashsureka Can you clarify what you mean by "on Intel"? Do you mean on an M1 mac but running an Intel Python?

it runs well on intel mac, but same issue like as https://github.com/letmaik/pyvirtualcam/discussions/94 on M1 mac I run example python code and send webcam frames to obs virtual cam by using your pyvirtualcam. I have checked on skype app. very low framrate is detected,

letmaik commented 1 year ago

@IDDD-Dennis @avinashsureka Could you let me know your macOS versions for both Intel and M1? I don't have an M1 myself, so it's going to be hard to debug this, but at least gathering enough info would be helpful.

IDDD-Dennis commented 1 year ago

@letmaik M1 Mac macOS Big Sur 11.6 Intel Mac macOS Monterey 12.5

IDDD-Dennis commented 1 year ago

Updated M1 Mac to macOS Monterey 12.6 and still getting issues

avinashsureka commented 1 year ago

@letmaik How are you? Couldn't you resolve yet? I have a question. I have compared your virtual_output.h with plugin-main.mm of obs-studio project. Why do you use [NSRunLoop run]? objs doesn't use it. is there any problem by this? Best regards.

avinashsureka commented 1 year ago

@letmaik I found the reason. You used timestamp as mach_absolute_time() It was working on intel mac because 1000 ticks = 1 microseconds. But it was changed on m1. https://eclecticlight.co/2020/11/27/inside-m1-macs-time-and-logs/ Please read this topic. I hope it will be help to resolve this issue for you.

letmaik commented 1 year ago

@avinashsureka Great that you found the issue! Might be worth checking the source code of OBS to see how they determine time for the frames.

letmaik commented 1 year ago

For reference, this is the code that details some of the expectations on the timestamp, which indeed has to be nanoseconds: https://github.com/obsproject/obs-studio/blob/1f72dad245907b6c85a069f8813ac96ca5f891c6/plugins/mac-virtualcam/src/dal-plugin/CMSampleBufferUtils.mm#L10

janmonterrubio commented 1 year ago

Wow, fantastic find there @avinashsureka 👏 👏 👏