~/.config/mpv/vapoursynth/mvtools.vpy
# vim: set ft=python:
## Use MVTools's BlockFPS function to perform motion interpolation on the video in realtime.
import vapoursynth as vs
core = vs.get_core()
dst_fps = display_fps
# MPV player
if "video_in" in globals():
# realtime
clip = video_in
# Interpolating to fps higher than 60 is too CPU-expensive, smoothmotion can handle the rest.
while (dst_fps > 60):
dst_fps /= 2
# Skip interpolation for >1080p or 60 Hz content due to performance
if not (clip.width > 1920 or clip.height > 1100 or container_fps > 59):
# f3kdb --> 16bit
if (clip.height <= 900):
clip = core.std.Trim(clip, first=0, length=500000)
clip = core.f3kdb.Deband(clip, output_depth=16, dynamic_grain=True, grainy=16, grainc=16)
src_fps_num = int(container_fps * 1e8)
src_fps_den = int(1e8)
# Needed because clip FPS is missing
clip = core.std.AssumeFPS(clip, fpsnum = src_fps_num, fpsden = src_fps_den)
#print("Motion Interpolation from ",src_fps_num/src_fps_den,"fps to",dst_fps_num/dst_fps_den,"fps.")
# Encoding
else:
# run with vspipe
clip = core.ffms2.Source(source=in_filename)
clip = core.resize.Bicubic(clip,1280,720,filter_param_a=0,filter_param_b=0.75)
dst_fps=float(dst_fps)
dst_fps_num = int(dst_fps * 1e4)
dst_fps_den = int(1e4)
sup = core.mv.Super(clip, pel=2, hpad=16, vpad=16)
bvec = core.mv.Analyse(sup, blksize=16, isb=True , chroma=True, search=3, searchparam=1)
fvec = core.mv.Analyse(sup, blksize=16, isb=False, chroma=True, search=3, searchparam=1)
clip = core.mv.BlockFPS(clip, sup, bvec, fvec, num=dst_fps_num, den=dst_fps_den, mode=3, thscd2=12)
clip.set_output()