Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th July 2022, 23:40   #1  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
MPEG2 Audio Sync + Field Order Transition

Trying to edit an MPEG2 file in Avisynth and I have two issues.

1. Field order keeps changing from TFF to BFF constantly.

2. Audio is out of sync after demuxing with both DGmpgdec and DGDecNV.

Since my audio keeps getting out of sync, I have tried repairing the MPEG2 file with TSDoctor, ffmpeg, AviDemux, ProjectX, and VideoReDo TS Suite with multiple passes and the file can't keep in sync.

I tried transcoding to MagicYUV in both VirtualDub and ffmpeg, it fixed the sync issues somewhat, but the wacky field order issues are still there.

I tried this command in ffmpeg:
Code:
ffmpeg -i "D:\megasync downloads\KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts" -c:v magicyuv -vf "fieldorder=tff" -c:a pcm_f32le -af aresample=async=1 -y "D:\megasync downloads\KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).avi"
It fixed the field order issues, however now the image gets shifted up constantly and I can't have that.

Is there a way to fix both issues?
ENunn is offline   Reply With Quote
Old 7th July 2022, 12:57   #2  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
Quote:
Originally Posted by ENunn View Post
Is there a way to fix both issues?
Yes, but we don't have a magic wand, so we need to see what's the problem here, so it would be better if you could share a sample so that we can take a look at it.

Anyway, as a rule of thumb try with:

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()
and check if you see fields by moving frame by frame on AVSPmod.
If you don't, then you're good to go as you can just easily re-encode it as progressive, otherwise, then it means you're dealing with interlaced stuff.

1) If you see 3 fields, 2 frames, 3 fields, 2 frames as a pattern (so if you move up 3 frames and it's interlaced, interlaced, interlaced and after that you see 2 identical repeated frames and the pattern goes on and on and on), then it means that you're dealing with a telecined file with 3:2 pulldown. In that case:

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()

tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3)) 
tdecimate()

2) If you don't see the pattern above, but you do see fields, then try with:

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()

AssumeTFF()
Bob()

and check what happens.

- IF it goes on step by step, it means it's Top Field First
- IF it goes on and then back and then on and then back and keeps jumping, then it means that it's actually BFF, so you try the following:

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()

AssumeBFF()
Bob()
and it shouldn't jump.

IF it moves on and on and on correctly, it doesn't jump back and it doesn't have any duplicated frames, then you're good to go, but use QTGMC() instead of Bob().
IF it moves on correctly BUT it does have duplicated frames, then you can use:

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()

AssumeBFF()
TDeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2)
or

Code:
#Indexing
video=LWLibavVideoSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
audio=LWLibavAudioSource("KMTR (NBC) - 2005 Sony HD 500 - September 4, 2005 (D-VHS)_1 (02).ts")
AudioDub(video, audio)
propclearall()

AssumeTFF()
TDeint(mode=2, order=-1, field=-1, mthreshL=6, mthreshC=6, map=0, type=2, debug=false, mtnmode=1, sharp=true, cthresh=6, blockx=16, blocky=16, chroma=true, MI=64, tryWeave=true, link=1, denoise=true, slow=2)



Anyway, we need a sample.

Last edited by FranceBB; 30th December 2023 at 17:28.
FranceBB is offline   Reply With Quote
Old 7th July 2022, 15:37   #3  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
Is this really just an MPEG file, or is it a VOB file from a DVD? If the source was a VOB, then the problems you are having are quite common and can be solved by using the right software to deal with the VOB (e.g., Womble, VideoRedo, etc.).
johnmeyer is offline   Reply With Quote
Old 7th July 2022, 17:55   #4  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Quote:
Originally Posted by FranceBB View Post
Anyway, as a rule of thumb try with:

Code:
#Indexing
video=LWLibavVideoSource("video.vob")
audio=LWLibavAudioSource("video.vob")
AudioDub(video, audio)
propclearall()
and check if you see fields by moving frame by frame on AVSPmod.
If you don't, then you're good to go as you can just easily re-encode it as progressive, otherwise, then it means you're dealing with interlaced stuff.
It's definitely interlaced.

Quote:
Originally Posted by FranceBB View Post
2) If you don't see the pattern above, but you do see fields, then try with:

Code:
#Indexing
video=LWLibavVideoSource("video.vob")
audio=LWLibavAudioSource("video.vob")
AudioDub(video, audio)
propclearall()

AssumeTFF()
Bob()

and check what happens.

- IF it goes on step by step, it means it's Top Field First
- IF it goes on and then back and then on and then back and keeps jumping, then it means that it's actually BFF, so you try the following:

Code:
#Indexing
video=LWLibavVideoSource("video.vob")
audio=LWLibavAudioSource("video.vob")
AudioDub(video, audio)
propclearall()

AssumeBFF()
Bob()
and it shouldn't jump.
Problem is is that it's mixed TFF and BFF. Some parts jump and others don't. Looks like loading it with LWLibAV fixed the field order issue. However, the audio file is still out of sync, even with av_sync=true.

