Log in

View Full Version : Perform a filter based on the frame number


Cary Knoop
24th July 2020, 00:16
I am working on a single clip where the frames from one camera need a plane shift, so for certain frame ranges, I want to perform a shift while for other ranges I want to do nothing.
How do I do this in Vapoursynth?

So assume for example we need to shift for frames between 0..2000, 3000..4000, and 6000..7000 while the other frames are correct already.

Wait, would something like this work:

part_1 = clip[0:2000].myshift()
part_2 = clip[2001:2999]
part_3 = clip[3000:4000].myshift()
part_4 = clip[4001:5999]
etc
...
clip = part_1 + part_2 + part_3 + part_4 + etc

Even if it works would it be the best approach performance wise?

_Al_
24th July 2020, 02:17
import functools

def func1(clip):
return clip.std.Expr(['x 50 -','','']) #darken

def func2(clip):
return clip.std.Expr(['x 50 +','','']) #brighten

TABLE = {
range(0,1000) : func1,
range(2000,2500) : func2,
range(3000,3500) : func1,
#etc
}

def distribute(n, clip):
for _range, func in TABLE.items():
if n in _range:
return func(clip)
return clip

fixed = core.std.FrameEval(clip, functools.partial(distribute, clip=clip))
fixed.set_output()
for range function that second number is excluded, range(0,200) would apply for 0 to 199 frame

Cary Knoop
24th July 2020, 02:26
import functools

def func1(clip):
return clip.std.Expr(['x 50 -','','']) #darken

def func2(clip):
return clip.std.Expr(['x 50 +','','']) #brighten

TABLE = {
range(0,1000) : func1,
range(2000,2500) : func2,
range(3000,3500) : func1,
#etc
}

def distribute(n, clip):
for _range, func in TABLE.items():
if n in _range:
return func(clip)
return clip

fixed = core.std.FrameEval(clip, functools.partial(distribute, clip=clip))
fixed.set_output()
Thanks, that looks great but how do I shift a Cb or Cr plane inside an expression?

lansing
24th July 2020, 02:31
https://github.com/Irrational-Encoding-Wizardry/Vapoursynth-RemapFrames

_Al_
24th July 2020, 02:31
that expression is just simple example, something to put in there, nothing that you would use in your function