Skip to content

Commit b60b7c6

Browse files
committed
rstdoc: AddBorders, LetterBox new options
1 parent d163e32 commit b60b7c6

3 files changed

Lines changed: 197 additions & 12 deletions

File tree

distrib/docs/english/source/avisynthdoc/corefilters/addborders.rst

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Add black or colored borders, increasing frame size. This has several common use
77
* Adjust the `aspect ratio`_ (make a 4:3 clip into 16:9 without stretching)
88
* :doc:`Splice <splice>` a smaller resolution clip to a larger one without resizing
99
* Together with :doc:`Crop <crop>`, shift a clip horizontally or vertically – see below.
10+
* Optionally filters the transient areas. (3.7.4-)
1011

1112
See also: :doc:`letterbox`, which adds borders without changing frame size.
1213

@@ -16,7 +17,8 @@ Syntax and Parameters
1617

1718
::
1819

19-
AddBorders (clip clip, int left, int top, int right, int bottom, int "color", int "color_yuv")
20+
AddBorders (clip clip, int left, int top, int right, int bottom, int "color", int "color_yuv",
21+
string "resample", float "param1", float "param2", float "param3", int "r" )
2022

2123
.. describe:: clip
2224

@@ -48,11 +50,82 @@ Syntax and Parameters
4850

4951
.. describe:: color_yuv
5052

51-
Specifies the border color using YUV values. Input clip must be YUV;
52-
otherwise an error is raised. See the :ref:`YUV colors <yuv-colors>` for
53-
more information.
54-
55-
53+
| Specifies the border color using YUV values. Input clip must be YUV;
54+
otherwise an error is raised.
55+
| Similar to ``color_yuv`` in :doc:`BlankClip <blankclip>`
56+
57+
.. describe:: resample
58+
59+
string resample = "gauss"
60+
61+
When `r` radius is not zero, then determines which resampler is used in the transient filtering.
62+
All AviSynth :doc:`resizers <resize>` are allowed:
63+
("point", "bilinear", "bicubic", "lanczos", "lanczos4", "blackman", "spline16", "spline36", "spline64",
64+
"gauss" and "sinc", "sinpow", "sinclin2" and "userdefined2").
65+
66+
Default is "gauss".
67+
68+
.. describe:: param1, param2, param3
69+
70+
These 'float' type parameters can be the additional parameters for the
71+
resampler. Some resizer algorithms would need and can be fine tuned with up to 3 parameters.
72+
Their default values depend on the selected chromaresample resizer kernel.
73+
74+
default (when "gauss"):
75+
76+
* param1 (p), param2(b), param3(s): p=10, b=2.71828182, s=0
77+
78+
for other resizer algoritms see in :doc:`resizers <resize>`.
79+
80+
.. describe:: r
81+
82+
int r = 0
83+
84+
The radius of the transient treatment in pixels. The value is meant as +/- around the border line.
85+
86+
When `r` radius is not zero, transient filtering occurs.
87+
Even ``r=1`` is giving sufficient protection for some next processing stages.
88+
89+
Why: by filtering the transient areas (boundary of the new borders), we can prevent
90+
artifacts e.g. ringing after a subsequent upscale.
91+
92+
This is how it works:
93+
94+
Eight crops are taken from around the transient areas:
95+
96+
- left and right rectangles, which cover +/- 10 (but at least ``r``) pixels
97+
horizontally around the new border line.
98+
- top and bottom rectangles, which cover +/- 10 (but at least ``r``) pixels
99+
vertically around the new border line.
100+
- four corners, top left, top right, bottom left, bottom right, dimension rules
101+
as seen above.
102+
103+
These eight rectangles are "resized", using the given resizer in convolution mode.
104+
No dimension is changed, just we'll get a blurred area.
105+
106+
Since 3.7.4 resizers can accept a ``force`` parameter, so we use it.
107+
108+
- left and right parts need only horizontal treatment.
109+
- top and bottom parts need only vertical treatment.
110+
- corners get both H and V processing.
111+
112+
Then, from this larger area only a central ``r`` (radius)-wide rectangle is copied over the transient area.
113+
114+
The left and right side will be overwritten by a ``r * original_height`` sized part.
115+
At the top and bottom an ``original_width * r`` sized rectangle will be copied back.
116+
And a ``r * r`` rectangle is copied over the corners.
117+
118+
The exact dimensions can be a bit different, e.g. if ``r`` is larger than the actually added left border.
119+
Then the radius is reduced accordingly.
120+
121+
The ``r`` radius is automatically adjusted with the video format subsampling requirements.
122+
AddBorders won't give error if e.g. for a YV12 ``r=1`` is given: due to the chroma subampling it will be
123+
automatically promoted to 2.
124+
125+
Other notes:
126+
127+
This copy-paste of the up-to eight area is using a new :doc:`MultiOverlay <multioverlay>` filter.
128+
56129
Examples
57130
--------
58131

