Log in

View Full Version : Error of Dither_resize16nr porting


feisty2
31st January 2015, 16:15
a fat error jumps out when I try to port dither_resize16nr to vaporsynth for fun...

def Resize16nr (src, w=None, h=None, sx=0, sy=0, sw=0, sh=0, kernel="spline36", fh=1, fv=1, taps=4, a1=None, a2=None, a3=None, kovrspl=1, cnorm=True, center=True, fulls=None, fulld=None, cplace="mpeg2", invks=False, invkstaps=4, noring=True):
sr_h = float (w) / float (src.width)
sr_v = float (h) / float (src.height)
sr_up = max (sr_h, sr_v)
sr_dw = 1.0 / min (sr_h, sr_v)
sr = max (sr_up, sr_dw)

thr = 2.5
nrb = (sr > thr)
nrf = (sr < thr + 1.0 and noring)
nrr = min (sr - thr, 1.0) if (nrb) == True else 1.0
nrv = [round ((1.0 - nrr) * 65535), round ((1.0 - nrr) * 65535), round ((1.0 - nrr) * 65535)] if (nrb) == True else [0, 0, 0]
nrm = core.std.BlankClip (clip=src, width=w, height=h, color=nrv) if (nrb and nrf) == True else 0

main = core.fmtc.resample (src, w=w, h=h, sx=sx, sy=sy, sw=sw, sh=sh, kernel=kernel, fh=fh, fv=fv, taps=taps, a1=a1, a2=a2, a3=a3, kovrspl=kovrspl, cnorm=cnorm, center=center, fulls=fulls, fulld=fulld, cplace=cplace, invks=invks, invkstaps=invkstaps)
nrng = core.fmtc.resample (src, w=w, h=h, sx=sx, sy=sy, sw=sw, sh=sh, kernel="gauss", a1=100, center=center, fulls=fulls, fulld=fulld, cplace=cplace) if (nrf) == True else main

clip = core.rgvs.Repair(main, nrng, 1) if (nrf) == True else main
clip = core.std.MaskedMerge (main, clip, nrm) if (nrf and nrb) == True else clip
return clip


error code
Failed to evaluate the script:
Python exception: resample: argument w was passed an unsupported type
Traceback (most recent call last):
File "vapoursynth.pyx", line 1488, in vapoursynth.vpy_evaluateScript (src\cython\vapoursynth.c:25136)
File "", line 6, in <module>
File "C:\Python34\lib\site-packages\dither.py", line 170, in Resize16nr
main = core.fmtc.resample (src, w=w, h=h, sx=sx, sy=sy, sw=sw, sh=sh, kernel=kernel, fh=fh, fv=fv, taps=taps, a1=a1, a2=a2, a3=a3, kovrspl=kovrspl, cnorm=cnorm, center=center, fulls=fulls, fulld=fulld, cplace=cplace, invks=invks, invkstaps=invkstaps)
File "vapoursynth.pyx", line 1374, in vapoursynth.Function.__call__ (src\cython\vapoursynth.c:23473)
vapoursynth.Error: resample: argument w was passed an unsupported type

what did I do wrong this time :confused:

Are_
31st January 2015, 16:55
Nothing, it works for me. Post the full script where you are making use of this function?

PD: Also theres is an error in your script logic because if you feed float() with None it will throw an error.

TheFluff
31st January 2015, 16:56
Well, what parameters did you call it with? Read the exception trace, the actual error message is on the last line. The parameter "w" was of an unsupported data type, and since your function just passes it in unchanged from its own parameters, the source of the problem is probably with the caller.

Myrsloik
31st January 2015, 18:47
Nothing, it works for me. Post the full script where you are making use of this function?

PD: Also theres is an error in your script logic because if you feed float() with None it will throw an error.

Actually if an argument exists and is passed None it is simply discarded as if the argument wasn't set at all. Or should be at least.

This is to make using default values a lot less crazy. Early scripts had walls of "if x is not None: ... for each argument.

Are_
1st February 2015, 00:51
Actually if an argument exists and is passed None it is simply discarded as if the argument wasn't set at all. Or should be at least.

This is to make using default values a lot less crazy. Early scripts had walls of "if x is not None: ... for each argument.

