PDA

View Full Version : Hacking the audio delay.


mattstan
19th September 2007, 17:05
Hi,

I'm trying to hack getting the audio delay from a corrupt DVD. The corrupted DVD plays its audio in sync, so the info must be somewhere in the VOB files.

When I de-muxed the m2v and ac3 files from the corrupted DVD and then re-authored a new DVD, I'm left with the audio arriving too early by just under a second (this is consistent all the way through the movie and BTW the video and audio lengths are almost the same, the audio is 23ms shorter but this is not long enough to account for the sync problem and just means the audio finishes 23ms before the video).

DGIndex and VobEdit both however inform me the audio delay is 0.

With a web search I found a post in this forum from 2002 by tateu, URL below, in which he describes his method for calculating the audio delay. Here's what he suggests:

"A VOB is a type of mpeg-2 file so I just read the PTS (Presentation Time Stamp) values of the first Pack containing Audio Data and the first Video Pack with a frame of video that has Temporal Reference = 0. This works on VOBs with mpeg audio and AC3 audio..."

http://forum.doom9.org/showthread.php?t=30895

With my VOB set:

1st video pack with temporal ref = 0 (which is the 1st video pack):
PTS = 00025854

1st audio pack
PTS = 00025854

The same value, so no audio delay !!

The VOB files each play with the audio in sync, but when de-muxed and re-authored the audio sync delay occurs every time, and I've tried several different de-muxing and re-authoring tools.

Where else might the audio delay be specified in the VOBs? I'm fine with cracking out my VOB C++ libraries if necessary, but would prefer a solution using VOBEdit (or such like).

Many thanks to you gurus, hopefully I'll be bowing to your superior knowledge (this is not my day-job). Regards, etc..

neuron2
19th September 2007, 17:49
The audio and video streams each carry timestamps to say when they should be presented, so a proper player can always play them in sync. It is only when you demux to elementary streams that you lose the timestamps. If the demuxing doesn't start at the same place for the video and audio streams, as may happen due to granularity of audio/video frames, MPEG frame re-ordering, etc., then an offset ("audio delay") may exist between the elementary audio and video streams. So everything depends on how you demuxed the streams.

Can you post a link to a fragment containing the start of the VOB? Preferably, it should be long enough to include an audio/video event that will allow the "real" sync to be assessed.

mattstan
19th September 2007, 19:22
The audio and video streams each carry timestamps to say when they should be presented, so a proper player can always play them in sync. It is only when you demux to elementary streams that you lose the timestamps. If the demuxing doesn't start at the same place for the video and audio streams, as may happen due to granularity of audio/video frames, MPEG frame re-ordering, etc., then an offset ("audio delay") may exist between the elementary audio and video streams. So everything depends on how you demuxed the streams.

Can you post a link to a fragment containing the start of the VOB? Preferably, it should be long enough to include an audio/video event that will allow the "real" sync to be assessed.
Many thanks for your informative reply. To demux, I first used VobEdit, and later used DGIndex (aka dgmpgdec), both resulted in my getting the usual m2v, ac3, and (in this case) 4 subtitle sup files. I tried re-authoring with IFOEdit, MuxMan, and DVD Author - in all cases I got a DVD with the audio out of sync. Might there be another de-muxer that I should try?

I am unsure which VOB you want me to upload a segment of. Is it the original (that's what I'd guess) which is in sync, or the re-authored which is out of sync?

Many thanks, and regards, etc..

neuron2
19th September 2007, 20:06
I am unsure which VOB you want me to upload a segment of. Is it the original (that's what I'd guess) which is in sync, or the re-authored which is out of sync?The original one, because I want to see if there is anything in there to account for the sync problem. Don't cut anything from the start of the VOB.

mattstan
19th September 2007, 20:14
The original one, because I want to see if there is anything in there to account for the sync problem. Don't cut anything from the start of the VOB.
That's what I thought and no I did not cut anything from the start. The clip is the first 3 mins of the 1st VOB and is being uploaded at the moment. It should be finished uploading to a web share site called MegaUpLoad in about 30 mins, assuming MegaUpLoad does not muck the upload up, in which case I'll upload to another file sharing site.

Thanks again.

mattstan
19th September 2007, 20:59
The file has finished uploading to MegaUpLoad, link below. When you reach the page, you need to enter a 3 letter code, and when that's done a new page will load with a button saying 'Please wait 45 seconds', the 45 will count down to 0, at which point you can click the button, which will now say 'download' - don't click on 'Premium Download', that's just for paying customers.

http://www.megaupload.com/?d=9WTOX58O

The file is 113 MB, and is the first 3 mins of the movie from the first VOB file of the original DVD's movie title set (so it was from VTS_11_1.VOB), the audio is in sync, and it's right from the start of the movie, that's why I needed to upload 113 MB, because it's not till the last 25 seconds that you get any dialog and so can see the audio is in sync.

