View Full Version : Gradual Audio Desync
thecoreyburton
17th May 2016, 05:28
What's the best way to fix an audio track that goes gradually out of sync from a BD source?
To better explain, it's an hour long and the delay 5 minutes into the footage is 0ms, the delay half an hour into the footage is 100ms and the delay at around 55 minutes in is about 200ms. These are all estimates as I'm just lining up the audio to the lips as accurately as I can, but it definitely falls further and further out of sync.
Is there a plugin for Avisynth that can account for such a thing without altering the video's frame rate? I'd demux the audio and use an external program to do so but it's 5.1 surround and it could prove difficult for some of the more basic programs.
raffriff42
17th May 2016, 06:20
dur = 3300.0 ## total duration in seconds
adj = -0.200 ## correction needed (-0.200 = decrease audio duration by 200 msec)
Ar = AudioRate (http://avisynth.nl/index.php/Clip_properties) ## original audio sample rate
## adjust audio duration
AssumeSampleRate (http://avisynth.nl/index.php/AssumeSampleRate)(Round(dur / (dur+adj) * Ar))
## (optional) restore original sample rate while retaining new duration
ResampleAudio (http://avisynth.nl/index.php/ResampleAudio)(Ar)
* For purest sound, I would not recommend pitch correction in this case.
* You can skip the "ResampleAudio" call, if you don't mind a slightly nonstandard sample rate
* Internal math rounding may affect the adjusted duration slightly (~30ms per hour)
tormento
17th May 2016, 07:28
What's the best way to fix an audio track that goes gradually out of sync from a BD source?
Better not mess with changing FPS of video or audio. I prefer mantain original ones and stretch them within Matroska container.
thecoreyburton
17th May 2016, 08:01
Thank you riffraff42, that's exactly what I was after.
Tormento, I didn't actually know that was possible! How would I go about doing this? I knew you could adjust all kinds of properties (delay, frame output dimenisons, compression, etc) but I was unaware that stretching was possible.
tebasuna51
17th May 2016, 09:54
What is the format of your audio? AC3, DTS, ...?
tebasuna51
19th May 2016, 00:00
You can use the Tormento method, with MkvToolnixGUI, selecting the audio track and filling:
Stretch by: 0.9999333 (200 ms in 50 minutes)
That modify the timestamps of that track. But read the help at that point:
Multiply this track's timestamps with a factor.
The value can be given either as a floating point number (e.g. 12.345) or a fraction of integer values (e.g. 123/456).
This works well for video and subtitle tracks but should not be used with audio tracks.
To explain the problem let me show what happens when try to extract the track (I used a AC3 track) with eac3to (Total column added by me):
Total
-----
[a02] Audio overlaps for 5ms at playtime 0:01:08. <WARNING> 5 ms
[a02] Audio overlaps for 5ms at playtime 0:02:23. <WARNING> 10 ms
[a02] Audio overlaps for 5ms at playtime 0:03:38. <WARNING> 15 ms
[a02] Audio overlaps for 5ms at playtime 0:04:52. <WARNING> 20 ms *
[a02] Audio overlaps for 5ms at playtime 0:06:07. <WARNING> 25 ms
[a02] Audio overlaps for 5ms at playtime 0:07:22. <WARNING> 30 ms
[a02] Audio overlaps for 5ms at playtime 0:08:37. <WARNING> 35 ms
[a02] Audio overlaps for 5ms at playtime 0:09:52. <WARNING> 40 ms
[a02] Audio overlaps for 5ms at playtime 0:11:07. <WARNING> 45 ms
[a02] Audio overlaps for 5ms at playtime 0:12:22. <WARNING> 50 ms *
[a02] Audio overlaps for 5ms at playtime 0:13:37. <WARNING> 55 ms
[a02] Audio overlaps for 5ms at playtime 0:14:52. <WARNING> 60 ms
[a02] Audio overlaps for 5ms at playtime 0:16:07. <WARNING> 65 ms
[a02] Audio overlaps for 5ms at playtime 0:17:22. <WARNING> 70 ms
[a02] Audio overlaps for 5ms at playtime 0:18:37. <WARNING> 75 ms
[a02] Audio overlaps for 5ms at playtime 0:19:52. <WARNING> 80 ms *
[a02] Audio overlaps for 5ms at playtime 0:21:07. <WARNING> 85 ms
[a02] Audio overlaps for 5ms at playtime 0:22:22. <WARNING> 90 ms
[a02] Audio overlaps for 5ms at playtime 0:23:37. <WARNING> 95 ms
[a02] Audio overlaps for 5ms at playtime 0:24:52. <WARNING> 100 ms
[a02] Audio overlaps for 5ms at playtime 0:26:07. <WARNING> 105 ms
[a02] Audio overlaps for 5ms at playtime 0:27:22. <WARNING> 110 ms
[a02] Audio overlaps for 5ms at playtime 0:28:37. <WARNING> 115 ms *
[a02] Audio overlaps for 5ms at playtime 0:29:52. <WARNING> 120 ms
[a02] Audio overlaps for 5ms at playtime 0:31:06. <WARNING> 125 ms
[a02] Audio overlaps for 5ms at playtime 0:32:22. <WARNING> 130 ms
[a02] Audio overlaps for 5ms at playtime 0:33:36. <WARNING> 135 ms
[a02] Audio overlaps for 5ms at playtime 0:34:51. <WARNING> 140 ms
[a02] Audio overlaps for 5ms at playtime 0:36:06. <WARNING> 145 ms *
[a02] Audio overlaps for 5ms at playtime 0:37:21. <WARNING> 150 ms
[a02] Audio overlaps for 5ms at playtime 0:38:36. <WARNING> 155 ms
[a02] Audio overlaps for 5ms at playtime 0:39:51. <WARNING> 160 ms
[a02] Audio overlaps for 5ms at playtime 0:41:06. <WARNING> 165 ms
[a02] Audio overlaps for 5ms at playtime 0:42:21. <WARNING> 170 ms
[a02] Audio overlaps for 5ms at playtime 0:43:36. <WARNING> 175 ms
[a02] Audio overlaps for 5ms at playtime 0:44:51. <WARNING> 180 ms *
[a02] Audio overlaps for 5ms at playtime 0:46:06. <WARNING> 185 ms
[a02] Audio overlaps for 5ms at playtime 0:47:21. <WARNING> 190 ms
[a02] Audio overlaps for 5ms at playtime 0:48:36. <WARNING> 195 ms
[a02] Audio overlaps for 5ms at playtime 0:49:51. <WARNING> 200 ms
[a02] Audio overlaps for 5ms at playtime 0:51:06. <WARNING> 205 ms
[a02] Audio overlaps for 5ms at playtime 0:52:21. <WARNING> 210 ms *
[a02] Audio overlaps for 5ms at playtime 0:53:36. <WARNING> 215 ms
[a02] Starting 2nd pass...
[a02] Realizing (E-)AC3 gaps...
Thats ends with a AC3 with 7 frames less than original.
Delete 7 frames, at (*) points, of 32ms (215 / 32 = 6,71875 frames)
This behaviour is similar when play the mkv, 7 frames are skiped and not send to the decoder.
Many times work fine, but there are a problem:
The decoders need a initialization value, from previous frame, to decode properly a frame.
If frame 5 is skiped the frame 6 is decoded with a initialization from frame 4.
At high volume points that can produce cliks like here (http://forum.doom9.org/showthread.php?p=1587184#post1587184).
Like the first question in the post was "What's the best way...", despite forum rule 12, I can answer what is my best way for these little progressive delays:
- Avoid TimeStrech functions of AviSynth or Audio Editors, because aren't perfect and need a recode than always lose quality.
- Delete the needed frames, only a few, at silence or low noise points to avoid previous explained problem.
For instance you can use eac3to, first decode it to wav:
eac3to ORIGINAL.ac3 TEST.wav -no2ndpass -downStereo -down16
Now use a Audio Editor (like Audacity for instance) to locate silence or low noise points (with a regular distribution for progressive delay) along the TEST.wav.
And use eac3to with this syntax (in inverse time order):
eac3to ORIGINAL.ac3 out1.ac3 -edit=0:52:21.000,-32ms
eac3to out1.ac3 out2.ac3 -edit=0:44:51.000,-32ms
eac3to out2.ac3 out3.ac3 -edit=0:36:06.000,-32ms
eac3to out3.ac3 out4.ac3 -edit=0:28:37.000,-32ms
eac3to out4.ac3 out5.ac3 -edit=0:19:52.000,-32ms
eac3to out5.ac3 out6.ac3 -edit=0:12:22.000,-32ms
eac3to out6.ac3 FINAL.ac3 -edit=0:04:52.000,-32ms
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.