pyvirtualcam icon indicating copy to clipboard operation
pyvirtualcam copied to clipboard

Performance drop on M1 Mac

Open IDDD-Dennis opened this issue 2 years ago • 11 comments

  • Operating system: M1 mac
  • Python version: Python 3.8
  • pyvirtualcam version: Latest
  • Virtual camera (OBS, v4l2loopback, UnityCapture): OBS
  • Virtual camera version: Latest

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.

IDDD-Dennis avatar Oct 06 '22 12:10 IDDD-Dennis

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?

letmaik avatar Oct 06 '22 18:10 letmaik

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.

IDDD-Dennis avatar Oct 07 '22 00:10 IDDD-Dennis

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 avatar Oct 07 '22 07:10 letmaik

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

letmaik avatar Oct 07 '22 07:10 letmaik

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.

IDDD-Dennis avatar Oct 07 '22 14:10 IDDD-Dennis

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?

avinashsureka avatar Oct 07 '22 14:10 avinashsureka

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

letmaik avatar Oct 07 '22 14:10 letmaik

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

avinashsureka avatar Oct 07 '22 14:10 avinashsureka

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

letmaik avatar Oct 08 '22 15:10 letmaik

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

IDDD-Dennis avatar Oct 09 '22 17:10 IDDD-Dennis

Updated M1 Mac to macOS Monterey 12.6 and still getting issues

IDDD-Dennis avatar Oct 10 '22 15:10 IDDD-Dennis

@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 avatar Oct 20 '22 15:10 avinashsureka

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

avinashsureka avatar Oct 26 '22 14:10 avinashsureka

@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 avatar Oct 26 '22 18:10 letmaik

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

letmaik avatar Oct 26 '22 20:10 letmaik

Wow, fantastic find there @avinashsureka 👏 👏 👏

janmonterrubio avatar Oct 27 '22 14:10 janmonterrubio