Skip to content

Instantly share code, notes, and snippets.

@wiwaz
Last active January 3, 2023 13:58
Show Gist options
  • Save wiwaz/7fcf296154fed5ed68c578d56a0375ea to your computer and use it in GitHub Desktop.
Save wiwaz/7fcf296154fed5ed68c578d56a0375ea to your computer and use it in GitHub Desktop.
def fix_telecined_fades(clip: vs.VideoNode, color: float | list[float] = 0.0) -> vs.VideoNode:
if clip.format.color_family == vs.RGB:
raise ValueError("fix_telecined_fades: Input must be YUV or GRAY!")
if clip.format.sample_type != vs.FLOAT:
raise ValueError("fix_telecined_fades: Input must be FLOAT!")
if not isinstance(color, list):
color = [color] * clip.format.num_planes
expr = []
clip = clip.std.Limiter().std.SeparateFields().std.PlaneStats()
for i in range(clip.format.num_planes):
expr += f"x.PlaneStatsAverage {color[i]} - AVG! AVG@ 0 = x x {color[i]} - AVG@ y.PlaneStatsAverage {color[i]} - + 2 / AVG@ / * ? {color[i]} +",
fe, fo = clip[::2], clip[1::2]
ffix = (
core.akarin.Expr([fe, fo], expr),
core.akarin.Expr([fo, fe], expr),
)
return core.std.Interleave(ffix).std.DoubleWeave()[::2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment