Log in

View Full Version : newbie questions of VapourSynth


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?

jackoneill
10th December 2014, 16:49
I believe the native RemoveGrain plugin now supports all modes, and 8..16 bits. You can replace

rg11 = core.avs.Dither_removegrain16 (stacked, 11, 11, 11)

with

rg11 = core.rgvs.RemoveGrain(clip, 11)

That allows you to remove some of those conversions between native and stack16. (I don't think any native VapourSynth filters process stack16).

LSMASHSource also has a VapourSynth plugin, maybe in the same DLL. You can always just try loading it.

1. Yes, the equality operator in Expr is "=", not "==".
"/" versus "//" is a Python detail. "/" performs floating point division regardless of the input, while "//" performs integer division. You could also use "int(x / y)" where an integer result is needed. Maybe skim through the Python tutorial (https://docs.python.org/3/tutorial/index.html).

2.

import vapoursynth as vs

c = vs.get_core()

def fillborders(clip, left, right, top, bottom, color):
clip = c.std.CropRel(clip, left=left, right=right, top=top, bottom=bottom)
return c.std.AddBorders(clip, left=left, right=right, top=top, bottom=bottom, color=color)

src = c.ffms2.Source("video.mkv")
src = fillborders(src, 2, 4, 6, 8, [100, 200, 200])

src.set_output()

feisty2
10th December 2014, 17:13
Thx! That really helps, I'm reading the Python tutorial right now