Log in

View Full Version : Audio subtly lags behind video - how to fix?


Vilx-
21st April 2019, 02:01
I have an MKV file that has an issue with the audio - it subtly lags behind the video. They start in sync, and then over the course of the whole clip they drift out of sync.

My first idea was that the video framerate is specified wrong by 1, but a quick calculation shows that the effect would be MUCH more pronounced then. I'm at a loss how this could have happened, and better yet - how do I correct it now, since I don't have access to the original source from which it was encoded anymore? Here's the output from MediaInfo:


General
Unique ID : [Redacted]
Complete name : [Redacted]
Format : Matroska
Format version : Version 4
File size : 823 MiB
Duration : 22 min 17 s
Overall bit rate : 5 164 kb/s
Encoded date : UTC 2017-10-16 18:54:58
Writing application : mkvmerge v17.0.0 ('Be Ur Friend') 64-bit
Writing library : libebml v1.3.5 + libmatroska v1.4.8

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 2 Ref Frames
Format settings, CABAC : Yes
Format settings, RefFrames : 2 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 22 min 14 s
Bit rate : 4 920 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 24.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.099
Stream size : 772 MiB (94%)
Writing library : x264 core 115 r1995M 5a37283
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=2 / psy=1 / psy_rd=1.00:0.00
/ mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1
/ chroma_qp_offset=0 / threads=4 / sliced_threads=0 / nr=250 / decimate=1 / interlaced=0 / bluray_compat=0
/ constrained_intra=0 / bframes=0 / weightp=1 / keyint=250 / keyint_min=24 / scenecut=40 / intra_refresh=0
/ rc_lookahead=10 / rc=2pass / mbtree=1 / bitrate=4920 / ratetol=1.0 / qcomp=0.60 / qpmin=5 / qpmax=69
/ qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:1.00
Language : English
Default : Yes
Forced : No

Audio #1
ID : 2
Format : AC-3
Format/Info : Audio Coding 3
Commercial name : Dolby Digital
Codec ID : A_AC3
Duration : 22 min 17 s
Bit rate mode : Constant
Bit rate : 192 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 31.250 FPS (1536 SPF)
Bit depth : 16 bits
Compression mode : Lossy
Stream size : 30.6 MiB (4%)
Language : Russian
Service kind : Complete Main
Default : Yes
Forced : No

Audio #2
ID : 3
Format : AAC LC SBR
Format/Info : Advanced Audio Codec Low Complexity with Spectral Band Replication
Commercial name : HE-AAC
Format settings : Explicit
Codec ID : A_AAC-2
Duration : 22 min 16 s
Bit rate : 127 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 23.438 FPS (2048 SPF)
Compression mode : Lossy
Stream size : 20.2 MiB (2%)
Language : English
Default : No
Forced : No


As you can see, the video is 22:14 long, while the sound is 22:17 long. Thus over the course of 22 minutes the sound drifts 3 seconds out of sync. To correct that in the framerate, the video would need to be played at about 24.054fps, but that's not any standard framerate I know of.

manolito
22nd April 2019, 00:56
You should do a little experimenting with MKVMergeGUI...

Load your MKV, highlight the video stream in the lower left window and have a look at the "Time codes and default duration" section in the right pane. You can either stretch the video by a certain factor, or you can specify the default duration for the video. Optionally you can also adapt the duration in the bitstream to the value in the container. Play around with the options... :cool:

LoRd_MuldeR
22nd April 2019, 15:30
I have an MKV file that has an issue with the audio - it subtly lags behind the video. They start in sync, and then over the course of the whole clip they drift out of sync.

Please explain how exactly you created or obtained this file.

mkver
22nd April 2019, 18:15
As you can see, the video is 22:14 long, while the sound is 22:17 long. Thus over the course of 22 minutes the sound drifts 3 seconds out of sync. To correct that in the framerate, the video would need to be played at about 24.054fps, but that's not any standard framerate I know of.
That's not true. In order for the video to be stretched to 22:17, the video framerate needs to be decreased, not increased. So the first thing I'd do is testing whether the video should run at 24/1.001 fps.

And MediaInfo's output (which is only exact down to a second) is not good enough for what you are trying to achieve. MediaInfo can be made to be more precise or you can e.g. use mkvinfo (part of MKVToolNix).

gonca
22nd April 2019, 20:52
Video 22min 14sec
Audio 1 22min 17sec
Audio 2 22min 16sec

Adjust audio in mkvtoolnix gui (right side stretch by)

Audio 1 0.9978
Audio 2 0.9985
Or clip the audio accordingly

And don't forget to answer LoRd_MuldeR's question

manono
25th April 2019, 22:24
I'd first try slowing the video to 23.976fps, as the MediaInfo readout says it's 24fps. That was mkver's earlier suggestion.

gonca
25th April 2019, 22:58
I'd first try slowing the video to 23.976fps, as the MediaInfo readout says it's 24fps. That was mkver's earlier suggestion.

But there are two audio tracks with two different durations.
One speed/time adjustment can't correct both tracks.

Of course if the sync drift is different for the two tracks then 23.976 might work.
Either way, won't hurt to try either method