Quote:
Originally Posted by FranceBB View Post
Yes, but we don't have a magic wand, so we need to see what's the problem here, so it would be better if you could share a sample so that we can take a look at it.
Here you go.

Quote:
Originally Posted by johnmeyer View Post
Is this really just an MPEG file, or is it a VOB file from a DVD? If the source was a VOB, then the problems you are having are quite common and can be solved by using the right software to deal with the VOB (e.g., Womble, VideoRedo, etc.).
It is an MPEG2 Transport Stream transferred off D-VHS. It had quite a few dropouts which probably explains why I'm having sync issues. I've already tried VideoRedo several times with several passes and the file is still out of sync in Avisynth.
ENunn is offline   Reply With Quote
Old 7th July 2022, 19:36   #5  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
I skimmed through the clip and didn't see major audio sync issues. The interviews toward the end are dead on. The sync in some of the commercials may be off a little, but by such a small amount that I'm guessing it may be related to the field reversal issue.

And yes, the field reversal issues are quite real, very annoying, and they keep going back and forth. I have never had dropouts or gaps on tapes cause fields to reverse and this makes me wonder about your capture setup. What capture device are you using? I couldn't get that information from Mediainfo. I use a Hauppauge capture device, so if it is one of theirs I might be able to provide a few pointers.
johnmeyer is offline   Reply With Quote
Old 7th July 2022, 21:47   #6  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Quote:
Originally Posted by johnmeyer View Post
I skimmed through the clip and didn't see major audio sync issues. The interviews toward the end are dead on. The sync in some of the commercials may be off a little, but by such a small amount that I'm guessing it may be related to the field reversal issue.
I'd send the full file, which would help y'all a lot, but it might be a dumb copyright nightmare even if it's not really enforced. It's not a Hollywood movie or anything but you never know NASCAR might have their ninjas outside my window ready to strike at any moment :P

Quote:
Originally Posted by johnmeyer View Post
And yes, the field reversal issues are quite real, very annoying, and they keep going back and forth. I have never had dropouts or gaps on tapes cause fields to reverse and this makes me wonder about your capture setup. What capture device are you using? I couldn't get that information from Mediainfo. I use a Hauppauge capture device, so if it is one of theirs I might be able to provide a few pointers.
No capture card, I transferred directly off the tape through firewire in VLC a long time ago. I always used firewire to transfer my D-VHS tapes unless they were copy protected.

Last edited by ENunn; 7th July 2022 at 21:56.
ENunn is offline   Reply With Quote
Old 8th July 2022, 01:10   #7  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
BTW, for others reading this who didn't download or analyze the clip, the program material is interlaced NTSC with 80% TFF and the remainder BFF. The commercials are included and they are all 23.976p, but telecined with 3:2 pulldown to 29.97. The field order also changes during the telecined material. IMHO, that will be really difficult to deal with -- not impossible, but I don't have anything in my bag of scripts to deal with it.

However, just for grins I used QTGMC to deinterlace it and, as FranceBB surmised, that takes care of the problem. I usually try to avoid deinterlacing when it is not needed but, in this case, it is not only needed, but it provides a stupidly simple fix to the problem.

To do a quick test with deinterlacing, I played the original clip through VLC with deinterlace set to YADIF and didn't see any visual problems (other than the lousy low-bitrate encoding macroblocks), and did not detect any significant audio sync issues (there might be a 1-2 frame sync offset in some of the commercials).
johnmeyer is offline   Reply With Quote
Old 10th July 2022, 11:50   #8  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
So the sample you uploaded isn't the original? Because it does have A/V sync issues but it seems to only be during the commercials near the end. The program itself seems okay and extracting the audio from the TS file and muxing it with an encoded version of the video doesn't change the A/V sync, so extracting the audio doesn't cause de-sync as such. If the original has perfect A/V sync try extracting the audio with eac3to. It'll try to fix any gaps etc as it extracts. It's the only extraction method I know of that does so. The sample ends in sync though, so I don't quite understand what's happening.

I ran FixD2V on the DGIndex index file (it's under the DGIndex GUI's Tools menu). It fiddled with the D2V file and created a log which I'm assuming shows it fixed three field transitions.

Code:
D2V Fix Output

Field order transition: 0 -> 2
900 6 0 93060000 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 f3 b0 a0
d00 6 0 93365876 0 0 0 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2
corrected...
900 6 0 93060000 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 f3 b0 a1
d00 6 0 93365876 0 0 0 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2

Field order transition: 2 -> 0
d00 6 0 95701964 0 0 0 92 a2
d00 6 0 95834880 0 0 0 90 b0 b0 a0 b0 b0 a0 b0 b0 a0 b0 b0 a0
corrected...
d00 6 0 95701964 0 0 0 92 a3
d00 6 0 95834880 0 0 0 90 b0 b0 a0 b0 b0 a0 b0 b0 a0 b0 b0 a0

Field order transition: 2 -> 0
900 6 0 100810488 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 a2
d00 6 0 101428632 0 0 0 d0 f1 f2 a2 b2 b2 e2 f2 f3 e0 f1 f2 e3
corrected...
900 6 0 100810488 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 a3
d00 6 0 101428632 0 0 0 d0 f1 f2 a2 b2 b2 e2 f2 f3 e0 f1 f2 e3
A quick check of an encoded version of the video looks okay, and it seems like the A/V sync is the same as it is for the TS file.
It's de interlaced to 59.94fps.

