View Single Post
Old 13th September 2015, 22:59   #2  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 321
I guess it can be greatly improved, because it is a pretty straight conversion without much thinking. And not really tested, I leave that to you. :P

Code:
import vapoursynth as vs


def prefilter(clip, thr=2, chromamotion=True):
    core = vs.get_core()
    return flux5framest(clip, thr=thr, chromamotion=chromamotion)


def flux5framest(clip, thr=2, thrc=None, chromamotion=True):
    core = vs.get_core()

    if chromamotion is True:
        thrc = thr if thrc is None else thrc
    else:
        thrc = 0

    if chromamotion is True:
        y = core.std.ShufflePlanes(clip, planes=0, colorfamily=vs.GRAY)
        u = core.std.ShufflePlanes(clip, planes=1, colorfamily=vs.GRAY)
        v = core.std.ShufflePlanes(clip, planes=2, colorfamily=vs.GRAY)
        med = core.std.ShufflePlanes([median5t(y), median5t(u), median5t(v)], planes=[0, 0, 0], colorfamily=vs.YUV)
    else:
        y = core.std.ShufflePlanes(clip, planes=0, colorfamily=vs.GRAY)
        med = core.std.ShufflePlanes([median5t(y), clip, clip], planes=[0, 1, 2], colorfamily=vs.YUV)

    avg = core.focus.TemporalSoften(clip, radius=2, luma_threshold=thr, chroma_threshold=thrc, scenechange=24, mode=2)
    res = core.std.Interleave([clip, med, avg]).rgvs.Clense(planes=[0, 1, 2] if chromamotion is True else 0).std.SelectEvery(cycle=3, offsets=1)

    return res

def median5t(clip):
    core = vs.get_core()

    def logic_max(c1, c2):
        return core.std.Expr([c1, c2], expr=['x y max'])

    def logic_min(c1, c2):
        return core.std.Expr([c1, c2], expr=['x y min'])

    last = core.std.DuplicateFrames(clip, frames=[clip.num_frames-1] * 5)
    bcmin = logic_min(core.std.DuplicateFrames(last, frames=[0]).std.SelectEvery(cycle=2, offsets=1), core.std.SelectEvery(last, cycle=2, offsets=0))
    bcmax = logic_max(core.std.DuplicateFrames(last, frames=[0]).std.SelectEvery(cycle=2, offsets=1), core.std.SelectEvery(last, cycle=2, offsets=0))
    demin = core.std.DeleteFrames(bcmin, frames=0)
    demax = core.std.DeleteFrames(bcmax, frames=0)
    x = logic_max(bcmin, demin)
    y = logic_min(bcmax, demax)
    a = core.std.DuplicateFrames(last, frames=[0]).std.SelectEvery(cycle=2, offsets=0)
    f = core.std.DeleteFrames(last, frames=0).std.SelectEvery(cycle=2, offsets=1)
    last = core.std.Interleave([a, x, y, f]).rgvs.Clense(planes=0).std.SelectEvery(cycle=4, offsets=[1, 2])
    return core.std.Trim(last, length=clip.num_frames)

Last edited by Are_; 14th September 2015 at 13:51. Reason: Fixed some stupid mistake
Are_ is offline   Reply With Quote