Results 1 to 1 of 1
When one views MKV files, sometimes the audio can be "out of sync" with the video. This post supplies easy to follow instructions on how to inspect the problem, and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-24-2012 #1Just Joined!
- Join Date
- Jan 2005
- Posts
- 54
How To Synchronize Audio in a Matroska (MKV) media file container
When one views MKV files, sometimes the audio can be "out of sync" with the video. This post supplies easy to follow instructions on how to inspect the problem, and repair your media file.
The following instructions use "variables" as we learn data for future reference in the format of MY_VARIABLE_NAME.
How to synchronize audio and video in a Matroska (MKV) media file container
Phase 0: Inspection:
Tools Required: mkvinfo, mkvmerge, vlc
1) Identify the file:
- What is the file we're having problems with?
EXAMPLE: MKV_FILE_NAME="MyVideo.mkv"
2) Identify the problem:
- Is the audio delayed, or ahead, and by how much time? (ms)
We can use vlc media player to dynamically figure it out:
VLC can increase or decrease the audio delay on the fly using keyboard shortcuts "j" and "k".
- "j" -> moves audio ahead (anti-delay)
- "k" -> moves audio behind (increase delay)
Play with this until you're satisfied, and note the value.
EXAMPLE: AUDIO_SHIFT=-300ms
i.e. The audio was 300ms behind.
3) Discover the Audio and Video Tracks:
- MKV is a container, it will have one or more audio/video tracks within it. To discover them, run:
Code:$ mkvmerge -i $MKV_FILE_NAME
Code:$ mkvmerge -i MyVideo.mkv File 'MyVideo.mkv': container: Matroska Track ID 1: video (V_MPEG4/ISO/AVC) Track ID 2: audio (A_AC3)
WARNING: Ensure that the audio/video tracks noted here matchthose from step (2) previous.
EXAMPLE: AUDIO_TRACK_ID=2
Phase 1: Adjust Audio Timecodes
Tools Required: mkvmerge
1) Perform the audio sync shift
Code:$ mkvmerge -o ${MKV_FILE_NAME}_FIXED.mkv -y $AUDIO_TRACK_ID:$AUDIO_SHIFT $MKV_FILE_NAMEPhase 2: Enjoy Synchronized Audio and VideoCode:$ mkvmerge -o MyVideo_FIXED.mkv -y 2:-300 MyVideo.mkv mkvmerge v4.5.0 ('Speed of Light') built on Feb 23 2011 00:12:51 'MyVideo.mkv': Using the Matroska demultiplexer. 'MyVideo.mkv' track 1: Using the MPEG-4 part 10 (AVC) video output module. 'MyVideo.mkv' track 2: Using the AC3 output module. The file 'MyVideo_FIXED.mkv' has been opened for writing. Progress: 100% The cue entries (the index) are being written... Muxing took 70 seconds.
1) Play the MyVideo_FIXED.mkv file in your media player of choice and enjoy the synchronized audio.Last edited by Fermulator; 04-24-2012 at 10:04 PM.


Reply With Quote