@@ -86,13 +159,75 @@ Examples
86159
on color format.
87160
* You can shift in sub-pixel increments with :doc:`Resize <resize>`.
88161

162+
* AddBorders with filtering
163+
164+
::
165+
166+
# Add 20 black pixels around the clip, filters (blurs) 1 pixel with the default "gauss" method
167+
AddBorders(20, 20, 20, 20, r=1)
168+
169+
* AddBorders filtering test script
170+
::
171+
172+
Function AddBordersHF(clip c, int left, int right, int flt_rad)
173+
{
174+
unflt=AddBorders(c, left, 0, right, 0)
175+
flt=GaussResize(unflt, unflt.width, unflt.height, p=10, b=2.71828, s=0, force=1)
176+
uf_internal=Crop(c, flt_rad, 0, c.width-flt_rad*2, c.height)
177+
return Overlay(flt, uf_internal, x=left+flt_rad, y=0)
178+
}
179+
180+
Function AddBordersVF(clip c, int top, int bottom, int flt_rad)
181+
{
182+
unflt=AddBorders(c, 0, top, 0, bottom)
183+
flt=GaussResize(unflt, unflt.width, unflt.height, p=10, b=2.71828, s=0, force=2)
184+
uf_internal=Crop(c, 0, flt_rad, 0, c.height - flt_rad*2)
185+
return Overlay(flt, uf_internal, x=0, y=top+flt_rad)
186+
}
187+
188+
Function Diff(clip src1, clip src2)
189+
{
190+
return Subtract(src1.ConvertBits(8),src2.ConvertBits(8)).Levels(120, 1, 255-120, 0, 255, coring=false)
191+
}
192+
193+
ColorBarsHD(2000,2000)
194+
UserDefined2Resize(width/10, height/10)
195+
196+
# filtering area, means +/- around the border boundaries
197+
r1=2
198+
r2=2
199+
200+
left=20
201+
top=20
202+
right=20
203+
bottom=20
204+
205+
std=AddBorders(left, top, right, bottom)
206+
a=last
207+
a=AddBordersHF(a, left, right, r1)
208+
a=AddBordersVF(a, top, bottom, r1).SubTitle("Scriptbased", align=5)
209+
210+
b=last
211+
b=AddBorders(b, left, top, right, bottom, param1=10, param2=2.71828, param3=0, r=r2).SubTitle("AVS 3.7.4", align=5)
212+
213+
d1 = Diff(a,b)
214+
d2 = Diff(std,a)
215+
d3 = Diff(std,b)
216+
217+
StackHorizontal(StackVertical(std, a, b), Stackvertical(d1, d2, d3))
218+
219+
LanczosResize(width*4, height*2, taps=16)
220+
221+
89222

90223
Changelog
91224
----------
92225

93226
+-----------------+------------------------------------------------------------------+
94227
| Version | Changes |
95228
+=================+==================================================================+
229+
| 3.7.4 | Add filtering. resample, param1, param2, param3, r parameters |
230+
+-----------------+------------------------------------------------------------------+
96231
| AviSynth+ 3.6.2 | Fix: AddBorders did not pass frame properties |
97232
+-----------------+------------------------------------------------------------------+
98233
| AviSynth+ 3.5.0 | New ``color_yuv`` parameter like in BlankClip |

distrib/docs/english/source/avisynthdoc/corefilters/letterbox.rst

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ Fills the top and bottom *rows* of each frame, and optionally the left and right
1010
* Black out the video noise at the bottom of the frame in `VHS`_ tape sources.
1111
* Black out overscan areas in `VCD`_ or `SVCD`_ sources.
1212
* Create a quick rectangular mask for other filters – a so-called "`garbage matte`_".
13+
* Optionally filters the transient areas. (3.7.4-)
1314

1415
See also: :doc:`AddBorders <addborders>`, which increases frame size.
1516
**Letterbox** does not change frame size.
1617

17-
The functionality of **Letterbox** can be duplicated with a combination of
18+
Actually, the functionality of **Letterbox** is performed with a combination of
1819
:doc:`Crop <crop>` and :doc:`AddBorders <addborders>`, but **Letterbox** is
19-
faster and easier.
20+
easier to use.
2021

2122
Generally, it's better to **Crop** video noise off than to black it out; many
2223
older lossy compression algorithms don't deal well with solid-color borders,
@@ -30,7 +31,8 @@ Syntax and Parameters
3031

