Log in

View Full Version : A/V out of sync in VFR encode!!


ben13
5th August 2011, 06:31
I was trying to encode a .ts recorded for my own veiwing purpose, I'm tring to make it vfr!
The video seems to be alrite, but the audio has some major delays...
kinda like 10s-15s!
Avs i used:

DGDecode_mpeg2source("test.d2v")
assumeTFF()

#PASS 1
#-------------------------------------------
tfm(d2v="test.d2v", output="matches.txt")
tdecimate(mode=4, output="metrics.txt")

#PASS 2
#-------------------------------------------
tfm(d2v="test.d2v", input="matches.txt")
tdecimate(mode=5, hybrid=2, vfrDec=1, input="metrics.txt", tfmIn="matches.txt", mkvOut="mkv-timecodesfile.txt")

#TRIM
#------------------------------------------------------
trim(2487,6611)++trim(8639,26687)++trim(32933,48150)


#resize & denoising
#-------------------
Spline64Resize(1280,720)

#Filtering
------------------------
Filters...



Encoded vfr Video Media info:
Encoded file media info
Codec ID/Info : Advanced Video Coding
Duration : 23mn 6s
Bit rate mode : Variable
Bit rate : 1 900 Kbps
Maximum bit rate : 50.0 Mbps
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Frame rate : 26.969 fps
Minimum frame rate : 17.982 fps
Maximum frame rate : 29.970 fps


Now the problem is...

#PASS 2
#-------------------------------------------
tfm(d2v="test.d2v", input="matches.txt")
tdecimate(mode=5, hybrid=2, vfrDec=1, input="metrics.txt", tfmIn="matches.txt", mkvOut="mkv-timecodesfile.txt")

#TRIM
#------------------------------------------------------
trim(2487,6611)++trim(8639,26687)++trim(32933,48150) <----- trimmed by avisynth assuming framerate at 26.96fps


But audio is still at 29.97 fps..

I tried making the audio at 26.96 using behappy n then tried trimming/cutting it, but no use.

Audio Clt file info

<?xml version="1.0"?>
<Cuts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Framerate>26.969681769860408</Framerate>
<Style>NO_TRANSITION</Style>
<AllCuts>
<CutSection>
<startFrame>2487</startFrame>
<endFrame>6611</endFrame>
</CutSection>
<CutSection>
<startFrame>8639</startFrame>
<endFrame>26687</endFrame>
</CutSection>
<CutSection>
<startFrame>32933</startFrame>
<endFrame>48150</endFrame>
</CutSection>
</AllCuts>
</Cuts>


So someone can assist me on this?
Thanks you very much!

Ghitulescu
5th August 2011, 09:13
A/V synch for VFR encodes are rather the exception than the rule, irrespective of the codec. All legal sources are CFR, why encode in VFR?

TheFluff
5th August 2011, 12:12
A/V synch for VFR encodes are rather the exception than the rule, irrespective of the codec.
What? If you're doing it right it'll always be in sync. In fact if you have the correct workflow it's HARD to get it to go out of sync.

All legal sources are CFR, why encode in VFR?
I take it you've never heard of hybrid content. Or the WMV format. Or...


@ben13: I suggest you cut the audio before encoding the video (or doing anything at all to it, really). Remember that the audio does not have a framerate and that you're not changing the length of the video.

cretindesalpes
5th August 2011, 16:22
Trim before TDecimate, otherwise the generated timecodes won't match the final video stream, and all will go out of sync.

You have also a typo:
trim(2487,6611)
...
<startFrame>2287</startFrame>
<endFrame>6611</endFrame>

ben13
5th August 2011, 19:45
@ben13: I suggest you cut the audio before encoding the video (or doing anything at all to it, really).

Emmm..? Please elaborate!


audio does not have a framerate

Sometimes, I see options like speedup- 23.97 t0 25fps or vice versa in audio encoders... what are they???

ben13
5th August 2011, 20:06
You have also a typo:
trim(2487,6611)
...
<startFrame>2287</startFrame>
<endFrame>6611</endFrame>

Sorry about that typo!
It was when I was experimenting on it, original one was 2487(correct one, but no use)


Trim before TDecimate, otherwise the generated timecodes won't match the final video stream, and all will go out of sync.

You mean this ?



#TRIM
#------------------------------------------------------
trim(2487,6611)++trim(8639,26687)++trim(32933,48150)

#PASS 2
#-------------------------------------------
tfm(d2v="test.d2v", input="matches.txt")
tdecimate(mode=5, hybrid=2, vfrDec=1, input="metrics.txt", tfmIn="matches.txt", mkvOut="mkv-timecodesfile.txt")


TFM dies an error saying
"test.d2v frame count does match the filter frame count":mad:

TheFluff
6th August 2011, 03:26
Sometimes, I see options like speedup- 23.97 t0 25fps or vice versa in audio encoders... what are they???

That's for film -> PAL speedup (or the reverse); a very different thing.

When doing VFR encodes you should under no circumstances change the length or the playback speed of the audio (just like you wouldn't do it when doing a normal CFR encode). If the audio requires cutting (such as in your case when you're working on a TS with what I assume to be commercial breaks) you should do the audio cutting first, before doing any video manipulation of any kind.

If you prefer cutting the audio in Avisynth, you should put your trim() statements first, right after the source filter. If you absolutely need to use the d2v parameter to TFM, you can cut right after that filter (but before decimation), but if your source is a broadcast TS the d2v parameter is most likely not going to be useful at all, so you can just remove it (broadcasters rarely if ever use soft telecining).

ben13
8th August 2011, 18:54
DGDecode_mpeg2source("test.d2v")
assumeTFF()

#TRIM
#------------------------------------------------------
trim(2487,6611)++trim(8639,26687)++trim(32933,48150)

#PASS 1
#-------------------------------------------
tfm(mode=1, output="matches.txt")
tdecimate(mode=4, output="metrics.txt")

#PASS 2
#-------------------------------------------
tfm(mode=1, input="matches.txt")
tdecimate(mode=5, hybrid=2, vfrDec=1, input="metrics.txt", tfmIn="matches.txt", mkvOut="mkv-timecodesfile.txt")

#resize & denoising
#-------------------
Spline64Resize(1280,720)

#Filtering
------------------------
Filters...

This new code does the job!

Thank you everyone!:)