AddBorders: Difference between revisions

From Avisynth wiki
Jump to navigationJump to search
Raffriff42 (talk | contribs)
m added category
Raffriff42 (talk | contribs)
formatting, links, phrasing
Line 1: Line 1:
{{Template:FuncDef|AddBorders(clip ''clip'', int ''left'', int ''top'', int ''right'', int ''bottom'' [, int ''color''])}}
Add black or colored borders, increasing frame size.


AddBorders adds black (or specified color) borders around the image, with the specified widths (in pixels). [[YV12]]/[[YUY2]] format only stores color information for every two pixels horizontally, so if you're processing in YV12/YUY2 mode, left and right must be even.
{{FuncDef
|AddBorders( clip ''clip'', int ''left'', int ''top'', int ''right'', int ''bottom'' [, int ''color'' ] )
}}


The color parameter is optional (added in v2.07), default=0 <black>, and is specified as an [[RGB]] value regardless of whether the clip format is RGB or [[YUV]] based. Color presets can be found here: [[color presets]]. See [[Colors]] for more information on specifying colors.
:{{Par2|left, top, right, bottom|int|(required)}}
::Border width in pixels.
::For [[YUV]] sources, all values must be even (divisible by 2).  


Be aware that many lossy compression algorithms don't deal well with solid-color borders, unless the border width happens to be a multiple of the block size (16 pixels for MPEG).  
:{{Par2|color|int|(black)}}
::Border color; specified as an RGB value. See [[Colors|this page]] for more information on specifying colors.
::For YUV clips, colors are converted from full-range (0&ndash;255) to tv-range (16&ndash;235).


You can use this filter in combination with [[Crop]] to shift an image around without changing the frame size. For example:
==== Examples and Notes====
<div style="max-width:54em" >
* Add ''letterbox'' (top and bottom) borders:
<div {{BoxWidthIndent|36|2}} >
## add dark blue borders, using [[Colors|hex color notation]]
AddBorders(0, 86, 0, 86, $00008B)
## same as above, using [[Preset_colors|named preset color]]
AddBorders(0, 86, 0, 86, color_darkblue)
</div>


  # Shift a 352x240 image 2 pixels to the right
* Be aware that many older lossy compression algorithms don't deal well with solid-color borders, unless the border happens to fall on a [[Wikipedia:Macroblock|macroblock]] boundary (16 pixels for MPEG).
  Crop(0, 0, 350, 240)
 
* Use '''AddBorders''' in combination with [[Crop]] to ''shift'' an image without changing the frame size:
<div {{BoxWidthIndent|36|2}} >
  # Shift an image 2 pixels to the right
  Crop(0, 0, Width-2, Height)
  AddBorders(2, 0, 0, 0)
  AddBorders(2, 0, 0, 0)
</div>
: Note, shifting this way with YUV clips must be done in 2-pixel increments.
: You can shift in ''sub''-pixel increments with [[Resize#General_information|Resize]].
</div>


# Add letterbox borders that are Black making a 720x308 image 720x480
# For YUV colorspace it will be correct (for CCIR-601) color (luma=16)
AddBorders(0, 86, 0, 86, $000000)


[[Category:Internal filters]]
[[Category:Internal filters]]
[[Category:Borders_and_Cropping]]
[[Category:Borders_and_Cropping]]

Revision as of 06:34, 30 January 2016

Add black or colored borders, increasing frame size.

AddBorders( clip clip, int left, int top, int right, int bottom [, int color ] )

int  left, top, right, bottom = (required)
Border width in pixels.
For YUV sources, all values must be even (divisible by 2).
int  color = (black)
Border color; specified as an RGB value. See this page for more information on specifying colors.
For YUV clips, colors are converted from full-range (0–255) to tv-range (16–235).

Examples and Notes

  • Add letterbox (top and bottom) borders:
## add dark blue borders, using hex color notation
AddBorders(0, 86, 0, 86, $00008B) 

## same as above, using named preset color
AddBorders(0, 86, 0, 86, color_darkblue) 
  • Be aware that many older lossy compression algorithms don't deal well with solid-color borders, unless the border happens to fall on a macroblock boundary (16 pixels for MPEG).
  • Use AddBorders in combination with Crop to shift an image without changing the frame size:
# Shift an image 2 pixels to the right
Crop(0, 0, Width-2, Height)
AddBorders(2, 0, 0, 0)
Note, shifting this way with YUV clips must be done in 2-pixel increments.
You can shift in sub-pixel increments with Resize.