3132
::
3233

33-
Letterbox (clip, int top, int bottom, int "x1", int "x2", int "color", int "color_yuv")
34+
Letterbox (clip, int top, int bottom, int "x1", int "x2", int "color", int "color_yuv"
35+
string "resample", float "param1", float "param2", float "param3", int "r" )
3436

3537
.. describe:: clip
3638

@@ -42,13 +44,19 @@ Syntax and Parameters
4244

4345
* For YUV420 sources, top and bottom must be `mod2`_ (divisible by 2).
4446

47+
``top+bottom`` must be less than the frame height, or else the first phase (Crop) would
48+
result in error with a zero-height clip.
49+
4550
.. describe:: x1, x2
4651

4752
Number of *left* (``x1``) and *right* (``x2``) columns to blank out.
4853

4954
* For YUV422 and YUV420 sources, left and right must be `mod2`_ (divisible by 2).
5055
* For YUV411 sources, left and right must be `mod4`_ (divisible by 4).
5156

57+
``x1+x2`` must be less than the frame width, or else the first phase (Crop) would
58+
result in error with a zero-width clip.
59+
5260
Default: 0, 0
5361

5462
.. describe:: color
@@ -68,8 +76,35 @@ Syntax and Parameters
6876

6977
.. describe:: color_yuv
7078

71-
| Specifies the fill color using YUV values. Input clip must be YUV.
72-
| See the :ref:`YUV colors <yuv-colors>` section for more information.
79+
| Specifies the color of the border using YUV values. Input clip must be YUV,
80+
otherwise it does nothing.
81+
| Similar to ``color_yuv`` in :doc:`BlankClip <blankclip>`
82+
83+
.. describe:: resample
84+
85+
string resample = "gauss"
86+
87+
When `r` radius is not zero, then determines which resampler is used in the transient filtering.
88+
89+
Default is "gauss".
90+
91+
For detailed description see :doc:`AddBorders <addborders>`.
92+
93+
94+
.. describe:: param1, param2, param3
95+
96+
These 'float' type parameters can be the additional parameters for the
97+
resampler.
98+
99+
For detailed description see :doc:`AddBorders <addborders>`.
100+
101+
.. describe:: r
102+
103+
int r = 0
104+
105+
The radius of the transient treatment in pixels. The value is meant as +/- around the border line.
106+
107+
For detailed description see :doc:`AddBorders <addborders>`.
73108

74109

75110
Changelog
@@ -78,6 +113,8 @@ Changelog
78113
+-----------------+---------------------------------------------------------------+
79114
| Version | Changes |
80115
+=================+===============================================================+
116+
| 3.7.4 | Add filtering. resample, param1, param2, param3, r parameters |
117+
+-----------------+---------------------------------------------------------------+
81118
| AviSynth+ 3.4.1 | Added ``color_yuv`` option. |
82119
+-----------------+---------------------------------------------------------------+
83120
| AviSynth+ r2487 | Added support for RGB48/64 and all Planar RGB(A)/YUV(A) color |
@@ -88,7 +125,7 @@ Changelog
88125
| AviSynth 2.0.6 | Added optional left and right parameters (``x1`` and ``x2``). |
89126
+-----------------+---------------------------------------------------------------+
90127

91-
$Date: 2022/02/08 11:37:04 $
128+
$Date: 2025/03/14 14:00:00 $
92129

93130
.. _VHS:
94131
https://en.wikipedia.org/wiki/VHS

distrib/docs/english/source/avisynthdoc/corefilters/resize.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ with nondefault settings.
137137
* 'param1', 'param2' and "param3" are always float. For 'taps' 'param1' is truncated to integer internally.
138138
When a resizer does not use one or more parameters they are simply ignored.
139139

140+
Resizers in AddBorders and LetterBox
141+
------------------------------------
142+
143+
Optionally, when a filtering radius is given, a custom resizer can be added to :doc:`AddBorders <addborders>` and
144+
:doc:`LetterBox <letterbox>`. In these filters the transient areas (boundary of the new borders) are filtered,
145+
in order to prevent ringing e.g. in a subsequent upscale.
146+
147+
The filters are used purely as convolution filters, no real resize happens.
148+
149+
Everything is the same as mentioned above in ``Resizers in ConvertToXXXX`` section, except, that
150+
``'gauss'`` default parameters are tunes for blurring:
151+
152+
* p,b,s: gauss (p=10, b=2.71828182, s=0)
140153

141154

142155
Syntax and Parameters

0 commit comments

Comments
 (0)