I know about that feature and I think it is super handy, but I'm talking about what happens at the second line of that script, amongst other ones.

sr_h = float (w) / float (src.width)

It's python the one how will complain, not vapoursynth.

feisty2
1st February 2015, 05:29
hey, sorry for the late reply
went out and had a blast and away from home all day
full script

import vapoursynth as vs
import dither # where the Resize16nr function stored
core = vs.get_core()
clip = core.d2v.Source(dvd video)
clip = core.fmtc.bitdepth (clip,bits=16)
clip = dither.Resize16nr (clip, 1440, 960)
clip.set_output ()


it's real weird, it didn't work in the morning before I went out, and now, it just works..?
all I did in between was a restart cuz windows update required it...
how's that even possible, a restart magically fixed a python error???

feisty2
1st February 2015, 05:37
btw, what's the right way to default a parameter like "Undefined ()" in avisynth and not like just remove it actually...

EDIT: did a test and found out how to trigger the error, run vseditor and paste the script in it, preview it, everything's fine, close the preview window and try to preview again, the error appears, one time preview? that's new..

feisty2
1st February 2015, 13:37
I did a little modification and tried to shut the error up, but it just resists to go away .. :(

def Resize16nr (src, w=None, h=None, sx=0, sy=0, sw=0, sh=0, kernel="spline36", fh=1, fv=1, taps=4, a1=None, a2=None, a3=None, kovrspl=1, cnorm=True, center=True, fulls=None, fulld=None, cplace="mpeg2", invks=False, invkstaps=4, noring=True):
w = src.width if w is None else w
h = src.height if h is None else h
sr_h = float (w) / float (src.width)
sr_v = float (h) / float (src.height)
sr_up = max (sr_h, sr_v)
sr_dw = 1.0 / min (sr_h, sr_v)
sr = max (sr_up, sr_dw)

thr = 2.5
nrb = (sr > thr)
nrf = (sr < thr + 1.0 and noring)
nrr = min (sr - thr, 1.0) if (nrb) == True else 1.0
nrv = [round ((1.0 - nrr) * 65535), round ((1.0 - nrr) * 65535), round ((1.0 - nrr) * 65535)] if (nrb) == True else [0, 0, 0]
nrm = core.std.BlankClip (clip=src, width=w, height=h, color=nrv) if (nrb and nrf) == True else 0

main = core.fmtc.resample (src, w=w, h=h, sx=sx, sy=sy, sw=sw, sh=sh, kernel=kernel, fh=fh, fv=fv, taps=taps, a1=a1, a2=a2, a3=a3, kovrspl=kovrspl, cnorm=cnorm, center=center, fulls=fulls, fulld=fulld, cplace=cplace, invks=invks, invkstaps=invkstaps)
nrng = core.fmtc.resample (src, w=w, h=h, sx=sx, sy=sy, sw=sw, sh=sh, kernel="gauss", a1=100, center=center, fulls=fulls, fulld=fulld, cplace=cplace) if (nrf) == True else main

clip = core.rgvs.Repair (main, nrng, 1) if (nrf) == True else main
clip = core.std.MaskedMerge (main, clip, nrm) if (nrf and nrb) == True else clip
return clip


the "you only get to preview once" error still remains...

Myrsloik
1st February 2015, 13:45
Try reading the error messages. Or at least posting them if you're stuck. WHY IS THIS SO HARD?

I'll tell you why it happens. It happens because you're not posting the whole script. In dither.py you've got the line "core = vs.get_core()" in global scope. I can smell it all the way from here even if you're trying to hide it. Because of how python evaluates imported modules (only once) it will always refer to the first script's core and not the reloaded script's core.

Call vs.get_core() inside each individual function instead and reloading will work.

Are_
1st February 2015, 13:51
I don't know if this has anything to do with your error, but if your Dither.py script is still like the one you have on github you have to remove the second line "core = vs.get_core()" and copy it inside all functions.

Also maybe you already noticed it, but if you change anything in any file you import in your script, you have to completly reload your python enviroment by completly closing vsedit (that's a little inconvenient :/).

feisty2
1st February 2015, 14:02
okay... problem solved
I wasn't hiding anything, I just didn't know such rule exists before, now I got it, the same mistake won't happen again
:thanks: