You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Linux] Big latency when monitoring auxiliary audio device #3525
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
In audio mixer, right click on your audio input source and choose Advanced Audio Properties.
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.
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.
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.
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.
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.
Please provide feedback on the PR, and can you attach the log from OBS with the patch where you reach over 1s of latency as well as the logs from your pulseaudio.
This is unfortunate. I tried both workarounds #3525 (comment) and #3525 (comment) but the latency is increasing constantly.
If there's a workaround that does not use the monitoring functionality in OBS please let me know!
I use droidcam OBS but I can't get audio input out of OBS. A 'start virtual microphone' setting in OBS would be nice.
As this issue is ongoing and people are asking for workarounds, I mentioned this before but on Linux at least, if you use a real device as the sink then create a virtual microphone then the latency is not there.
I set my monitor to my internal soundcard (instead of my USB headphones, which I use as my primary audio output) and then create a virtual microphone from that:
For me, this works. I set my onboard soundcard as the monitor in OBS then I use the remapped microphone in teams/discord/collaborate/etc. It also works if I set my monitor to the HDMI speaker of my monitor, remap that and turn my monitor volume down.
There is about ~150ms latency but it doesn't grow (and this is fine for my purposes). The latency is in the pulseaudio virtual speaker that is used as the monitor. As soon as a real hardware device is used it works fine, at least for me.
I have run classes for 8 hours a day and the latency has not grown.
Whether it is the media source or a microphone input, in all cases they are monitored to pulseaudio's sink-input way from OBS.
The problem is that the sink-input buffer increases the longer a sink-input runs for an input monitored by OBS or the more media is repeated into its sink-input who stills.
For testing, I fixed the hardware latency again like my comment on Oct 2020 #3525 (comment) :
In daemon.conf :
default-fragments = 2
default-fragment-size-msec = 10
In default.pa :
load-module module-udev-detect
replaced by
load-module module-udev-detect tsched=0
For the hw sound card i got 10ms of latency without variation (3.6% cpu instead of 0.6, it's cpu consuming).
But, the sink-input from OBS increases about to +20ms -> + 100ms every media loop.
No change on this side.
(you can force the media restart by editing the media source en press enter to replay the media many times in a row)
And looking for obs media sink-input buffer increasing with:
pactl list sink-inputs
I'm looking for a way to flush all sink-inputs buffers from a pulseaudio command while waiting for a fix for OBS.
(By the way, this problem teaches me a lot about pulseaudio)
Do you have any ideas how to flush sink-input buffers with external command from OBS ?
For the patch #4908, I have 2 results on 2 machines.
The first machine on Debian 10 (pulseaudio 12.2) has a delay due to the buffer as usual.
On another machine on Debian 11 (pulseaudio 14.2) I don't have any delay anymore, the buffer doesn't exceed 20 to 30 ms.
I have installed pulseaudio 14.2 on Debian 10, I still have an increasing latency. The configuration is coming from the packages.
There is probably something with alsa and many other packages. I will upgrade the whole machine to Debian 11 and do a follow-up to this ticket.
Hey there, just to say, I always had the same issue, currently on arch, all packages at latest versions. Also had it on Pop!_OS 19.10 a year ago and on 20.04 a couple of months ago. Lag did appear even if I was monitoring real devices thru OBS.
Just to mentions this is a cross platform issue. I use the next workaround:
Create a copy of source and set it to monitoring.
Set a hotkey to show and hide it, this resets the lag.
@TRPB thanks for the workaround. The latency at least remains constant, but definitely more crackling this way. Surprisingly this didn't use to happen at all when I was using pretty much an identical setup on a laptop, but it's now giving me seconds of delay with for online classes. Have you tried #4908 and did it help you?
EDIT: No it doesn't help. Running it for longer (even when using a physical device and its monitor) still results in seconds of delay.
I haven't tried that as the hardware monitor workaround has worked fine for me for me since November last year. Strange that it hasn't worked for you, it must either be my hardware configuration or something the audio driver is doing to automatically adjust for it.
An almost proper fix would be for OBS to monitor the buildup with a watchdog, and after it hits an specified size to completely clear the buffer to get only the most recent audio.
Activity
ogmkp commentedon Sep 30, 2020
To listen pulseaudio loopback on default line-in or mic:
pactl load-module module-loopback latency_msec=1
kkartaltepe commentedon Oct 1, 2020
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 pulseaudiocovering the timespan you are running the test with obs.ogmkp commentedon Oct 1, 2020
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.
kkartaltepe commentedon Oct 1, 2020
Please provide the log, not some section you think might be relevant.
ogmkp commentedon Oct 1, 2020
There is the full log .......
kkartaltepe commentedon Oct 1, 2020
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.
kkartaltepe commentedon Oct 1, 2020
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.
ogmkp commentedon Oct 1, 2020
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?
kkartaltepe commentedon Oct 1, 2020
use a reasonable buffer size for non-realtime applications. 20ms should be plenty for OBS to keep up.
kkartaltepe commentedon Oct 1, 2020
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.
ogmkp commentedon Oct 1, 2020
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.
kkartaltepe commentedon Oct 3, 2020
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.
ogmkp commentedon Oct 3, 2020
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 ?
kkartaltepe commentedon Oct 3, 2020
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.
ogmkp commentedon Oct 3, 2020
If someone needs to comment they can.
And I invite devs to pull a request to improve this project.
I close this ticket.
20 remaining items
kkartaltepe commentedon Jun 22, 2021
Please provide feedback on the PR, and can you attach the log from OBS with the patch where you reach over 1s of latency as well as the logs from your pulseaudio.
Creanimo commentedon Jun 23, 2021
Hello everyone, first time ever writing here, so I hope I am doing it right... 😁
I think I have the same issue, but on Windows 10:
I see this issue is tagged Linux, but could there be a similar problem on Windows? Will this be addressed by the fix from the PR?
arktronic commentedon Jun 23, 2021
@Creanimo, there is also a related issue for macOS (#3664) and Windows (#4531).
bcm0 commentedon Jun 23, 2021
This is unfortunate. I tried both workarounds #3525 (comment) and #3525 (comment) but the latency is increasing constantly.
If there's a workaround that does not use the monitoring functionality in OBS please let me know!
I use droidcam OBS but I can't get audio input out of OBS. A 'start virtual microphone' setting in OBS would be nice.
TRPB commentedon Jun 23, 2021
As this issue is ongoing and people are asking for workarounds, I mentioned this before but on Linux at least, if you use a real device as the sink then create a virtual microphone then the latency is not there.
I set my monitor to my internal soundcard (instead of my USB headphones, which I use as my primary audio output) and then create a virtual microphone from that:
For me, this works. I set my onboard soundcard as the monitor in OBS then I use the remapped microphone in teams/discord/collaborate/etc. It also works if I set my monitor to the HDMI speaker of my monitor, remap that and turn my monitor volume down.
There is about ~150ms latency but it doesn't grow (and this is fine for my purposes). The latency is in the pulseaudio virtual speaker that is used as the monitor. As soon as a real hardware device is used it works fine, at least for me.
I have run classes for 8 hours a day and the latency has not grown.
ogmkp commentedon Jun 24, 2021
Whether it is the media source or a microphone input, in all cases they are monitored to pulseaudio's sink-input way from OBS.
The problem is that the sink-input buffer increases the longer a sink-input runs for an input monitored by OBS or the more media is repeated into its sink-input who stills.
For testing, I fixed the hardware latency again like my comment on Oct 2020 #3525 (comment) :
In daemon.conf :
default-fragments = 2
default-fragment-size-msec = 10
In default.pa :
load-module module-udev-detect
replaced by
load-module module-udev-detect tsched=0
For the hw sound card i got 10ms of latency without variation (3.6% cpu instead of 0.6, it's cpu consuming).
But, the sink-input from OBS increases about to +20ms -> + 100ms every media loop.
No change on this side.
(you can force the media restart by editing the media source en press enter to replay the media many times in a row)
And looking for obs media sink-input buffer increasing with:
pactl list sink-inputs
I'm looking for a way to flush all sink-inputs buffers from a pulseaudio command while waiting for a fix for OBS.
(By the way, this problem teaches me a lot about pulseaudio)
Do you have any ideas how to flush sink-input buffers with external command from OBS ?
ogmkp commentedon Jun 29, 2021
For the patch #4908, I have 2 results on 2 machines.
The first machine on Debian 10 (pulseaudio 12.2) has a delay due to the buffer as usual.
On another machine on Debian 11 (pulseaudio 14.2) I don't have any delay anymore, the buffer doesn't exceed 20 to 30 ms.
I have installed pulseaudio 14.2 on Debian 10, I still have an increasing latency. The configuration is coming from the packages.
There is probably something with alsa and many other packages. I will upgrade the whole machine to Debian 11 and do a follow-up to this ticket.
somewhatfrog commentedon Jun 30, 2021
Hey there, just to say, I always had the same issue, currently on arch, all packages at latest versions. Also had it on Pop!_OS 19.10 a year ago and on 20.04 a couple of months ago. Lag did appear even if I was monitoring real devices thru OBS.
Just to mentions this is a cross platform issue. I use the next workaround:
ogmkp commentedon Jul 11, 2021
The patch #4908 is good for me, no lag for hours on Debian 10 but only for input device, no change for medias.
ngoonee commentedon Aug 3, 2021
@TRPB thanks for the workaround. The latency at least remains constant, but definitely more crackling this way. Surprisingly this didn't use to happen at all when I was using pretty much an identical setup on a laptop, but it's now giving me seconds of delay with for online classes. Have you tried #4908 and did it help you?
EDIT: No it doesn't help. Running it for longer (even when using a physical device and its monitor) still results in seconds of delay.
TRPB commentedon Aug 3, 2021
I haven't tried that as the hardware monitor workaround has worked fine for me for me since November last year. Strange that it hasn't worked for you, it must either be my hardware configuration or something the audio driver is doing to automatically adjust for it.
MechanicallyDev commentedon Sep 16, 2021
I made a python plugin as a workaround for this issue... It just disables and enables the monitoring of an specified device every X seconds. It does this quite fast, so it is barely noticeable.
Currently the plugin is set to WASAPI (windows audio API), but it is easy to replace the input prefix on the code for people using linux (I didn't knew the prefix used for linux audio drivers).
https://github.com/MechanicallyDev/OBS-Anti-Mic-Monitoring-Desync
An almost proper fix would be for OBS to monitor the buildup with a watchdog, and after it hits an specified size to completely clear the buffer to get only the most recent audio.
HEPOSHEIKKI commentedon May 16, 2024
This is how I learned to not blindly copy paste commands...