Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TFM - Can't override to use clip2 deinterlacer when PP is initially set to 0 #42

Open
jack4455667788 opened this issue Oct 18, 2023 · 3 comments

Comments

@jack4455667788
Copy link

jack4455667788 commented Oct 18, 2023

Bug Description :

If in the initial tfm call PP is set to 0 and clip2 is defined as an external deinterlacer source, changing the PP value to greater than 1 in the override file will not invoke the clip2 external deinterlacer as expected.

Notes :

I am not really sure if this is a bug, or a feature request, or if I am fundamentally just trying to use the wrong tool for the job. Thank you for this excellent tool in any case.

What I am trying to do is to just stitch/weave all frames together (ideally without any processing on frame match or comb detection) except for the specific frames i specify in the override file which need to be deinterlaced (using QTGMC, not the internal deinterlacer - and ideally only applying the deinterlacing to the detected comb "mask").

My video source is perfect 25p interlaced to 50i except for the credits which have no matching fields (and are followed by more 25p interlaced to 50i content).

This is what I am using to try an accomplish this. Should this work, or am I going about this the wrong way?

avs script :

mpeg2source("nirvana.d2v")
deint = QTGMC(Preset="Very Slow")
tfm(d2v="nirvana.d2v",mode=0,pp=0,slow=0,debug=True,ovr="override.txt",clip2=deint.SelectEven())

override.txt :

72325,73025 m 5
72325,73025 +
72325,73025 P 5

I have already worked around the issue by changing the initial PP value to 5 and explicitly setting every other frame than the range above as PP=0 and not combed in the override - but is that supposed to be required?

also, the notes for clip2 say

if PP >= 5 (i.e. using motion adaptation)
then TFM will build the mask as usual and only pixels in moving areas will be taken
from the frames in clip2.

Is this correct and am I using it properly above? Is the particular deinterlacing type specified by the PP value (5=blend,6=cubic,7=modified-ela) simply ignored when calling qtgmc - meaning that choosing 5,6, or 7 will produce the same output and only editing the qtgmc settings will change the deinterlace mode (this is what I assume is happening)?

also, can the slow value be changed in the override? I didn't see any mention of that in the documentation.

@pinterf
Copy link
Owner

pinterf commented Oct 19, 2023

I have to declare that I'm quite dumb in this area, and can only tell you what I see and debug at the code level. (I never used this plugin). I put here code line links, maybe it is helpful and a good starting place for someone smarter or for a future myself :)

The options o, m, f, P and i are read from the override file in each frame, this is sure.
https://github.com/pinterf/TIVTC/blob/master/src/TIVTC/TFM.cpp#L59

Then this overridden PP is checked with a combing variable being -1
https://github.com/pinterf/TIVTC/blob/master/src/TIVTC/TFM.cpp#L96
which is filled here
https://github.com/pinterf/TIVTC/blob/master/src/TIVTC/TFM.cpp#L92

And now it gets a little bit complicated here inside
https://github.com/pinterf/TIVTC/blob/master/src/TIVTC/TFM.cpp#L680
because I do not really understand what happens here.

@flossy83
Copy link
Contributor

flossy83 commented Apr 13, 2024

What I am trying to do is to just stitch/weave all frames together (ideally without any processing on frame match or comb detection) except for the specific frames i specify in the override file which need to be deinterlaced (using QTGMC, not the internal deinterlacer - and ideally only applying the deinterlacing to the detected comb "mask").

If you substitute a QTGMC deinterlaced pixel into TFM's mask it'll look weird cause QTGMC's pixels have different geometry due to them being always blended with surrounding pixels and you'll see edges of objects popping and getting fatter and thinner as those pixels are substituted. Also TFM's deint mask appears bugged as it often just substitutes all pixels for interpolated pixels for reasons I've yet to determine, so I'd avoid using it and use PP=3 instead so the whole frame gets substituted for the frames from your deint clip which uses its own accurate and reliable mask:

PropDelete("_FieldBased")   /* ensures downstream filters use Avisynth field order instead of source filter order */

deint = 
\ .BWDIF(field=-1, thr=2)	/* per pixel deinterlacing at half rate (25p) */
\ .QTGMC(InputType=1/2)		/* QTGMC antialiasing (not deinterlacing) /*

Here are some screenshots showing the differences between InputType=1/2
https://forum.doom9.org/showpost.php?p=1999882&postcount=1008

You needn't bother with the override file instead you can just make 2 TFM clips, one with PP=0 and the other with PP=3 and join the Trim()'d versions of the frame ranges you want to be processed with PP=3. Quick pseudocode example - completely untested but the underlying logic should be sound:

tfm0 = TFM(PP=0)
tfm3 = TFM(PP=3, clip2=deint)

section1 = tfm0.Trim(0,15000)  		# first 10 minutes
section2 = tfm3.Trim(15001, 18000)      # 10-12 minutes
section3 = tfm0.Trim(18001, 0)		# 12 minutes til end

section1 ++ section2 ++ section3

Alternatively you could do the selection logic inside a ScriptClip with "if current_frame >= n && current_frame <= p, return tfm0 else return tfm3".

@flossy83
Copy link
Contributor

flossy83 commented Apr 13, 2024

After reading your OP again it sounds like you want to deinterlace every frame in section2 in which case set section2 = deint instead.

Because TFM's PP>0 will only deinterlace a frame (i.e start using frames from clip2) if the frame was detected as combed, and its combing detection is not reliable on extended combed sequences (it's only good for detecting short clusters of combed frames here and there) . You can lower the combing detection thresh to something absurdly low like cthresh=6, MI=25 but I can't think of any advantage to doing that. If you know that section is interlaced you may as well just deinterlace it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants