obsproject / obs-studio

OBS Studio - Free and open source software for live streaming and screen recording
https://obsproject.com
GNU General Public License v2.0
58.8k stars 7.83k forks source link

Upscaling/Downscaling output via "Rescale Output" vastly improves frame render time when Virtual Camera is running. #11120

Open ninbura opened 1 month ago

ninbura commented 1 month ago

Operating System Info

Windows 11

Other OS

No response

OBS Studio Version

30.2.2

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://drive.proton.me/urls/4FCVACQ1KC#wisNreIefBOl

OBS Studio Crash Log URL

No response

Expected Behavior

OBS should have the lowest average frame rendering time when streaming at the same resolution as your canvas. Regardless of whether Virtual Camera is running.

Current Behavior

OBS reports less than 1/2 the average frame rendering time when output is scaled vs non-scaled while Virtual Camera is running. This is true even when upscaling the output. One would assume that performance would decrease, not increase, when upscaling the output.

Steps to Reproduce

  1. Set base canvas to 2560x1440.
  2. Start virtual camera if it's not running.
  3. Verify that "Rescale Output" is disabled in "Output" settings.
  4. Observe frame render time before streaming.
  5. Start streaming to YouTube.
  6. Observe frame render time.
  7. Stop streaming.
  8. Stop Virtual Camera.
  9. Enable rescale output & set resolution to 3840x2160.
  10. Start Virtual Camera.
  11. Observe frame render time before streaming.
  12. Start streaming to YouTube.
  13. Observe frame render time.
  14. Contrast upscaled frame render time with native frame render time.

Anything else we should know?

I would like access to whatever pipeline grants this performance uplift without the need to scale. I want a base canvas of 3840x2160, and to stream at 3840x2160 without my average frame rendering time doubling. Unfortunately, this "hack" doesn't work when trying to "re-scale" your output to the same resolution as your canvas. I need to keep Virtual Camera enabled as this is how I stream to Discord & Microsoft Teams. I consistently stream to YouTube & one of the aforementioned applications simultaneously.

video demonstration

https://github.com/user-attachments/assets/d62a5ca5-063d-43fa-95a8-75980c88dd6c

test stream links

Fenrirthviti commented 1 month ago

Please run the test again in a portable build or with no third-party plugins installed. I am wondering if scaling disables parts of those plugins and causes the drop in rendering time. As it stands in vanilla OBS, this shouldn't be happening, and does not happen for me. Render times are identical regardless if scaling is enabled or not.

ninbura commented 1 month ago

Just ran the same test in portable mode and got the same results.

Log

Video Demonstration

https://github.com/user-attachments/assets/7f914f54-81f9-46f3-ae44-d1ff3a001bbf

derrod commented 1 month ago

This is probably just due to the GPU switching to a higher clock speed once you're scaling, resulting in the average time to render going down. Use a tool like GPU-Z to monitor the clock speed (the nvidia overlay is broken with the latest drivers): https://www.techpowerup.com/download/techpowerup-gpu-z/

ninbura commented 1 month ago

This is probably just due to the GPU switching to a higher clock speed once you're scaling, resulting in the average time to render going down.

This seemed plausible. A few years back I noticed I would get higher render times in OBS when my GPU clock was lower, so I started making sure that "Prefer maximum performance" was enabled in Nvidia control panel. This seemed to keep my GPU at the highest possible clock regardless of workload, and that still appears to be the case.

Typically I use HWiNFO for monitoring, but I installed GPU-Z just to have a second a opinion. My clocks look rock solid regardless of OBS being open or closed, and/or if I'm streaming, scaling, etc.

video demonstration

https://github.com/user-attachments/assets/d8e9d535-cedb-4dd6-a3e2-43a9b26fc28f

I think the most noteworthy thing here is that render times are only high when I'm streaming without scaling & with Virtual Camera running. If I turn off Virtual Camera or if I enable output scaling; render time returns to what you'd expect.

Output scaling must be meaningfully changing some process internally.

ninbura commented 1 month ago

More relevant info - can't replicate issue on OBS v29.1.3.

I remembered complaining on Discord about my render time increasing when I updated OBS a while ago. Dug through my Discord message history and sure enough... found the message. It was when I updated from OBS v29.1.3 to v30.0. Screenshot 2024-08-12 at 12 44 15 PM

I just ran the same test on v29.1.3 and render time does not double when streaming to YouTube at 2560x1440 without scaling & with Virtual Camera running. I did a test back to back with v29.1.3 & v30.2.2, both in portable mode, same machine, identical settings, and the same source.

OBS v29.1.3

OBS v30.2.2

Video Demonstration

https://github.com/user-attachments/assets/e5c7c2da-692f-4460-a9a3-9f6c8b4a2c4f

ninbura commented 1 month ago

Tested on an alternate PC and observed the same result.

  1. Streaming @ 2560x1440 without scaling & Virtual Camera running results in high average render time.
  2. Stopping Virtual Camera cuts average render time in half.
  3. Upscaling output to 4K cuts render time by 33% while Virtual Camera is running.
  4. Issue is not replicable on OBS v29.1.3 & lower.

Relevant System Info

OBS v29.1.3

OBS v30.2.2

video demonstration

https://github.com/user-attachments/assets/bcf5f7ba-3978-4005-90a3-17996f29363c

ninbura commented 1 month ago

Obviously, with these tests the average render time would be considered low regardless of the differing results. But the average render time is only that low because of the extremely simple configurations. Single scene, single source, etc.

However, in a real-world scenario on my capture system with complex scenes composed of many AV sources; I get peak average render times over 16ms, resulting in dropped frames. This occurs with a 4K canvas when streaming to YouTube & Discord, while also recording locally. If I rescale my output, or if I run OBS v29.1.3, my average render time drops by around 4ms. Giving me the headroom I need to avoid "Frames missed due to rendering lag".

ninbura commented 2 weeks ago

Same behavior on my work laptop, running Windows 11, connected to a RTX 3050 via Thunderbolt enclosure. However, I'm not streaming with this one, just recording.

With Virtual Camera enabled, if I scale my recording output from 1080p to 1440p my average time to render frame is cut in half.

I tested on my MacBook and did not witness the same issue. Render time does not decrease with scaling on the output.