# Motion Compensation based FPS converter script (also known as jm_fps) by johnmeyer from Doom9
# Slightly modified interface by manolito
# Updated by MrC (October 2017)
# Following AviSynth plugins are required in the same folder:
#   mvtools2.dll		more info @ https://avisynth.org.ru/mvtools/mvtools2.html
#   RemoveGrainS.dll	more info @ http://avisynth.nl/index.php/RemoveGrain
# Following Libraries are required in System32 or SysWOW64 folder for Dct values other than 0:
#   fftw3.dll           more info @ http://www.fftw.org/install/windows.html

Loadplugin("mvtools2.dll")
Loadplugin("RemoveGrainS.dll")

function MCJMFPS(clip source, float "fps", int "BlkSize", int "Dct")
{
fps = default(fps, 25.000)
fps_num = int(fps * 1000)
fps_den = 1000
BlkSize = default(BlkSize, 16)
Dct = default(Dct, 0)

prefiltered = RemoveGrain(source, 22)
super = MSuper(source, hpad = 16, vpad = 16, levels = 1) # one level is enough for MRecalculate
superfilt = MSuper(prefiltered, hpad = 16, vpad = 16) # all levels for MAnalyse
backward = MAnalyse(superfilt, isb = true, blksize = BlkSize, overlap = 4, search = 3, dct = Dct)
forward = MAnalyse(superfilt, isb = false, blksize = BlkSize, overlap = 4, search = 3, dct = Dct)
forward_re = MRecalculate(super, forward, blksize = 8, overlap = 2, thSAD = 100)
backward_re = MRecalculate(super, backward, blksize = 8, overlap = 2, thSAD = 100)
out = MFlowFps(source, super, backward_re, forward_re, num = fps_num, den = fps_den, blend = false, ml = 200, mask = 2)

return out
}