Obs-studio: [Linux] Big latency when monitoring auxiliary audio device

Created on 30 Sep 2020  Â·  22Comments  Â·  Source: obsproject/obs-studio




Platform



Operating system and version: Linux Ubuntu 20.04
OBS Studio version: tested on 26.0 and 25.0.8

Expected Behavior


Turning ON monitoring and output and listen no latency.

Current Behavior



When I turn monitor and output ON in Advanced Audio Properties, the latency is approximately OK at the begining but after 5 minutes, the monitor gives some big latency.
Tested on standard pulseaudio and RT pulseaudio.
If I listen to pulseaudio line-in or mic loopback, theres no latency, never.
No warns or errors in OBS log or system logs.

Steps to Reproduce



  1. In audio mixer, right click on your audio input source and choose Advanced Audio Properties.
  2. Select Monitor and Output in Audio Montioring.
  3. Wait 5 minutes, sound loopback takes increasing latency permanently.

Additional information



That's an long time observed issue.
Was present in OBS 19, 22, 23, 24, 25.0.x and latest 26.

All 22 comments

To listen pulseaudio loopback on default line-in or mic:
pactl load-module module-loopback latency_msec=1

Provide a log from OBS, it sounds like you probably have buffer underruns due to attempting to get low latency out of pulseaudio. These might be caught by OBS resulting in us increasing our buffer thinking your device/configuration is correctly outputting data and if we wait we might actually see that lost audio.

Also provide logs from pulseaudio running in verbose logging mode. Something like journalctl --since "1 day ago" --user-unit pulseaudio covering the timespan you are running the test with obs.

There is the log:
https://pastebin.com/raw/dEEH6A1q

In pulseaudio log I have just this (when I start listening to pulseaudio loopback input):
oct. 01 14:04:48 PC-M pulseaudio[1235]: Configured latency of 1,00 ms is smaller than minimum latency, using minimum instead
oct. 01 14:04:48 PC-M pulseaudio[1235]: Cannot set requested sink latency of 2,25 ms, adjusting to 2,50 ms
oct. 01 14:04:48 PC-M pulseaudio[1235]: Cannot set requested source latency of 2,25 ms, adjusting to 2,50 ms

I have no latency on listening to pulseaudio loopback.

But I can hear clearly a big difference in monitoring between pulseaudio loopback and OBS loopback.
Aprox 400 ~ 600 ms after 5 minutes and increasing.

Please provide the log, not some section you think might be relevant.

There is the full log .......

Then you did not run pulseaudio with verbose logging. At least in OBS there is no issues with latency, its outputing the audio with at most 42ms of latency and never added any more.

It may also be possible the reverse is happening, your buffers are so low that PA is growing its buffer since OBS is not able to feed it in the 1ms you have configured. But without a usable PA log its hard to say.

There is the log of pulseaudio in debug mode.
https://pastebin.com/raw/7k3aus4Z

You are right, pulseaudio adds latency on sink device for OBS.
What are your recommendations?

use a reasonable buffer size for non-realtime applications. 20ms should be plenty for OBS to keep up.

Its also possible we dont handle resizing our buffer when notified of increases on the other side (which might be why it continues to grow past a reasonable size). Im not sure precisely how that code works.

I set in daemon.conf:
default-fragments = 2
default-fragment-size-msec = 5

but these parameters are ignored if udev module is not setted to tsched=0

I modified in default.pa
load-module module-udev-detect tsched=0 fixed_latency_range=yes

Better result and no changes are made on latency now.
I stay observating and I will close this ticket if all goes well.

Thank for your help.

just a small update but OBS appears to handling the underruns and is extending the latency of the PA buffer. Normally this is the right behavior but its still underrunning even with an enormous buffer. Im not a PA wizard but I assume this is because samples are lost from the monitored device which was configured with a tiny buffer that isnt growing as OBS tries to increase latency.

But with my fixed size of 10 msec and forcing PA to stay at a fixed latency range, I haven't latency anymore (just a little little, that is acceptable at the end of the chain for a software treatment and stills sync with video).
Do you think I can close this issue or do you want to continue investigations ?

