Cropping and Borders

In some situations its useful to either remove or add lines on the edges of a frame. You might need to remove black borders that are in an image to give it appropriate dimensions for DVD authoring, or even from an actual image to avoid resizing. Likewise an image sometimes needs extra borders added to the edges to format it correctly, perhaps to reach mod16 resolution for MPEG encoding of some kind or to meet resolution requirements for DVD, HD DVD, or Blu-ray authoring.

In addition to any other requirements, you should always be aware of potential problems that could arise from cropping or adding borders. In particular, you should always know if your video's resolution is mod16 (divisible by 16), mod8 (divisible by 8), mod4 (divisibly by 4), or mod2 (divisible by 2). Although borders can be cropped one at a time, other filters, or even features of other programs, may require horizontal or vertical resolution (or both) divisible by 4, 8, or 16. You should always try to use at least a mod2 resolution.


Crop (clip, int left, int top, int width, int height)

Crop (clip, int left, int top, int -right, int -bottom, bool "align")

clipCliplast*The clip to crop
leftInteger*Number of lines to crop from left side of frame
topInteger*Number of lines to crop from top of frame
rightIntegerNumber of lines to crop from left side of frame
topIntegerNumber of lines to crop from bottom of frame
widthIntegerWidth, in pixels, of the new frame
heightIntegerHeight, in pixels, of the new frame

There are two different ways to specify which borders to crop with this filter. You can either explicitly state the number of lines to crop from each side, using negative values for the right and bottom edges. Alternatively you can supply the number of lines to crop from the right side and bottom, followed by the final dimensions. This instructs AviSynth to crop whatever number of lines it must to achieve the desired resolution. Although this method of cropping may remove lines that are part of the image, you'll know exactly what resolution the resulting image will be. By contrast, the standard method of specifying the number of pixels to crop on all sides makes it easier to ensure only pixels that make up the borders around the image are removed, but the final resolution will vary based on what decisions you make when cropping.

Example Code

Crop letterbox borders from a widescreen DVD:
Crop(0, 30, -0, -30)

Crop from 720x480 to 704x480:
Crop(8, 0, 704, 480)

When To Use It

Use crop to remove extra horizontal or vertical lines from your video.


AddBorders (clip, int left, int top, int right, int bottom, int "color") 

clipCliplastThe clip to add borders to
leftIntegerNumber of pixels to add to the left
topIntegerNumber of pixels to add to the top
rightIntegerNumber of pixels to add to the right
bottomIntegerNumber of pixels to add to the bottom
colorIntegerColor of the border lines. See description for more details

As the name suggests, AddBorders adds lines to one or more sides of an image. This can be useful when resizing, particularly from DVD to MPEG-4. Although the lines added by AddBorders are normally black, by using the color argument you can specify a color of your choice. Colors must always be entered as RGB values, ranging from 0 to 255. Use hexadecimal (base16) notation is the easiest way to do this, as in $FF0038 for Red = 255, Green = 0, and Blue = 56.

When adding borders it's important to remember that they may make your video harder to compress. When adding borders just to reach a particular resolution or Aspect Ratio it's good to add them only to a single side, rather than dividing them between opposite sides. This will generally give your video encoder the fewest problems.

Example Code

Add 16 pixel black borders to the top and bottom:
AddBorders(0, 16, 0, 16)

Add 8 pixel wide red borders to the left and right:
AddBorders(8, 0, 8, 0, color = $FF0000)

When To Use It

When you need to add just a few pixels to the edges of the frame it's usually best to use this filter rather than a resize filter. It's also useful to pad a clip's frame size so it can be encoded. In combination with the Crop filter it can even be used to shift the image from one side to the other by cropping the border from one sideand then adding it to the other.
previous  | next
Written by: Rich Fiscus