Log in

View Full Version : Audio Slightly Out of Sync


MysteryX
13th January 2016, 20:54
I have this script to play videos in real-time. It's working pretty well.

However, I'm seeing that there's a very slight delay between the audio and the video. I found that for one video, I have to add "DelayAudio(.0016)" to get it in perfect sync. Another video, however, will have a different delay so I can't fix it that way.

When I'm encoding the audio and video instead of playing it live, the sync is perfect. What could be causing such a delay?


P="Encoder\"
LoadPlugin(P+"TimeStretch.dll")
Import(P+"UUSize4.avsi")
SetMTMode(3,4)
LoadPlugin(P+"LSMASHSource.dll")
file="BoA - Kiss My Lips.mkv"
LWLibavVideoSource(file, cache=false, threads=2)
AudioDub(LWLibavAudioSource(file, cache=false))
SetMTMode(2)
UUSize4(mod=4)
ResampleAudio(48000)
TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)

geometer
13th January 2016, 21:10
for playback, why do you resample and change pitch? probably this degrades audio quality. perhaps it adds the complexity that leads to your problem.
(BoA fan here! :o )

MysteryX
13th January 2016, 21:16
To change the pitch from 440hz to 432hz. Try both side-to-side and see which one you prefer.

The way I'm doing it, the audio degradation is very minor.

However, I don't want to re-encode the repitching as I then lose considerable quality during re-encoding, so I'd rather do it on the original audio.

sneaker_ger
13th January 2016, 21:32
I have to add "DelayAudio(.0016)" to get it in perfect sync.
You can hear a difference of 1.6 ms?

geometer
13th January 2016, 21:32
Ah, I see, but then, you might just re-encode the audio (perhaps lossless format) and mux it with the original video.

resampling at studio quality is very hitech, you may check Voxengo r8brain..

MysteryX
14th January 2016, 00:05
You can hear a difference of 1.6 ms?
It feels slightly "off", yes. Especially when running it with SVP at 60fps.

Re-encoding is an option that works, but I'd rather avoid it if possible.

MysteryX
14th January 2016, 00:32
I was thinking... if LWLibavSource works fine when encoding, then it must not be its fault. It's probably AviSynth's fault.

So I tried with AviSynth+ MT. Now the timing is good.

MysteryX
14th January 2016, 05:59
Then there's the problem that SVP doesn't synchronize audio and video with AviSynth+... but I think some people got it working, perhaps a setting to adjust in ffdshow or something.

wonkey_monkey
14th January 2016, 09:44
It feels slightly "off", yes. Especially when running it with SVP at 60fps.


1.6ms equates to a distance, at the speed of sound, of 0.5m. So moving 50cm further away from your source will have the same effect on your ears.

In other words, it seems remarkably unlikely that anyone could notice a delay of 0.0016s. It's more likely that adding the delayaudio does something unexpected to playback (I don't know what), if there really is a difference.

raffriff42
14th January 2016, 14:36
I was gonna say something like that, davidhorman. Except in feet (1mS is the time it takes for sound to travel one foot.)

There is a limit to the precision of time stretchers, frame rate converters etc: in video, frame rates are stored as ratios of 2 signed, 32bit integers. Therefore the closest, best-case framerate resolution is 32766/32767, or 0.99996948. http://avisynth.nl/index.php/TimeStretch

This is NOT a sample exact plugin. If you use it, slight inaccuracies might occur. Since we are dealing with float values rounding errors might occur, especially on large samples. In general however inaccuracies should not exceed a few 10's of milliseconds for movielength samples.

Not to mention, you can't timestretch by fractional frames, only whole ones.

raffriff42
14th January 2016, 15:32
By the way, to experience the (unlikely) benefits of A=432 tuning, the actual instruments should be tuned that way, and the recording should be as pristine as possible (32 bit, 192kHz lossless) - certainly not resampled and pitch-shifted.

MysteryX
14th January 2016, 19:00
I confirm that it is TimeSretch that causes the slight delay. It appears to be the combination of TimeStretch and AviSynth 2.6, as it works fine with AviSynth+

Whether the small delay is an issue, and whether there are benefits to this, is a totally separate discussion that is up to each user to decide for themselves.

MysteryX
14th January 2016, 19:19
Re-tuning with this script doesn't have the delay; but then it slows down the playback speed.

V=AssumeFPS(432.0/440.0*FrameRate)
A=AssumeSampleRate(int(432.0/440.0*AudioRate))
AudioDub(V, A)


Btw, studio-quality headphones don't have "speed of sound" delays, and I don't like to compromise.

geometer
14th January 2016, 21:31
eventually, the quality will depend on the upsampling techniques in the audio drivers and soundcard.
a shared device will not adapt its sample rate to the source, but resample. (some sound editors and DAWs might claim exclusive use of a device though)