Since your post is in the section which is specifically not about Hybrid.
Here also an example on how to do what you described:
import functools
# Define a function that will apply the filter only if the change in the frame meets a specified comparison condition.
def filterOnlyIf(clip, filtered, thres: float=0.5, compare_method: str="<", debug: bool=False):
def filterOnly(n, f, clip):
# Extract the PlaneStatsDiff property for the current frame.
diff = f.props['PlaneStatsDiff']
# Define comparison logic based on 'compare_method'
if compare_method == "<":
condition = diff < thres
elif compare_method == "<=":
condition = diff <= thres
elif compare_method == "=":
condition = diff == thres
elif compare_method == ">":
condition = diff > thres
elif compare_method == ">=":
condition = diff >= thres
else:
raise ValueError(f"Invalid comparison method: {compare_method}")
# Apply filter or return the original clip based on the comparison result
if condition:
# If the condition is met, apply the filter (Levels in this case).
ret = filtered
if debug:
ret = ret.text.Text(f"filtered, thresh: {diff}")
else:
# If the condition is not met, skip applying the filter and return the original clip.
ret = clip
if debug:
ret = ret.text.Text(f"skip, thresh: {diff}")
return ret
# Apply the 'filterOnly' function frame-by-frame using FrameEval.
clip = core.std.FrameEval(clip=clip, eval=functools.partial(filterOnly, clip=clip), prop_src=differences)
return clip
# Example usage with '>' as comparison method and core.std.Levels as filter:
# Generate PlaneStats for the difference between frames
differences = core.std.PlaneStats(clipa=clip, clipb=clip[0] + clip)
# adjusting color space from YUV420P8 to RGB24 for vsLevels
clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="limited")
# Apply the Levels filter to the clip (this will adjust color levels, range from 16-235).
# In this case, min_in=16, max_in=235 (input range), min_out=16, max_out=235 (output range), gamma=2.00 (adjust gamma).
filtered = core.std.Levels(clip=clip, min_in=16, max_in=235, min_out=16, max_out=235, gamma=2.00)
clip = filterOnlyIf(clip, filtered, thres=0.004, compare_method=">", debug=True) # Use '>' comparison)
This example will boost the gamma whenever, the changes are below 0.004.
Cu Selur
Ps.: if a few users think this is something that could be useful, I could add this as a general option. Won't add this atm., since I don't really have a use case for this. Like I wrote before, I think a motion mask would be the better fit for your scenario.