samplesjumpy.mkv

Code:
DGDecode_mpeg2source("E:\samplesjumpy.d2v")

Deint = QTGMC(preset="medium")

BWDIF(Field=-2, edeint=Deint)
hello_hello is offline   Reply With Quote
Old 22nd July 2022, 06:50   #9  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Quote:
Originally Posted by hello_hello View Post
So the sample you uploaded isn't the original? Because it does have A/V sync issues but it seems to only be during the commercials near the end. The program itself seems okay and extracting the audio from the TS file and muxing it with an encoded version of the video doesn't change the A/V sync, so extracting the audio doesn't cause de-sync as such. If the original has perfect A/V sync try extracting the audio with eac3to. It'll try to fix any gaps etc as it extracts. It's the only extraction method I know of that does so. The sample ends in sync though, so I don't quite understand what's happening.
The sample is from the full recording, but in terms of if it was from the original recording, I don't think so, I honestly forgot. I'd share the full recording but, again, potential copyright garbage.

Quote:
Originally Posted by hello_hello View Post
I ran FixD2V on the DGIndex index file (it's under the DGIndex GUI's Tools menu). It fiddled with the D2V file and created a log which I'm assuming shows it fixed three field transitions.

Code:
D2V Fix Output

Field order transition: 0 -> 2
900 6 0 93060000 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 f3 b0 a0
d00 6 0 93365876 0 0 0 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2
corrected...
900 6 0 93060000 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 f3 b0 a1
d00 6 0 93365876 0 0 0 92 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2 b2 b2 a2

Field order transition: 2 -> 0
d00 6 0 95701964 0 0 0 92 a2
d00 6 0 95834880 0 0 0 90 b0 b0 a0 b0 b0 a0 b0 b0 a0 b0 b0 a0
corrected...
d00 6 0 95701964 0 0 0 92 a3
d00 6 0 95834880 0 0 0 90 b0 b0 a0 b0 b0 a0 b0 b0 a0 b0 b0 a0

Field order transition: 2 -> 0
900 6 0 100810488 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 a2
d00 6 0 101428632 0 0 0 d0 f1 f2 a2 b2 b2 e2 f2 f3 e0 f1 f2 e3
corrected...
900 6 0 100810488 0 0 0 32 32 92 b2 b2 a2 b2 b2 a2 a3
d00 6 0 101428632 0 0 0 d0 f1 f2 a2 b2 b2 e2 f2 f3 e0 f1 f2 e3
A quick check of an encoded version of the video looks okay, and it seems like the A/V sync is the same as it is for the TS file.
It's de interlaced to 59.94fps.
I always use this for anything with a field order transition, and while it fixes that issue, it doesn't fix the audio sync issues.

Just incase the sample source wasn't the original recording I re-transferred the tape. Ran it through VideoReDo and DGIndex, and the field order garbage and audio sync issues are gone. Guess it was my old recording.
ENunn is offline   Reply With Quote
Old 30th December 2023, 04:53   #10  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Posting again after a while, I'm trying this again with some other D-VHS rips, but they have a lot of dropouts. So whenever I fix the file with BOTH ffmpeg and VideoReDo, then index with DGIndex, the resulting d2v and ac3 files are out of sync. If I load the .ts file with lwlibavvideosource, everything's in sync but there's a ton of field order changes, so when I deinterlace, it's jumpy. Does anyone know of any solutions to the problem? No sample for now, since the last time I sent one, there was no issues. Recapping the tape has the same problems.
ENunn is offline   Reply With Quote
Old 30th December 2023, 17:15   #11  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
PM sent
ENunn is offline   Reply With Quote
Old 30th December 2023, 20:22   #12  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
I got your PM. I uploaded two samples if you wanna check them out. They are the original recordings, so I haven't ran them through ffmpeg or VideoReDo.
ENunn is offline   Reply With Quote
Old 31st December 2023, 17:15   #13  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
I tried it on a file with less dropouts, and that one's STILL out of sync for some reason. I even tried an older version of DGIndex, and I still have sync issues. I tried DGIndexNV, and it's also out of sync plus it didn't fix the field order transitions.

Last edited by ENunn; 31st December 2023 at 17:19.
ENunn is offline   Reply With Quote
Old 6th February 2024, 20:14   #14  |  Link
ENunn
Registered User
 
Join Date: Dec 2019
Posts: 68
Sorry for the late reply, but thank you for trying! My capture setup is fine, I've transferred several tapes this way with no issues. It's just only on these problem tapes that I have issues when it comes to syncing in Avisynth.

I've tried some other options: I demuxed the video with both ProjectX and tsMuxeR and loaded them that way, and I tried to fix the ac3 file with DelayCut (to which it didn't actually do anything to fix the sync issues). Unfortunately it's still 30+ seconds out of sync. Still looking for solutions...
ENunn is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.