Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 24th July 2015, 02:20   #1  |  Link
Ninaz
Registered User
 
Join Date: Jul 2015
Location: Canada
Posts: 5
Vapoursynth AddBorders with StaxRip

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.

Not understanding how to write this properly, I have to ask if someone would kindly help.
Ninaz is offline   Reply With Quote
Old 24th July 2015, 02:58   #2  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
Here's an example on how to use AddBorders:

Code:
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.
Reel.Deel is offline   Reply With Quote
Old 24th July 2015, 04:54   #3  |  Link
Ninaz
Registered User
 
Join Date: Jul 2015
Location: Canada
Posts: 5
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?
Ninaz is offline   Reply With Quote
Old 24th July 2015, 05:08   #4  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
import vapoursynth as vs
core = vs.get_core()
feisty2 is offline   Reply With Quote
Old 24th July 2015, 09:57   #5  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,837
you have to use clip instead of src, I might be able to remove this restriction, profiles use clip and core as variable names.

Code:
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:

Code:
[Borders]
AddBorder1080 =
	w = (1920 - width) / 2.0
	h = (1080 - height) / 2.0
	AddBorders(floor(w), floor(h), ceil(w), ceil(h))
stax76 is offline   Reply With Quote
Old 24th July 2015, 23:33   #6  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by Reel.Deel View Post
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.
splinter98 is offline   Reply With Quote
Old 25th July 2015, 00:21   #7  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
@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.
Reel.Deel is offline   Reply With Quote
Old 25th July 2015, 01:24   #8  |  Link
Ninaz
Registered User
 
Join Date: Jul 2015
Location: Canada
Posts: 5
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.
Ninaz is offline   Reply With Quote
Old 25th July 2015, 09:05   #9  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Reel.Deel View Post
@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.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 25th July 2015, 16:52   #10  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by jackoneill View Post
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.
splinter98 is offline   Reply With Quote
Old 25th July 2015, 17:41   #11  |  Link
Ninaz
Registered User
 
Join Date: Jul 2015
Location: Canada
Posts: 5
Quote:
Originally Posted by stax76 View Post

Code:
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.
Ninaz is offline   Reply With Quote
Old 25th July 2015, 17:51   #12  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by Ninaz View Post
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]
splinter98 is offline   Reply With Quote
Old 25th July 2015, 21:04   #13  |  Link
Ninaz
Registered User
 
Join Date: Jul 2015
Location: Canada
Posts: 5
BANG ON!

Thank you, thank you
Ninaz is offline   Reply With Quote
Old 26th July 2015, 02:29   #14  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: void
Posts: 2,633
Quote:
Originally Posted by splinter98 View Post
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...
feisty2 is offline   Reply With Quote
Old 26th July 2015, 19:16   #15  |  Link
splinter98
Registered User
 
Join Date: Oct 2010
Posts: 36
Quote:
Originally Posted by feisty2 View Post
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.

Last edited by splinter98; 26th July 2015 at 19:29. Reason: Correct my previous error
splinter98 is offline   Reply With Quote
Reply

Tags
addborders, vapoursynth

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:36.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.