The file is called: Original_DVD_(So_Audio_In_Sync)_First_VOB_First_3_Mins.MPG

Many, many, thanks for your help.

Regards, etc..

mattstan

neuron2
19th September 2007, 21:11
OK. I can't look at it until this evening, though.

mattstan
19th September 2007, 22:14
Whenever you have time would be great. It's very kind of you even to take a look. Many thanks again.

neuron2
20th September 2007, 01:50
It's the well-known "leading black GOPs with no audio" problem.

Load the VOB into DGIndex. Then hit the > key three times. Then hit the [ key. Then save the project. You'll get a delay of -128ms. Use this script and everything plays in sync.

vid=MPEG2Source("Original.d2v")
aud=nicac3source("Original T01 2_0ch 192Kbps DELAY -128ms.ac3").delayaudio(-0.128)
audiodub(vid,aud)

You can save your project with the Log Timestamps option enabled. Then if you inspect the log, you can see that the SCR resets to 0 after a few GOPS.

mattstan
20th September 2007, 16:27
It's the well-known "leading black GOPs with no audio" problem.

Load the VOB into DGIndex. Then hit the > key three times. Then hit the [ key. Then save the project. You'll get a delay of -128ms. Use this script and everything plays in sync.

vid=MPEG2Source("Original.d2v")
aud=nicac3source("Original T01 2_0ch 192Kbps DELAY -128ms.ac3").delayaudio(-0.128)
audiodub(vid,aud)

You can save your project with the Log Timestamps option enabled. Then if you inspect the log, you can see that the SCR resets to 0 after a few GOPS.
Many thanks neuron2, you got that exactly right!! Sorry to take a while to reply, I think your evening is my middle-of-the-night, and I've been out on a job most of today. Hopefully the timing will be just right for you getting this post during your morning. :D

So the fix for this kind of audio problem is to skip a few I frames and mark that point as the new start point. Easy enough once you know how.

Thanks so much for taking the time to help me, I really appreciate it, and it was very kind of you.

Regards, etc..,

mattstan

mattstan
20th September 2007, 17:39
I only just realized neuron2 that you are the author of DGMPGDec - thanks for the great tool and for all your help.

I wrote the following to post in the other forums I posted in for help on this issue. For the sake of completeness and for others searching the forum for this kind of problem, here's the solution in detail explaining to the less experienced exactly how to do the fix.


My audio out of sync problem turned out to be a well known 'leading black GOPs with no audio' problem. That is to say, some frames at the start of the DVD vob title set have no audio in them, but when de-muxed the audio starts at the same time as the video (including the no-audio video frames), meaning your audio starts fractionally too early, knocking it out of sync with the video.

To fix:

NOTE: If your audio is arriving too late and not too early then this fix is not for you, as you do not have the 'leading black GOPs with no audio' problem.

Get a copy of the software DGMPGDec aka DGIndex, here's the URL:
http://neuron2.net/dgmpgdec/dgmpgdec.html

You need to use DGIndex to de-mux the DVD's streams.

Load DGIndex, and use File-->Open to load the first vob file in the movie title's vob set (in my case the movie title's set starts with VTS_11_1.vob). This brings up a 'File list' dialog, use 'Add' to add all the rest of the vob files from the set, EG. VTS_11_2.vob, VTS_11_3.vob, VTS_11_4.vob, VTS_11_5.vob. Obviously they must be in the correct order. Click 'OK'.

Them use the '>' button to skip a few I frames (each press skips not a single frame but on to the next I frame), I needed to press '>' 3 times. HINT: Skip until you see the first video frame displayed and then go back once using '<', but if this (later) does not give you an audio delay number then skip to the 1st video frame and don't go back 1. Then click on the '[' button to mark this I frame as the new start point, in so doing you're skipping the frames that have no audio.

Now just select File-->Save Project And De-Mux Video. This will de-mux your vob file set's streams. The audio stream's file name will contain the out of sync value in ms - if this says 0, cancel and try moving on an I frame or more, as suggested in the previous paragraph, don't forget to use '[' again to mark the new I frame as the new starting point.

Once de-muxing has finished, you can use IFOEdit (or whatever re-mux software you want) to re-author the DVD, using the value given in the audio file name to get your audio back in sync (don't forget the minus sign or you'll be making it exactly twice as badly out of sync!!).

OR... if you are using Avisynth, use a script SOMETHING like this:

LoadPlugin("path...\DGDecode.dll")
video=MPEG2Source("path...\filename.d2v")
audio=nicac3source("path...\filename.ac3").delayaudio(-0.128)
AudioDub(video,audio)

Replacing the delayaudio value of -0.128 with your out of sync value, converted to a fraction of 1000 (1000 ms = 1 sec), EG. -128 becomes -0.128, -64 becomes -0.064. If you're not sure about this simply divide your value by 1000, EG. 64 / 1000 = 0.064.

Hope this helps.