obs-studio icon indicating copy to clipboard operation
obs-studio copied to clipboard

Audio latency on monitor

Open cmavr8 opened this issue 4 years ago • 28 comments

Platform

Operating system and version: Mac OS 10.15.7 OBS Studio version: 26.0.2

Expected Behavior

Audio output of OBS should be delivered with minimal lag/latency/delay to the audio monitor output

Current Behavior

When I first start OBS, the audio is delivered to the monitor with minimal lag. After a few minutes (as low as 10), there is a noticeable delay added to the audio stream that is output to the monitor. Over time this increases, reaching more than 1 second lag after 90 minutes of having OBS running. (Log attached in following comment, to keep this field short)

Steps to Reproduce

  1. Install OBS and either BlackHole (brew install blackhole) or VB-Cable
  2. In obs, settings > audio > Mic/Aux audio: select a microphone
  3. Monitoring device: BlackHole
  4. In the audio mixer panel (lower center), click the cog of the mic source > Advanced audio properties > next to Mic/aux, under audio monitoring, select monitor & output
  5. Hold Option and click on the audio icon at the top system bar, select BlackHole as the input device
  6. Start Photo Booth
  7. Record a video with the webcam showing your face. Say "test" and stop recording after a couple seconds. Watching the recorded video, observe your lips and note that there is no or minimal delay between audio and video. All good.
  8. Wait 20-30' (Photo Booth doesn't need to be open)
  9. Repeat steps 6 & 7. Observe that there is now a delay between lips and audio.

Additional information

I'm using a Trust USB microphone as a source. No other CPU/RAM/GPU intensive programs are running on the Mac. No video inputs or other audio sources configured in OBS. The default scene is the only one there, and is empty.

The following things do not solve the problem, once it manifests:

  • playing with (muting/unmuting etc) various settings in OBS, MacOS's MIDI audio device panel and MacOS's Sound panel.
  • using VB-Audio instead of BlackHole
  • Removing filters on the Mic/Aux
  • Using Mic/Aux 4 instead of 1
  • Using different apps to record the test video

The only workaround is to restart OBS every 10 minutes. Obviously this is problematic.

cmavr8 avatar Oct 29 '20 12:10 cmavr8

90min obs results in mic lag.log

Edit: Multiple recent threads on OBS forums report similar issues: 1, 2, 3, 4, 5, 6

cmavr8 avatar Oct 29 '20 12:10 cmavr8

It doesnt look like obs even supports increasing buffers on macosx monitors, so something other than obs in the audio chain is adding latency to monitors. OBS internally cannot add more than 1s of latency to any source before it just ignores samples from that source, but its possible obs is still underrunning its buffers prompting something else to increase its latency. If any mac experts can add a way to detect this in OBS that would be nice, but otherwise you will need to investigate some other avenue to diagnose this.

kkartaltepe avatar Oct 29 '20 15:10 kkartaltepe

Thanks for the response. I'm wondering, assuming the hypothesis that something other than OBS adds the delay, why does a restart of OBS solve the issue?

Sorry if this is a silly question, I'm not very familiar with how all this works together.

cmavr8 avatar Oct 29 '20 17:10 cmavr8

Restarting OBS will flush the buffers, which is not possible otherwise. When there is a device slowly drifting and sending back timestamps, the buffer (up to 1s) will fill and eventually cap out. Restarting OBS will "reset" this because the buffer is reinitialized, but it's pretty much always an external device misbehaving rather than something internal to OBS.

Fenrirthviti avatar Oct 29 '20 21:10 Fenrirthviti

I see, so, what other components may be responsible for this? I'm thinking:

  • the driver of the physical USB mic used as source
  • coreaudio or whatever in macOS sits between the driver and OBS
  • after OBS, the fake device's driver (BlackHole or VB-Audio)

Am I getting this right?

I understand that if this is not an OBS issue we should close this ticket. Given the number of people affected I'd appreciate if we can troubleshoot a bit more. Thanks.

cmavr8 avatar Oct 30 '20 08:10 cmavr8

