View Single Post
Old 15th November 2012, 12:47   #2  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,915
Issues with gaps/overlaps

First explain the gaps/overlaps audio problems based in the different duration of video and audio frames.
Supose 2 m2ts with 25 fps video and one ac3 track (for easy numbers).
And want extract the full ac3 stream.

See the attached image with 3 options:

A) The second m2ts begin with a new audio. For instance a initial credit added before the main movie.
Now we can't recover the perfect sync without recode the audio.

B) The second m2ts begin with the next audio frame (maybe when the delay is low).
Now we preserve the sync only adding the second audio stream to the first.

C) The second m2ts begin with a duplicated frame of the ac3.
Now we need delete the duplicated frame before add the two streams.

Go with a real sample, extract the english ac3 track from Brave BD.
(I'm using the spanish angle but is the same for this track).
There are 9 .m2ts and I extract (eac3to) the ac3 for each file (t01.ac3 to t09.ac3).

I analyze video and audio durations and check if there are ac3 frames duplicated (numbers in ms.):
Code:
 Audio   Dur_Aud  Dur_Vid  Dif_A-V  Acu_Aud  Acu_Vid  Acu_A-V
------- -------- -------- -------- -------- -------- --------
t01.ac3    44608    44586       22    44608    44586       22
t02.ac3    28288    28278       10    72896    72864       32 Initial frame duplicated
t03.ac3   182496   182474       22   255392   255338       54
t04.ac3    58048    58016       32   313440   313355       85 Initial frame duplicated
t05.ac3  4888320  4888300       20  5201760  5201655      105 Initial frame duplicated
t06.ac3    46272    46255       17  5248032  5247909      123
t07.ac3   324288   324282        6  5572320  5572192      128 Initial frame duplicated
t08.ac3    34912    34910        2  5607232  5607102      130
t09.ac3    45152    45128       24  5652384  5652230      154
Then the full audio is 154 ms longer than video.

I delete the duplicated frames and repeat the check:
Code:
 Audio   Dur_Aud  Dur_Vid  Dif_A-V  Acu_Aud  Acu_Vid  Acu_A-V
------- -------- -------- -------- -------- -------- --------
t01.ac3    44608    44586       22    44608    44586       22
t02.ac3    28256    28278      -22    72864    72864        0
t03.ac3   182496   182474       22   255360   255338       22
t04.ac3    58016    58016        0   313376   313355       21
t05.ac3  4888288  4888300      -12  5201664  5201655        9
t06.ac3    46272    46255       17  5247936  5247909       27
t07.ac3   324256   324282      -26  5572192  5572192        0
t08.ac3    34912    34910        2  5607104  5607102        2
t09.ac3    45152    45128       24  5652256  5652230       26
Now the audio finish with only 26 ms. of difference.
And always the difference is less than 32 ms. (ac3 frame duration)
If we join the ac3 files we have a perfect stream in sync with the video.

If I use eac3to to extract the full stream from the .mpls I have the WARNINGS:
Code:
[a03] Audio overlaps for 22ms at playtime 0:00:45.  <WARNING>
[a03] Audio overlaps for 10ms at playtime 0:01:13.  <WARNING>
[a03] Audio overlaps for 22ms at playtime 0:04:15.  <WARNING>
[a03] Audio overlaps for 31ms at playtime 0:05:13.  <WARNING>
[a03] Audio overlaps for 20ms at playtime 1:26:42.  <WARNING>
[a03] Audio overlaps for 18ms at playtime 1:27:28.  <WARNING>
[a03] Audio overlaps for  6ms at playtime 1:32:52.  <WARNING>
And after realize the gaps/overlaps finish with a ac3 with the same length than first method.
But aren't identical.
Seems eac3to delete initial frame in t02.ac3 (correct) but also in t03.ac3 (incorrect).

Delete a correct frame, or preserve duplicated frames, most the times is unnoticeable, but sometimes can be detected like here.
Also for a perfect decode of the audio, a frame need a correct initialization from the previous frame and, if isn't the correct one can produce glitches, like was detected here.

For this BD you can obtain the correct english ac3 stream with a .bat file like this:
Code:
@echo off
"YourPathTo\eac3to.exe" 00952.m2ts 2: t01.ac3
"YourPathTo\eac3to.exe" 00960.m2ts 2: t02.ac3 -32ms
"YourPathTo\eac3to.exe" 00954.m2ts 2: t03.ac3
"YourPathTo\eac3to.exe" 00961.m2ts 2: t04.ac3 -32ms
"YourPathTo\eac3to.exe" 00956.m2ts 2: t05.ac3 -32ms
"YourPathTo\eac3to.exe" 01042.m2ts 2: t06.ac3
"YourPathTo\eac3to.exe" 00958.m2ts 2: t07.ac3 -32ms
"YourPathTo\eac3to.exe" 00968.m2ts 2: t08.ac3
"YourPathTo\eac3to.exe" 00959.m2ts 2: t09.ac3
copy /B t01.ac3 + t02.ac3 + t03.ac3 + t04.ac3 + t05.ac3 + t06.ac3 + t07.ac3 + t08.ac3 + t09.ac3 english.ac3
pause
I test the same procedure with DTS and DTS-HD and seems work fine.

BTW, not always delete the duplicated frames can be enough to mantain the sync, because can have type A join, then I suggest:
- First check if there are a duplicate frame and delete.
- If the accumulated delay is greater than the audio frame duration (not than half duration like seems work now eac3to) then delete a frame.
Attached Images
 
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 17th November 2012 at 12:44. Reason: Add info
tebasuna51 is online now   Reply With Quote