Log in

View Full Version : Vapoursynth AddBorders with StaxRip


Ninaz
24th July 2015, 02:20
I’m familiar with the Avisynth function (script?) “AddBorders(0, 86, 0, 86, $000000)”. Using this in Vapoursynth creates a Python error, saying there’s an invalid syntax. Understandably you may say.

Vapoursynth docs indicates the Avisynth equivalent as “std.AddBorders” or “std.AddBorders(clip clip[, int left=0, int right=0, int top=0, int bottom=0, float[] color=<black>])”.

My feeble attempts have not resulted in a positive.:confused:

Not understanding how to write this properly, I have to ask if someone would kindly help.

Reel.Deel
24th July 2015, 02:58
Here's an example on how to use AddBorders:

import vapoursynth as vs
core = vs.get_core()

src = core.std.BlankClip(color=[255, 255, 255])

src = core.std.AddBorders(clip=src, left=0, right=0, top=86, bottom=86, color=[0, 0, 0])

src.set_output()

Unlike AviSynth, the color values are not specified in hex.

Ninaz
24th July 2015, 04:54
Thanks for your assistance.

Adjusted top and bottom numbers and loaded your code into StaxRip’s Scripting Editor, and got the following error:

Python exception: name 'core' is not defined
Traceback (most recent call last):
File "vapoursynth.pyx", line 1467, in vapoursynth.vpy_evaluateScript (src\cython\vapoursynth.c:24719)
File "N:\Rips\TS00852\TS00852 temp files\TS00852_new.vpy", line 1, in <module>
core.std.LoadPlugin(r'N:\Portable\StaxRip\Apps\Plugins\both\ffms2\ffms2.dll')
NameError: name 'core' is not defined

Any ideas?

feisty2
24th July 2015, 05:08
import vapoursynth as vs
core = vs.get_core()

stax76
24th July 2015, 09:57
you have to use clip instead of src, I might be able to remove this restriction, profiles use clip and core as variable names.

clip = core.std.AddBorders(clip = clip, left = 0, right = 0, top = 86, bottom = 86, color = [0, 0, 0])

maybe you are interested in what a AviSynth profile might look like:

[Borders]
AddBorder1080 =
w = (1920 - width) / 2.0
h = (1080 - height) / 2.0
AddBorders(floor(w), floor(h), ceil(w), ceil(h))

splinter98
24th July 2015, 23:33
Unlike AviSynth, the color values are not specified in hex.

Technically not 100% true, Python supports 0x hex notation and will automatically convert it into decimal, so: [0xFF, 0xFF, 0xFF] is the same as [255, 255, 255] so if you're converting Avisynth scripts you don't have to do the hex conversion.

It's also good to note that the color parameter replaces both color and color_yuv in blank clip in Avisynth. Vapoursynth will use the RGB if the format is an RGB format, YUV if it is a YUV format, and Grey if it is a single channel clip.

The other thing to be aware of is the color number is also related to the bit depth of the clip, so 8bit clips will have 255 as white (or 235 for limited range), 10bit clips white is 1023, 16bit clips is 65535 and 1.0 for float. So if dealing with high bit depth clips using 8 bit colors will not work and will need to be converted to the correct format.

This information is lacking in the documentation, and should be added.

Reel.Deel
25th July 2015, 00:21
@splinter98

Thanks for that informational post, I did not know that. Yes, some parts of the VapourSynth documentation can be a bit vague, especially for us that are not Python experts.

Ninaz
25th July 2015, 01:24
Thanks Stax76, your code worked beautifully and seems more straight forward (in my mind). Is it specific to StaxRip?

I know there seems to be more interest in cropping than adding borders. Have you considered adding a Border Menu alongside Aspect Ratio and Crop within Image Options?

Thank you so much for helping and for everyone’s patience with a non-coder.

jackoneill
25th July 2015, 09:05
@splinter98

Thanks for that informational post, I did not know that. Yes, some parts of the VapourSynth documentation can be a bit vague, especially for us that are not Python experts.

If you point out something specific, I'll be happy to fix it.

splinter98
25th July 2015, 16:52
If you point out something specific, I'll be happy to fix it.
A summary of my previous post in BlankClip and AddBorders (and any other filter that uses the color semantics) would be useful to add.

Ninaz
25th July 2015, 17:41
clip = core.std.AddBorders(clip = clip, left = 0, right = 0, top = 86, bottom = 86, color = [0, 0, 0])


Border color is dark green. Everywhere I look [0, 0, 0] is black and black is what I want. I've also entered different numbers and preview is always dark green. I don't understand.

When using the Avisynth code, $000000 is black and I get black.

splinter98
25th July 2015, 17:51
Border color is dark green. Everywhere I look [0, 0, 0] is black and black is what I want. I've also entered different numbers and preview is always dark green. I don't understand.

When using the Avisynth code, $000000 is black and I get black.

You're falling into the pitfall of the clip format is yuv. (you'd get the same issue in AviSynth if you used color_yuv=$000000 instead of color=$000000).

color defaults to black if it isn't set, but for YUV it should be: [0, 128, 128]

Ninaz
25th July 2015, 21:04
BANG ON!

Thank you, thank you

feisty2
26th July 2015, 02:29
color defaults to black if it isn't set, but for YUV it should be: [0, 128, 128]

that depends, actually, it's still [0, 0, 0] for float YUV clips...

splinter98
26th July 2015, 19:16
that depends, actually, it's still [0, 0, 0] for float YUV clips...

If the YUV colour space is actually Y'CbCr yes. (as Cb, Cr are in the range -0.5 to 0.5 and not 0 to 1).

EDIT: Actually no my mistake, Integer YUV types are shifted by (2^bitdepth)/2 to make all the numbers positive.