Could this be related? image Edit: Probably not. This was a transient issue that was fixed by restarting coreaudio (restarting OBS didn't affect it). Weird, since I am only processing audio, so my 8 logical-core 2018 system should be able to cope.

cmavr8 avatar Oct 30 '20 10:10 cmavr8

Rendering lag is GPU overload, which shouldn't have any impact on audio. It does, however, point a finger at lack of system resources, so there could be a connection from that standpoint. If the system is being overloaded and can't send audio packets fast enough, that could absolutely cause the issues being described.

Fenrirthviti avatar Oct 30 '20 19:10 Fenrirthviti

Thanks once again for your help!

Let's see if this is considered overload: While not recording, and just using my browser, obs is processing sound, obviously. The system load looks like this: idling Note that if I do this for 10' after starting OBS, and then start recording, I already experience the delay. So whatever the problem, it builds up during this "idling" stage.

When I'm actually recording (using the photobooth app), load looks like this: while recording

If I restart OBS and restart recording, the lag is eliminated and the process monitor shows similar things to above. No change in load.

All in all, it seems to me that quite a bit of system resources are used, both in idle and recording, but within the limits of the system. What's your take?

cmavr8 avatar Oct 31 '20 09:10 cmavr8

GPU = graphics card. htop only shows CPU usage.

WizardCM avatar Nov 01 '20 09:11 WizardCM

Actually I was focusing on the load of the rest of the system. Here is the GPU load while recording: GPU load while recording

The graph looks very similar when I'm experiencing the audio delay. No visible difference.

So, the system does not seem to be overloaded, right?

cmavr8 avatar Nov 01 '20 10:11 cmavr8

In one of the forum threads I mentioned above, someone made 2 observations:

  • I have left the original Elgato Game Capture App on for an hour and the Audio stays in sync there but not on OBS.
  • when I change the audio monitoring to Monitor Off, and recording for 1 hour, there does not seem to be any delay, but the problem then becomes I cannot hear it without Monitor Only (mute output)

cmavr8 avatar Nov 02 '20 08:11 cmavr8

Another data point:

  • The internal mic of my laptop is also affected by this, but much less than the external USB mic

To make the problem easier to understand, I made a short video: https://youtu.be/y_P6GxZhIuU

cmavr8 avatar Nov 03 '20 15:11 cmavr8

I have the same problem with audio delay on monitoring my elgato(Windows 10). Like it already mentioned, after approx 1 hour i've got this problem.

I do only streaming, no recording. And the interesting thing is, that the stream works in sync. So I have 1 second delay, but my Viewer told me, that he doesn't have any delay between Audio and Video. So the issue is i think on the "monitoring"-Feature.

To reset it i just hide the source through the "eye" (image).

And after few seconds I make it visible again. And then its fixed for approx. one hour.

alextiekam avatar Dec 28 '20 03:12 alextiekam

Hey @alextiekam, thanks for the tip about toggling the "eye". Unfortunately it doesn't help in my situation.

I think we need someone who understands the mac OS sound subsystem well to analyze this. I unfortunately don't have the time right now to do this :/

cmavr8 avatar Dec 28 '20 15:12 cmavr8

I get a lagging when ever I open the Filters on my Mic and to remove the Lag, I disable the monitoring and then activating it back.

Then the lag of (half / full second) is gone.

negue avatar Dec 28 '20 16:12 negue

Hi @cmavr8, i'm using obs in Windows. Sorry. Forgot to mention my OS. Therefore im thinking, something is wrong within the Software.

alextiekam avatar Dec 28 '20 19:12 alextiekam

@cmavr8, OBS is currently unusable for anything else than recording or perhaps streaming to a few services. It is great that OBS introduced the virtual camera, but it is currently completely useless, as it does not feature virtual audio, and the ridiculous workaround through the audio monitor is unusable due to the latency issue. So this makes OBS completely useless for any online services like Zoom, Webex or Teams, and I hate that I have to tell people to use crap like splitcam instead of OBS, which used to be the de-facto standard for video production. I appreciate this is an open-source project and the community can decide to spend their time on things that are more fun to do. But please consider the consequences of these decisions. Thank you!

bruxy70 avatar Dec 28 '20 21:12 bruxy70

I get a lagging when ever I open the Filters on my Mic and to remove the Lag, I disable the monitoring and then activating it back.

Then the lag of (half / full second) is gone.

@negue, The fastest way I have found to fix the lag is by selecting the mic source in the sources panel, clicking on the drop-down "Device" that's in the above panel, selecting another source, clicking again, selecting my mic as source.

Hi @cmavr8, i'm using obs in Windows. Sorry. Forgot to mention my OS. Therefore im thinking, something is wrong within the Software.

@alextiekam, Interesting, so it may actually be a bug of OBS. Anyway, we need someone who understands the subsystems of one of these two OSes to analyze this 🤷

@cmavr8, OBS is currently unusable for anything else than recording or perhaps streaming to a few services. It is great that OBS introduced the virtual camera, but it is currently completely useless, as it does not feature virtual audio, and the ridiculous workaround through the audio monitor is unusable due to the latency issue. So this makes OBS completely useless for any online services like Zoom, Webex or Teams, and I hate that I have to tell people to use crap like splitcam instead of OBS, which used to be the de-facto standard for video production. I appreciate this is an open-source project and the community can decide to spend their time on things that are more fun to do. But please consider the consequences of these decisions. Thank you!

Hey @bruxy70, I'm not sure what decision you're referring to, or why this is addressed to me personally. I have not made any decisions regarding the development of OBS. I'm just a user trying to figure out how to fix the audio lag issue.

cmavr8 avatar Dec 29 '20 09:12 cmavr8

@cmavr8 , sorry, I thought you were the code owner for this. This issue does not have anyone assigned so I got confused. Sorry.

bruxy70 avatar Dec 29 '20 11:12 bruxy70

No worries mate!

cmavr8 avatar Dec 29 '20 15:12 cmavr8

I have the same problem on Ubuntu 20.04, updated weekly from the repositories. Presently on OBS Studio 25.0.3+dfsg1-2. I normally have OBS running continuously for an entire morning (about 4 hours) for a full-tech rehearsal, break, and then a live stream and backup recording for about 1.5 hours. I have multiple cameras feeding individually into OBS, and a finished soundtrack from an external hardware mixer through a USB interface. No audio processing at all in OBS...or at least not configured for it; that's the external mixer's job.

The stream and recording are always okay; only the monitor (my headphones) increases its latency as time goes on, which makes it difficult to produce the stream because what I hear in the 'phones no longer lines up with the cameras. But even then, the stream and recording are still good, and OBS's audio meter is still in time with the room. Only the monitor output itself (my 'phones) is wrong.

I also hear a "hiccup" every so often in the 'phones, so it would not surprise me if the latency is being added incrementally at those discrete moments. Each one is not enough to notice a difference, but they add up.

Unlike the previous comments, I found a workaround that does NOT require restarting OBS. I have two different audio output devices that can drive my 'phones equally well (one USB via PulseAudio and then Jack, and one built-in via PulseAudio alone), so I put a hardware switch between them. When the latency gets to be intolerable, go to OBS's Audio settings, change the Monitor output device, and flip the hardware switch to match. The latency is now reset! This can even be done during a live stream without interrupting it. The details of the audio chain don't seem to matter; just switch to a different one, and it's all good...for a while.

So that removes the maximum length of an event if you care about the monitor, but it's still annoying.

AaronD-GH avatar Mar 28 '21 13:03 AaronD-GH

Hey @AaronD-GH, thanks for sharing 👍 Maybe checkout this way too, from above:

The fastest way I have found to fix the lag is by selecting the mic source in the sources panel, clicking on the drop-down "Device" that's in the above panel, selecting another source, clicking again, selecting my mic as source.

I'm still suffering from this bug, so I use this workaround every day :)

cmavr8 avatar Mar 28 '21 17:03 cmavr8

Hey @AaronD-GH, thanks for sharing +1 Maybe checkout this way too, from above:

The fastest way I have found to fix the lag is by selecting the mic source in the sources panel, clicking on the drop-down "Device" that's in the above panel, selecting another source, clicking again, selecting my mic as source.

I'm still suffering from this bug, so I use this workaround every day :)

I didn't get a chance to try that today. We were already live by the time it did again, and I really don't want to mess with what's going out to the audience!

I also might be mistaken about the slow-and-steady part. Twice today, I heard a full cut-out that lasted about half a second, and then the monitor was delayed by that much. Just like a network glitch, except that this is all on the same machine. Both times, the meter in OBS was still correct afterwards, only my headphones (the monitor output) had that delay.

So as not to disrupt the critical live output that was still okay, I used my trick again instead of yours, and just like always, that fixed it right up. It would probably work to switch OBS twice and not use the hardware one (so if you only have one physical output but still have a virtual one or something else that doesn't go anywhere, that can work), but the second switch in OBS would take that much longer and I really want to get back to live production ASAP. I can switch the software and the hardware at the same time, so it's slightly shorter to do it that way.

AaronD-GH avatar Mar 28 '21 22:03 AaronD-GH

I've recently opened another issue with the same problem (https://github.com/obsproject/obs-studio/issues/4531). The workaround I use is, for each microphone, to use 2 "Move Source" filters on the scene where I insert my audio inputs: Move Source # 1: To disable the microphone source, wait an interval with it disabled (I got good results disabling for 100ms), and at the end enable the Move Souce # 2. Move Source # 2: To enable the microphone source, wait an interval with it enabled (I got good results with 60000ms / 1 minute), and at the end enable the Move Source # 1.

MechanicallyDev avatar Apr 16 '21 16:04 MechanicallyDev

Move Source # 1: To disable the microphone source, wait an interval with it disabled (I got good results disabling for 100ms), and at the end enable the Move Souce # 2. Move Source # 2: To enable the microphone source, wait an interval with it enabled (I got good results with 60000ms / 1 minute), and at the end enable the Move Source # 1.

So you're automatically "blinking the mic's mute button"? (to slightly misappropriate some terminology from live audio) (1/10-second cut-out every minute)

Doesn't that also cut out the stream/recording, which is still okay? (or at least was before you added the artificial "mic blink")

AaronD-GH avatar Apr 16 '21 16:04 AaronD-GH

Move Source # 1: To disable the microphone source, wait an interval with it disabled (I got good results disabling for 100ms), and at the end enable the Move Souce # 2. Move Source # 2: To enable the microphone source, wait an interval with it enabled (I got good results with 60000ms / 1 minute), and at the end enable the Move Source # 1.

So you're automatically "blinking the mic's mute button"? (to slightly misappropriate some terminology from live audio) (1/10-second cut-out every minute)

Doesn't that also cut out the stream/recording, which is still okay? (or at least was before you added the artificial "mic blink")

Exactly, I use move source to blink the mic, refreshing the buffer automatically. 100ms is fast enough that it isn't noticeable even if it happens when you're speaking, but you can decrease the blink time (it stops refreshing the buffer if it's too fast), or increase the time between each blink to one that better fit your needs.

MechanicallyDev avatar Apr 16 '21 17:04 MechanicallyDev

It seems like I was able to fix this by switching the Sample Rate to 44.1 khz (down from 48 khz) in my particular setup. I'm using an EVGA XP1 on Windows 10. Maybe this well help someone else here!!

VastleCania avatar Sep 15 '22 18:09 VastleCania

Hmm, nevermind. It was better but the delay does build up eventually in the monitor.

VastleCania avatar Sep 15 '22 20:09 VastleCania

It's unclear what exactly the original issue was, and there has since been additional logging added for buffering.

If anyone in this thread is still having the issue, can you please reproduce and provide a log file?

Fenrirthviti avatar Oct 19 '22 20:10 Fenrirthviti

Duplicate of https://github.com/obsproject/obs-studio/issues/4531

PatTheMav avatar Oct 20 '22 16:10 PatTheMav