1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MKV Muxing Audio Out-of-Sync with Video

Discussion in 'Other video questions' started by Cube11, Jun 26, 2008.

  1. Cube11

    Cube11 Member

    May 6, 2004
    Likes Received:
    Trophy Points:
    Hey, so here is a breakdown of the issue I'm trying to resolve:

    File #1: I have a Matroska (MKV) file, in which the video stream was encoded with H264. The frame-rate is most likely 23.976 fps (more on that in a little bit).

    File #2: I have a separate MKV file that was also encoded with H264 and by all indications, has the SAME frame-rate as File #1 (i.e. probably 23.976 fps). The following is important: File #2 is the exact SAME video content as File #1. Emphasizing the word "content," since the technical properties of File #2 are different than File #1, despite the identical video "content." The audio stream I'm interested in from File #2 was encoded with AAC 48000Hz stereo, just like the audio stream from File #1. But, the actual "content" of the audio is DIFFERENT between File #1 and File #2.

    Now, despite the fact that File #1 and File #2 consist of the same video "content," the length of Files #1 and #2 is different. How different depends on what program you use to look up that information. Here are screenshots of file information comparing File #1 and File #2 using the programs Windows Media Player Classic, VirtualDub, and ConvertXtoDVD, respectively.


    According to Windows Media Player Classic:
    File #1: Length: 23 min, 27 sec | Video: 23.98 fps
    File #2: Length: 23 min, 25 sec | Video: 23.98 fps
    Difference in length = 2 sec


    According to VirtualDub:
    File #1: Video Length: 23 min, 27.07 sec | Video: 23.976 fps | Audio Length: 23 min, 27.03 sec
    File #2: Video Length: 23 min, 25.94 sec | Video: 23.976 fps | Audio Length: 23 min, 25.90 sec
    Difference in video length = 1.13 sec | Difference in audio length = 1.13 sec


    According to ConvertXtoDVD:
    File #1: Length: 23 min, 28.042 sec | Video: 24.39 fps
    File #2: Length: 23 min, 25.920 sec | Video: 24.39 fps
    Difference in length = 2.122 sec

    Now, based on the file info obtained from Media Player Classic, VirtualDub, and ConvertXtoDVD, I conclude that the frame-rate is probably the same for both files (whether it's 23.976 fps or something else). The exact difference in length, however, is uncertain. What I can conclude is that the length of File #2 is SHORTER than the length of File #1.

    OKAY, now that the background info has been established: What I want to do is take one audio stream from MKV File #2, and mux it with the video from MKV File #1. Using a program called "mkvmerge GUI," I was able to do this. But, the audio is out-of-sync (perhaps progressively) with the video.


    Now, the audio seems to start off fine at the very beginning, so I don't think it's an audio delay issue. Therefore, I tried the "Stretch by" option using file length info from ConvertXtoDVD:

    File #1: 23 minutes, 28.042 seconds = 1408.042 seconds
    File #2: 23 minutes, 25.920 seconds = 1405.920 seconds

    But, entering in the fraction 1405.920/1408.042 or the reciprocal into the "Stretch by" line doesn't fix the audio/video sync problem. It does slightly speed up or slow down the audio and/or video overall, but it's still terrifically out-of-sync.

    Million-dollar question: Based on the info presented thus far, can you tell me what I'm doing wrong? Or in other words, what should I do to achieve my goal of muxing one audio stream from File #2 with the video stream from File #1, and having it be in sync?

    Finally, is there any way to natively "correct" the audio stream to sync up with the video? In other words, to make it so that if I mux the audio with the video, and then de-mux, and re-mux without "stretching it" using mkvmerge, it will still be in sync? Any input on my questions would be greatly appreciated. Thanks!
  2. attar

    attar Senior member

    Jun 17, 2005
    Likes Received:
    Trophy Points:
    Joining/saving the video and audio (without setting adjustments) in mkvmerge and playing it back in Media Player Classic or VLC, you can gauge the delay by either pressing the + or - keys on the keypad (in MPC) or Ctrl l or Ctrl k (VLC).
    If you can get a setting that synchronizes the A/V, then note it and use that factor in the 'Delay' setting of mkvmerge - see if it works.

Share This Page