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. |
|
|
#1 | Link |
|
Registered User
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
|
Very Effective Field Matching script
Sorry, I disappeared, but soon I will again. However, today I was playing with avisynth and I found a nice way to make field matching thanks to the VMAF2 plugin. Basically you make a c/n/p match clips, then you deinterlace them with a simple vertical blur, then you make a comparison using the PSNR metric. The highest wins, of course. Works in 99.9% of the cases on my source. I don't have time to make a plugin so, if someone likes it, please do.
Code:
mpeg2Source("VTS_01_1.d2v")
global c = last
global n = DoubleWeave(c).SelectOdd()
global p = DoubleWeave(c).SelectOdd().DuplicateFrame(0)
global c = VMAF2(c,Blur(c,0,1),feature = 0)
global n = VMAF2(n,Blur(n,0,1),feature = 0)
global p = VMAF2(p,Blur(p,0,1),feature = 0)
c
ScriptClip("""
propGetFloat(n,"psnr_y") > propGetFloat(c,"psnr_y") ? n : \
propGetFloat(p,"psnr_y") > propGetFloat(c,"psnr_y") ? p : c
""")
|
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Jan 2018
Posts: 2,169
|
any chance in this situation for the first part??
https://forum.doom9.org/showthread.p...02#post1992102 Last edited by kedautinh12; 3rd October 2023 at 08:05. |
|
|
|
|
|
#5 | Link |
|
Registered User
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
|
I have no idea.
BTW, never used vapoursynth but I did a version for it too. Code:
import vapoursynth as vs
core = vs.core
c = core.d2v.Source("VTS_01_1.d2v")
n = core.std.SeparateFields(c)
n = core.std.DoubleWeave(n)
n = core.std.SelectEvery(n,2,1)
p = core.std.DuplicateFrames(n,0)
c = core.vmaf.Metric(c,core.std.BoxBlur(c,hradius=0),0)
n = core.vmaf.Metric(n,core.std.BoxBlur(n,hradius=0),0)
p = core.vmaf.Metric(p,core.std.BoxBlur(p,hradius=0),0)
def SelectFrame(n, f):
A = f[0].props["psnr_y"]
B = f[1].props["psnr_y"]
C = f[2].props["psnr_y"]
if B > A:
return f[1]
elif C > A:
return f[2]
else:
return f[0]
core.std.ModifyFrame(clip=c,clips=[c, n, p],selector=SelectFrame).set_output()
|
|
|
|
|
|
#7 | Link |
|
Registered User
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
|
With vinverse we are at the 100% of correct match on my source.
Code:
mpeg2Source("VTS_01_1.d2v")
global c = last
global n = DoubleWeave(c).SelectOdd()
global p = DoubleWeave(c).SelectOdd().DuplicateFrame(0)
global c = VMAF2(c,vinverse(c),feature = 0)
global n = VMAF2(n,vinverse(n),feature = 0)
global p = VMAF2(p,vinverse(p),feature = 0)
c
ScriptClip("""
propGetFloat(n,"psnr_y") > propGetFloat(c,"psnr_y") ? n : \
propGetFloat(p,"psnr_y") > propGetFloat(c,"psnr_y") ? p : c
""")
|
|
|
|
|
|
#9 | Link |
|
Registered User
Join Date: Feb 2016
Location: Nonsense land
Posts: 339
|
This should be more precise.
Code:
global c = last
global n = DoubleWeave(c).SelectOdd()
global p = DoubleWeave(c).SelectOdd().DuplicateFrame(0)
global c = VMAF2(c,vinverse(c),feature = 0)
global n = VMAF2(n,vinverse(n),feature = 0)
global p = VMAF2(p,vinverse(p),feature = 0)
c
ScriptClip("""
n_metric = propGetFloat(n,"psnr_y") + propGetFloat(n,"psnr_cb") + propGetFloat(n,"psnr_cr")
c_metric = propGetFloat(c,"psnr_y") + propGetFloat(c,"psnr_cb") + propGetFloat(c,"psnr_cr")
p_metric = propGetFloat(p,"psnr_y") + propGetFloat(p,"psnr_cb") + propGetFloat(p,"psnr_cr")
n_metric > c_metric && n_metric > p_metric ? n : \
p_metric > c_metric && p_metric > n_metric ? p : c
""")
|
|
|
|
|
|
#10 | Link |
|
Registered User
Join Date: Oct 2001
Location: Germany
Posts: 7,659
|
Can't get the Vapoursynth version working.
I used the code from post #5, packed it into a function and adjusted SelectFrame, where: Code:
if B > A:
return f[1]
elif C > A:
return f[2]
else:
return f[0]
Code:
if B > A:
if B > C:
return f[1]
return f[2]
elif C > A:
return f[2]
else:
return f[0]
Code:
# FieldMatching from https://forum.doom9.org/showthread.php?t=185104 by Ceppo
# requires:
# havsfunc https://github.com/Selur/VapoursynthScriptsInHybrid/blob/master/havsfunc.py when Vinverse is enabled (!not working atm!)
# VMAF: https://github.com/HomeOfVapourSynthEvolution/VapourSynth-VMAF
def cFieldMatch(clip: vs.VideoNode, chroma: bool=False, vinverse: bool=False):
# prepare
n = clip
n = core.std.SeparateFields(clip=n) # separate frames
n = core.std.DoubleWeave(clip=n) # double weave
n = core.std.SelectEvery(clip=n, cycle=2, offsets=1) # select odd
p = core.std.DuplicateFrames(clip=n, frames=[0]) # duplicate first frame
# calculate PSNR
if vinverse:
import havsfunc
c = core.vmaf.Metric(reference=clip, distorted=havsfunc.Vinverse(clip), feature=[0])
n = core.vmaf.Metric(reference=n, distorted=havsfunc.Vinverse(n), feature=[0])
p = core.vmaf.Metric(reference=p, distorted=havsfunc.Vinverse(c), feature=[0])
else:
c = core.vmaf.Metric(reference=clip, distorted=core.std.BoxBlur(clip,hradius=0), feature=[0])
n = core.vmaf.Metric(reference=n, distorted=core.std.BoxBlur(n,hradius=0), feature=[0])
p = core.vmaf.Metric(reference=p, distorted=core.std.BoxBlur(p,hradius=0), feature=[0])
def SelectFrameChroma(n, f):
A = f[0].props["psnr_y"] + f[0].props["psnr_cb"] + f[0].props["psnr_cr"] # c
B = f[1].props["psnr_y"] + f[1].props["psnr_cb"] + f[1].props["psnr_cr"] # n
C = f[2].props["psnr_y"] + f[2].props["psnr_cb"] + f[2].props["psnr_cr"] # p
# return max
if B > A:
if B > C:
return f[1]
return f[2]
elif C > A:
return f[2]
else:
return f[0]
def SelectFrame(n, f):
A = f[0].props["psnr_y"] # c
B = f[1].props["psnr_y"] # n
C = f[2].props["psnr_y"] # p
# return max
if B > A:
if B > C:
return f[1]
return f[2]
elif C > A:
return f[2]
else:
return f[0]
# select
if chroma:
return core.std.ModifyFrame(clip=c, clips=[c, n, p], selector=SelectFrameChroma)
return core.std.ModifyFrame(clip=c, clips=[c, n, p], selector=SelectFrame)
Does anyone have an idea why it does not work? Cu Selur |
|
|
|
|
|
#13 | Link |
|
Registered User
Join Date: Jan 2018
Posts: 2,169
|
Did you try with IT, Ceppo??
https://github.com/Asd-g/AviSynthPlu...ent-1771105416 |
|
|
|
|
|
#14 | Link |
|
Registered User
Join Date: Jan 2018
Posts: 2,169
|
Asd-g ask you license to update Ctools, Ceppo
https://github.com/Asd-g/AviSynthPlu...ent-1923731799 |
|
|
|
|
|
#15 | Link | |
|
Registered User
Join Date: May 2018
Posts: 215
|
Quote:
Code:
-vf "dejudder, fps=30000/1001, fieldmatch=mode=pcn_ub:combmatch=full, yadif=deint=interlaced, decimate" Last edited by takla; 20th February 2024 at 22:36. |
|
|
|
|
![]() |
|
|