-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Is Audio Timestamp Calculation Correct? #959
Comments
I forked the code and did my own timestamp calculation. What I'm doing is simple - take the NDI timestamp, and subtract the duration of the audio samples received from it - and use that as the OBS Source timestamp. Since NDI's timestamps are always guaranteed to be behind the local computer, that should shift the audio frame by the appropriate amount so OBS places it in the correct spot in its buffer. In
However, the moment I apply a filter, I still get some audio issues. Will need to investigate further. |
Update: calculating the timestamp increment/decrement using all integer operations results in rounding errors of a few hundred nanoseconds per bundle of samples. With 1024 samples/audio frame being received at 48000Hz, that works out to 15,984 ns per second, or 0.016 ms inaccuracy. After switching to calculating the duration using Here's my new code.
Still seems to be some audio glitches, especially when transmitted over NDI Bridge. Still investigating. |
Further testing showed that this method would cause audio issues. I tried another method suggested by the OBS folks - just use
So far, been running for 15 minutes without any glitches in the worst-case scenario (NDI Bridge). Will continue testing. |
Update: I'm doing something similar to what OBS does in the decklink driver.
I also added another sync mode called "Synthetic" which ignores the NDI timestamp/timecode. So far, the sync/stability of video seems to be better with my sources. |
Hi, is it possible de get a build for linux of your modifications ? |
I don't know if it's related, but I've found that activating framesync causes a constant delay in the sound on the monitor, which doesn't happen when it's deactivated. |
Try this as a temp fix: |
Operating System Version
Windows 10 Pro, Windows 11 Pro
OBS Version
30.0.2
NDI Tools Version
5.6
Describe the bug
I've been hunting down some audio/video drift issues over the last few days with OBS-NDI. Here's what I've been able to find. Note this is based on my understanding of reading through the code for both OBS and obs-ndi. It may be inaccurate.
I believe there is a fundamental incompatibility between OBS' internal sync and the way OBS-NDI is computing timestamps. OBS-NDI passes timecode/timestamp direct to OBS, which I think could cause issues with sync.
Shouldn't the increment of the timestamp depend on the audio sample rate and the number of frames?
So say we get 1024 samples (that's what Screen Capture HX sends from my machine, same with my Mevos).
The increment should be:
NoSamples / SampleRate * 1000000
So:
1024 / 48000 * 1000000 = 21,333.3333
But, the timestamps or timecodes, they're not guaranteed to increment by the number of samples received. NDI sources can send audio "frames" whenever they want, and while best practice is outlined in the SDK, senders are not bound to follow it.
Here's what my Mevo camera gives for timestamps when receiving an audio frame.
If we do have a connection hiccup, we could go quite a while between frames and timestamps.
If my interpretation is correct, the way that timestamps are being calculated for the OBS source are wrong no matter what sync method you choose, as the timestamp/timecode is not guaranteed to increase in nice discrete intervals - and OBS is checking for the next expected timestamp. If it's outside that range, I think we get into buffer issues (and if the buffer grows too large, OBS just dumps out the audio).
obs-ndi takes that timestamp and multiplies it by 100
366714645333300 - 366714624000000 = 21,333,300. Which is far different from the 21333 above. And again - the timestamp/timecode from NDI is not guaranteed to increment in discrete steps that match the amount of audio samples received.
Also - in this case, my Screen Capture HX instance and my Mevo Starts send 1024 samples of audio data. I have another app that sends 1920 samples per audio frame. Again, an NDI sender can send an arbitrary number of samples per audio "frame" it sends out.
From the documentation:
Timecode: can be generated by the NDI source or synthesized by the NDI source. If synthesized, it's the current system clock time since the Unix Epoch with 100 nanosecond precision. (Again - it can be whatever the sender wants it to be)
Timestamp: Generated by the NDI SDK, it's the time (in 100 ns intervals) when the frame was submitted to the SDK - and this is based on the sender's clock.
IMO, the plugin should be looking at the # of samples received by NDI, not the timestamp/timecode of the audio frame.
Could that be the cause of some sync problems?
I could be 100% wrong about this, but my hunch is OBS doesn't like the way timestamps/timecodes are being generated.
Steps to reproduce
No response
Expected behavior
No response
Screenshots
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: