SetMemoryMax(1024)
global threads=7
LoadPlugin("C:\Program Files (x86)\SVP\plugins\x64\svpflow1.dll")
LoadPlugin("C:\Program Files (x86)\SVP\plugins\x64\svpflow2.dll")

global crop_params=""

x = last.width          # video width
y = last.height         # video height
ar = float(x) / float(y) # ar = aspect ratio, to keep the video ar as is

(y > 900) ? \
    eval("""
        y = 900
        x = int(y * ar)
    """) : nop()

(x > 1600) ? \
    eval("""
        x = 1600
        y = int(float(x) / ar)
    """) : nop()

# LanczosResize balked when the pixel is odd
x = (x % 2 == 0) ? x : x-1
y = (y % 2 == 0) ? y : y-1

# setting for 1920x1080
global resize_string="LanczosResize(" + string(x) + ", " + string(y) + ")"
global super_params="{pel:1,scale:{up:0},gpu:1,full:false,rc:true}"
global analyse_params="""
{
    block:{
        w:32,h:32,overlap:1
    },
    main:{
        distance: 0,
        search:{
            type: 3,
            coarse:{
                width: 1600,
                satd: false,
                bad:{
                    sad: 1000,
                    range: 24
                },
                distance:-6
            }
        },
        penalty: {
            plevel: 1.0,
            prev: 50
        }
    },
    refine: [{
        thsad: 8000,
        search: { distance: 1 }
    }]
}"""


maskArea = 0
algo = "13"

# usedefault is defined to simplify switching between option that I used
# with SVP Manager and the options that I experimented
# The values below are pretty much default though.
usedefault = false

global smoothfps_params = usedefault ? \
    "{rate:{num:" + string(num) + ",den: " \
        + string(den) + "},algo:13,mask:{area: " + string(maskArea) + \
        "},scene:{}}" : \
    """
{
    rate: {
        num: """ + string(num) + """,
        den: """ + string(den) + """
    },
    algo: """ + algo + """,
    mask: {
        cover: 100,
        area: """ + string(maskArea) + """,
        area_sharp: 1.0
    },
    scene: {
        limits: {
            m1: 1600,
            m2: 2800,
            scene: 4000,
            zero: 100,
            blocks: 10
        }
    }
}"""

# Script below are from "last used AVS script" from SVP Manager
# I left it as is
global demo_mode=0
stereo_type=0
stereo_left_selection=""
stereo_right_selection=""

function interpolate(clip src)
{
	input = crop_params=="" ? src : eval("src.crop("+crop_params+")")
	input = resize_string=="" ? input : eval("input."+resize_string)
	super=SVSuper(input, super_params)
	vectors=SVAnalyse(super, analyse_params, src=input)
	smooth=SVSmoothFps(input, super, vectors, smoothfps_params, mt=threads, url="www.svp-team.com")
	return demo_mode==0 ? smooth : demo(input,smooth)
}
input=last
	stereo_type==0 ? eval(""" interpolate(input)
""") : 	stereo_type==1 || stereo_type==3 ? eval("""
		lf = interpolate(input.crop(0,0,input.width/2,0))"""+stereo_left_selection+"""
		rf = interpolate(input.crop(input.width/2,0,0,0))"""+stereo_right_selection+"""
		StackHorizontal(lf, rf)
""") : 	stereo_type==2 || stereo_type==4  ? Eval("""
		lf = interpolate(input.crop(0,0,0,input.height/2))"""+stereo_left_selection+"""
		rf = interpolate(input.crop(0,input.height/2,0,0))"""+stereo_right_selection+"""
		StackVertical(lf, rf)""") : input
Prefetch(threads)