im fine with leaving it open its probably possible to push the latency on the device being read up when not using Fixed latency. Maybe we can add a reasonable max latency as well. I dont think ill investigate much more personally, but maybe someone else will.

If someone needs to comment they can.
And I invite devs to pull a request to improve this project.
I close this ticket.

Its also possible we dont handle resizing our buffer when notified of increases on the other side (which might be why it continues to grow past a reasonable size). Im not sure precisely how that code works.

I found this thread because I have a similar (the same?) problem. I use a null-device to create something for OBS to shove into. Right after creating the device, latency is there, but small. After some time (a few minutes at most), it is a few seconds. Monitoring the latency in the output of "pactl list sinks" shows the "configured latency" increasing in steps up to 2 seconds. However, this is not the whole story.

Suspending/unsuspending the null-device gets rid of the built-up latency in pulseaudio, but there is still latency left. The only way I found so far is to close and re-open OBSstudio. It looks to me like OBS is doing some internal buffering as well, which is increasing, too. Your comment makes me think it might actually adapt to pulseaudio increasing, but does not recognize that is might also decrease.

The other question apart from OBS going back to less latency would be why this is building up in the first place. What would be a good way to debug that?

Finally: should we reopen this issue or open a new one? OBSstudio should, after all, work with the default configuration of major distributions, or at least recognize this being a problem and possibly display a warning.

And after hours of production, I still have the issue, the latency increases after 20 ~ 30 mins on some OBS sessions and not for others ones.
I have to disable monitoring and re-enable again (don't need to close the software) to get a new source for pulse and get no latency again.

@maxdrash : what exactly do you mean by "disable monitoring"? I could set the "monitoring device" to "default", but not sure what device that would then be. Or is there another setting to disable monitoring entirely? (I usually set it to the null-device I manually created)

Like I said at the beginning of this issue -> Right click on sources sounds -> Advanced audio properties -> Audio monitoring: Monitor and Output, or, Monitor OFF.

Like I said at the beginning of this issue -> Right click on sources sounds -> Advanced audio properties -> Audio monitoring: Monitor and Output, or, Monitor OFF.

Just tested and can confirm: this also works for me. It's not a solution, but at least I don't have to close/reopen OBSstudio now, so I can do that even while streaming. Thanks!

I've been struggling this for weeks and have found a workaround that at least works for me. I was getting ~8 seconds of delay by the end of a 4 hour teaching block which is really annoying.

I've been using a Virtual speaker/null device to capture the audio and then use module remap to remap it to a microphone for use in browsers.

After trial and error I've worked out that the cause is the the Virtual Speaker. Using a real audio device solves the problem for me. I just enabled my HDMI audio output and set up OBS to monitor to that instead of a virtual speaker, then remapped that to appear as a source. So far I've not had any unreasonable delays. There is about a 0.2s latency but it's consistent and fine for my needs. If you have a hardware audio device you're not using, just use that as your monitor instead.

I’m facing the same problem (increasing monitoring delay). I’m all but an expert on PA and how sound is being played on linux.
I first noticed the progressive lag while I was streaming. After some tests I discovered that not all audio source behave in the same way. As an example I’ve added three audio input (USB webCam, wired jack mic and, phone through wifi). At the begining all audio are synced and time passing they become unsynced with huge delay for some.

  • The streaming isn’t affected nor the recording only the monitoring.
  • The graphical db meter stays synced all the time (every sources are synced, a clap is a good test)
  • I’m using my default audio for loopback, I haven’t configured anything fancy …
  • Every input uses the same monitoring channel (obviously)
    I can confirm that deactivating the monitoring and re activating it suppresses the delay.

I also had this problem this morning using another laptop and capturing audio through CamLink : The stream is OK but I had delay on monitoring.

I’m using majaro linux and OBS 26.0.2-2 packed with it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Slapbox picture Slapbox  Â·  10Comments

DaWe35 picture DaWe35  Â·  7Comments

HumbertoStrada picture HumbertoStrada  Â·  8Comments

Marocco2 picture Marocco2  Â·  9Comments

curya picture curya  Â·  10Comments