Avisynth BalanceBorders
BalanceBorders fixes dirty edge lines: dark, bright or discolored rows and columns along the frame edges.
Filtering → Avisynth → Frame → Edge

What it does
For each edge the chosen number of lines is blurred and matched to the first clean line next to it. The difference is added to the border, optionally limited by a threshold. An edge set to 0 is left alone. Crop letterbox bars first, fix the edges, and add borders back last.
Requirements
CPU only. Needs MaskTools2, which Hybrid ships.
Settings
| Control | Parameter | Range | Hybrid default | Meaning |
|---|---|---|---|---|
| BalanceBorders | – | on/off | off | Enables the filter. |
| Top / Bottom / Left / Right | cTop / cBottom / cLeft / cRight | 0–512 each (step 2) | 0 | Number of lines to correct on that edge. Values must be even; with an odd value Hybrid leaves the filter out and writes a note to the filter log. |
| Threshold | thresh | 1–128 | 128 | Largest amount a border pixel may be moved. 128 is effectively no limit; lower it when picture content gets dragged along. |
| Blur | blur | 1–999 | 999 | Blur width is max(4, width / blur). 1 matches detail by detail; 999 uses the narrowest width and carries only the average color across. |
Example
With all four borders at 0 (the default) the filter does nothing and Hybrid leaves it out of the script. Set at least one border, for example Top 2, to get a BalanceBorders line.
How Hybrid calls it
- Hybrid loads masktools2.dll, BalanceBorders.avsi and a helper script.
- The four border values are always written in the order top, bottom, left, right. Threshold and Blur are written only when they differ from the defaults.
- The script accepts 4:2:0, 4:4:4 and luma-only clips and needs progressive input. For other YUV formats (4:2:2, 4:1:1, YUY2) Hybrid converts the clip before the filter.
- BalanceBorders also offers the common options and can be added to the filter queue several times.
Background
BalanceBorders.avsi (version dated 2020) is based on the older BalanceBorders function and uses MaskTools2 for all calculations. It rotates the clip so that every edge is handled as a top edge. The usual call in forum posts is BalanceBorders(2,0,0,0,thresh=28). Copies of the script are in realfinder's AVS-Stuff on GitHub.
See also: Vapoursynth Balance Borders
Sources
- Doom9: BalanceBorders usage
- realfinder/AVS-Stuff
- Hybrid's tooltips
- The AviSynth+ documentation does not cover BalanceBorders.