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

Performance drop on M1 Mac #99

Closed
IDDD-Dennis opened this issue Oct 6, 2022 · 16 comments · Fixed by #100
Closed

Performance drop on M1 Mac #99

IDDD-Dennis opened this issue Oct 6, 2022 · 16 comments · Fixed by #100
Labels
bug Something isn't working macOS This issue appears on macOS

Comments

@IDDD-Dennis
Copy link

IDDD-Dennis commented Oct 6, 2022

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

@letmaik
Copy link
Owner

letmaik commented Oct 6, 2022

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
Copy link
Author

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
Copy link
Owner

letmaik commented Oct 7, 2022

Seems to be the same issue discussed here: #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
Copy link
Owner

letmaik commented Oct 7, 2022

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

@IDDD-Dennis
Copy link
Author

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
Copy link

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
Copy link
Owner

letmaik commented Oct 7, 2022

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

@avinashsureka
Copy link

avinashsureka commented Oct 7, 2022

@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 #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
Copy link
Owner

letmaik commented Oct 8, 2022

@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 letmaik added bug Something isn't working macOS This issue appears on macOS labels Oct 8, 2022
@IDDD-Dennis
Copy link
Author

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

@IDDD-Dennis
Copy link
Author

Updated M1 Mac to macOS Monterey 12.6 and still getting issues

@avinashsureka
Copy link

@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
Copy link

@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
Copy link
Owner

letmaik commented Oct 26, 2022

@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
Copy link
Owner

letmaik commented Oct 26, 2022

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
Copy link

Wow, fantastic find there @avinashsureka 👏 👏 👏

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

Successfully merging a pull request may close this issue.

4 participants