feisty2
10th December 2014, 16:13
I was kind of "got nothing to do" today, so I just thought, why not try to learn something new, then I wrote my very first vapoursynth script, the "Hello World!" like script below, simple script but a little bit more complex than the "getting started" example, it runs successfully, but I still got a few questions
import vapoursynth as vs
core = vs.get_core()
core.avs.LoadPlugin("dither.dll")
core.avs.LoadPlugin("LSMASHSource.dll")
clip = core.avs.LWLibavVideoSource ("some video")
clip = core.fmtc.stack16tonative (clip)
stacked = core.fmtc.nativetostack16 (clip)
rg11 = core.avs.Dither_removegrain16 (stacked, 11, 11, 11)
native = core.fmtc.stack16tonative (rg11)
rg11D = core.std.Expr (clips = [clip, native], expr = ["x y - 32768 +"], format = vs.YUV420P16)
rg11Dstk = core.fmtc.nativetostack16 (rg11D)
rg11Drstk = core.avs.Dither_removegrain16 (rg11Dstk, 11, 11, 11)
rg11Dr = core.fmtc.stack16tonative (rg11Drstk)
abrg11D = core.std.Expr (clips = [rg11D], expr = ["x 32768 - abs"], format = vs.YUV420P16)
Ddif = core.std.Expr (clips = [rg11D, rg11Dr], expr = ["x y - 32768 +"], format = vs.YUV420P16)
abDdif = core.std.Expr (clips = [Ddif], expr = ["x 32768 - abs"], format = vs.YUV420P16)
abDDD = core.std.Expr (clips = [abDdif, abrg11D], expr = ["x y - 32768 +"], format = vs.YUV420P16)
Dmask1 = core.std.Expr (clips = [abDDD], expr = ["x 32768 < 65535 0 ?"], format = vs.YUV420P16)
Ddifgn = core.std.Expr (clips = [Ddif], expr = ["x 32768 = x x 32768 < 0 65535 ? ?"], format = vs.YUV420P16)
Ddifgs = core.fmtc.nativetostack16 (Ddifgn)
Ddifg = core.std.CropRel(Ddifgs, 0, 0, 0, (Ddifgs.height // 2))
rg11Dgn = core.std.Expr (clips = [rg11D], expr = ["x 32768 = x x 32768 < 0 65535 ? ?"], format = vs.YUV420P16)
rg11Dgs = core.fmtc.nativetostack16 (rg11Dgn)
rg11Dg = core.std.CropRel(rg11Dgs, 0, 0, 0, (rg11Dgs.height // 2))
Dmask2l = core.std.Expr (clips = [Ddifg, rg11Dg], expr = ["x 128 - y 128 - * 0 < 0 255 ?"], format = vs.YUV420P8)
DD1 = core.std.Expr (clips = [rg11D, Ddif, Dmask1], expr = ["65536 z - x * z y * + 32768 + 65536 /"], format = vs.YUV420P16)
blankdif = core.std.Expr (clips = [DD1], expr = ["32768"], format = vs.YUV420P16)
Dmask2s = core.std.StackVertical([Dmask2l, Dmask2l])
Dmask2 = core.fmtc.stack16tonative (Dmask2s)
DD2 = core.std.Expr (clips = [blankdif, DD1, Dmask2], expr = ["65536 z - x * z y * + 32768 + 65536 /"], format = vs.YUV420P16)
output = core.std.Expr (clips = [clip, DD2], expr = ["x y - 32768 +"], format = vs.YUV420P16)
output.set_output ()
1. are operators altered in vapoursynth? the red marked "=" should be "==" in avisynth, but I have to change it to "=" or vs gives me error, and I can't use "/" anymore, I have to use "//"
2. how to wrap a function exactly? it's very simple in avs (Function xxx (parameters)), I tried "def" in vs several times but failed miserably, it just throws me all kinds of errors, could someone kind please show me a simple example of wrapping functions?
import vapoursynth as vs
core = vs.get_core()
core.avs.LoadPlugin("dither.dll")
core.avs.LoadPlugin("LSMASHSource.dll")
clip = core.avs.LWLibavVideoSource ("some video")
clip = core.fmtc.stack16tonative (clip)
stacked = core.fmtc.nativetostack16 (clip)
rg11 = core.avs.Dither_removegrain16 (stacked, 11, 11, 11)
native = core.fmtc.stack16tonative (rg11)
rg11D = core.std.Expr (clips = [clip, native], expr = ["x y - 32768 +"], format = vs.YUV420P16)
rg11Dstk = core.fmtc.nativetostack16 (rg11D)
rg11Drstk = core.avs.Dither_removegrain16 (rg11Dstk, 11, 11, 11)
rg11Dr = core.fmtc.stack16tonative (rg11Drstk)
abrg11D = core.std.Expr (clips = [rg11D], expr = ["x 32768 - abs"], format = vs.YUV420P16)
Ddif = core.std.Expr (clips = [rg11D, rg11Dr], expr = ["x y - 32768 +"], format = vs.YUV420P16)
abDdif = core.std.Expr (clips = [Ddif], expr = ["x 32768 - abs"], format = vs.YUV420P16)
abDDD = core.std.Expr (clips = [abDdif, abrg11D], expr = ["x y - 32768 +"], format = vs.YUV420P16)
Dmask1 = core.std.Expr (clips = [abDDD], expr = ["x 32768 < 65535 0 ?"], format = vs.YUV420P16)
Ddifgn = core.std.Expr (clips = [Ddif], expr = ["x 32768 = x x 32768 < 0 65535 ? ?"], format = vs.YUV420P16)
Ddifgs = core.fmtc.nativetostack16 (Ddifgn)
Ddifg = core.std.CropRel(Ddifgs, 0, 0, 0, (Ddifgs.height // 2))
rg11Dgn = core.std.Expr (clips = [rg11D], expr = ["x 32768 = x x 32768 < 0 65535 ? ?"], format = vs.YUV420P16)
rg11Dgs = core.fmtc.nativetostack16 (rg11Dgn)
rg11Dg = core.std.CropRel(rg11Dgs, 0, 0, 0, (rg11Dgs.height // 2))
Dmask2l = core.std.Expr (clips = [Ddifg, rg11Dg], expr = ["x 128 - y 128 - * 0 < 0 255 ?"], format = vs.YUV420P8)
DD1 = core.std.Expr (clips = [rg11D, Ddif, Dmask1], expr = ["65536 z - x * z y * + 32768 + 65536 /"], format = vs.YUV420P16)
blankdif = core.std.Expr (clips = [DD1], expr = ["32768"], format = vs.YUV420P16)
Dmask2s = core.std.StackVertical([Dmask2l, Dmask2l])
Dmask2 = core.fmtc.stack16tonative (Dmask2s)
DD2 = core.std.Expr (clips = [blankdif, DD1, Dmask2], expr = ["65536 z - x * z y * + 32768 + 65536 /"], format = vs.YUV420P16)
output = core.std.Expr (clips = [clip, DD2], expr = ["x y - 32768 +"], format = vs.YUV420P16)
output.set_output ()
1. are operators altered in vapoursynth? the red marked "=" should be "==" in avisynth, but I have to change it to "=" or vs gives me error, and I can't use "/" anymore, I have to use "//"
2. how to wrap a function exactly? it's very simple in avs (Function xxx (parameters)), I tried "def" in vs several times but failed miserably, it just throws me all kinds of errors, could someone kind please show me a simple example of wrapping functions?