OBS Screen Capture (XSHM) causes mouse to "lag"

I’ve been trying to setup OBS studio for Replay Buffer and wanted to use Screen Capture (XSHM) source. But for some reason this source causes my mouse to lag but fps doesn’t drop when playing games. I noticed that it only happens when GPU is at 99% and if i set my max fps to something low and doesn’t use that much GPU these lags stop, but i cant lower my fps because for example cs2 will be unplayable for me.
Xcomposite window capture source works just fine without any lag but i really want to use screen capture
Is there any possible fix for this?

I already asked the same question on OBS forums but got no answers.

Also not sure in which category i should ask, hope this is the right one.

im on KDE, X11.

Sir, post your output inxi -bz

System:
  Kernel: 6.9.9-arch1-1 arch: x86_64 bits: 64
  Desktop: KDE Plasma v: 6.1.2 Distro: EndeavourOS
Machine:
  Type: Desktop System: ASRock product: B650 PG Lightning v: N/A
    serial: <superuser required>
  Mobo: ASRock model: B650 PG Lightning serial: <superuser required>
    UEFI: American Megatrends LLC. v: 2.02 date: 11/17/2023
CPU:
  Info: 6-core AMD Ryzen 5 7600 [MT MCP] speed (MHz): avg: 2714
    min/max: 400/5170
Graphics:
  Device-1: NVIDIA TU116 [GeForce GTX 1660 SUPER] driver: nvidia v: 555.58.02
  Device-2: AMD Raphael driver: amdgpu v: kernel
  Display: x11 server: X.Org v: 21.1.13 with: Xwayland v: 24.1.1 driver: X:
    loaded: amdgpu,nvidia unloaded: modesetting dri: radeonsi
    gpu: nvidia,nvidia-nvswitch resolution: 1: 1920x1080 2: 1920x1080
  API: OpenGL v: 4.6.0 compat-v: 4.5 vendor: nvidia mesa v: 555.58.02
    renderer: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2
Network:
  Device-1: Realtek RTL8125 2.5GbE driver: r8169
Drives:
  Local Storage: total: 1.78 TiB used: 228.52 GiB (12.5%)
Info:
  Memory: total: 16 GiB note: est. available: 14.75 GiB used: 8.13 GiB (55.1%)
  Processes: 351 Uptime: 3h 9m Shell: Zsh inxi: 3.3.35

Could this be an nvidia related issue?

More like CPU related issue, because mouse going laggy is CPU thingy. But you are sure game runs on Nvidia, right?

So, your BIOS is old. Time to upgrade firmware :slight_smile:

IDK OBS studio and Screen Capture. Those are 2 programs or one? Can you run obs from command line: obs and see if there ae obvious errors? Same for XSHM.

XSHM is something that OBS uses for screen capture method i believe.

Tried running obs from terminal, only errors that i see are error: VAAPI: Failed to initialize display in vaapi_device_av1_supported and info: FFmpeg VAAPI AV1 encoding not supported.
When i add Screen Capture (XSHM) source i get no errors and when running a game with obs open i also see no errors but lags are present.

Hmmmm. I would guess there is no hardware encoding of video, so all work is done by CPU, so it get’s laggy.

In such case you will have a lot of fun with that: https://wiki.archlinux.org/title/Hardware_video_acceleration

You can also try different quality settings (less MB/s) / codec settings in OBS. Some older codecs could be more CPU friendly.

Welcome @domitori! :wave: :sunglasses: :enos_flag:

In OBS, you can bring up statistics to see the demand it’s placing on your system. You can see CPU overhead, as well as frame drops and such.

There is a balance to be struck between encoding overheads, and general system performance.

Heres what i see when gpu usage is 99%


More than 20% missed frames

But even when i set my maximum fps to 60 and no frames are missed i get some amount of lags.

In OBS, what encoder settings are you using? Screenshot that perhaps?


I tried using all other available encoders, no difference

Give me a moment, I’m just reinstalling OBS. From memory, check your output settings. Perhaps try setting that to no more than 1920x1080 for the moment, with an FPS of 30.

Might this be not even an encoder issue? Because i see lags on my screen even when im not recording, just when screen capture source is active

No I don’t think it is an encoder issue, which is why I moved onto the output settings. The statistics show CPU is largely untouched, but the big issue is your rendering lag.

That’s why I think it’s worth testing a standard resolution, and a framerate capped at 30fps.

OK, OBS installed. I see the error I made here. The settings I was after were under Video, whereas Output is the encoder options.

What does yours show?

When i lower fps in video settings in OBS there are less lags.
If i set fps to 1 theres like 1 small lag per second maybe? I dont really know how to explain this

Keep an eye on those statistics as you test. Those will hopefully help you find the balance.

Anything less than 30fps is going to be impractical, but perhaps the 1fps was just for testing sake.

Under Advanced, set colour format to NV12 as well. If this setting is too high, it can cause lag too.

What resolution is your source content (the screen capture)? Is it higher than 1920x1080?

its 1920x1080

1 Like

I’m out of ideas as far as sticking with XSHM screen capture is concerned. The Xcomposite window capture works ok as you’ve mentioned… and that was about the only other thing I could suggest.

The limited info I’ve noted online, seems to suggest it could be a Nvidia settings issue, but the thread is 4 years old, so I don’t know how relevant it is now. Just something to explore perhaps.

https://www.reddit.com/r/pop_os/comments/jjddmk/obs_xshm_screen_capture_stutter_with_multiple/?rdt=42510

Yeah i will probably just be using the windows capture source then.
Also i saw this thread and tried it already.
Thanks for your help though

1 Like