» AviSynth is a powerful video FrameServer for Win32.

AviSynth Links:
»Learn to script
»Discussion fora
»Project page
»External filters

» You can add pages to this website immediately. No login required.
Edit this document

» AboutAviSynth




( Diese Seite in flag-germany.gif Deutsch )

Layer [YUY2][RGB32]

Layer(clip base_clip, clip overlay_clip, string op, int level, int x, int y, int threshold, bool use_chroma)

This filter can overlay two clips of different sizes (but with the same color format) using different operation modes.

For pixel-wise transparency information the 4th color channel of RGB32 (A- or alpha-channel) is used as a mask.

Base_clip: the underlying clip which determines the size and all other video and audio properties of the result.

Overlay_clip: the clip which is merged onto clip.

op: the performed merge operation, which can be: "add", "subtract", "lighten", "darken", "fast", "mul"

level: 0-255, the strength of the performed operation. 0: the base_clip is returned unchanged, 255: the maximal strength is used

x, y: offset position of the overlay_clip

threshold: only implemented for "lighten" and "darken"

use_chroma: use chroma of the overlay_clip, default=true. When false only luma is used.

There are some differences in the behaviour and the allowed parameter depending on the color format and the operation; here are the details:

  • There is no mask (alpha-channel) in YUY2, so the alpha-channel is assumed to be opaque everywhere.
  • in RGB32 the alpha-channel of the overlay_clip is multiplied with level, so the resulting alpha = (alpha_mask * level) / 256. This means for full strength of operation BOTH alpha and level have to be 255.

These operators behave equally for RGB32 or YUY2:

fast: use_chroma must be TRUE, level and threshold is not used. The result is simply the average of base_clip and overlay_clip.

add: threshold is not used. The difference between base_clip and overlay_clip is multiplied with alpha and added to the base_clip.

alpha=0 -> only base_clip visible,

alpha=128 -> base and overlay equally blended,

alpha=255 -> only overlay visible.

subtract: the same as add, but the overlay_clip is inverted before.

These operators seem to work correctly only in YUY2:

mul: threshold is not used. The base_clip is colored as overlay_clip, so use_chroma should be TRUE.

alpha=0 -> only base_clip visible,

alpha=255 -> approx. the same Luminance as Base but with the colors of Overlay

lighten: use_chroma must be TRUE. Performs the same operation as "add", but only when the result is BRIGHTER than the base the new values is used. With a higher threshold the operation is more likely, so with threshold=255 it's the same as "add", with threshold=0 the base_clip is more likely passed unchanged, depending on the difference between base_clip and overlay_clip.

darken: the same as "lighten", but it is performed only when the result is DARKER than the base.

The audio and framerate/framecount are taken from the first clip.


This can be used to combine to captures of different broadcasts for reducing noise. A discussion of this idea can be found [here]. A sample script (of course you have to ensure that the frames of the two clips match exactly -- use DeleteFrame if necessary):

clip1 = AviSource("F:\shakira-underneath_your_clothes.avi").ConvertToYUY2
clip2 = AviSource("F:\shakira-underneath_your_clothes2.avi").ConvertToYUY2
return Layer(clip1, clip2, "fast") 

Mask [RGB32]

Mask(clip clip, mask_clip clip)

Applies a defined alpha-mask to clip, for use with Layer, by converting mask_clip to greyscale and using that for the mask (the alpha-channel) of RGB32. In this channel "black" means completely transparent, white means completely opaque).

ResetMask [RGB32]

ResetMask(clip clip)

Applies an "all-opaque" alpha-mask to clip, for use with Layer. The alpha-channel of a RGB32-clip is not always well-defined (depending on the source), this filter is the faster way to apply an all white mask:

clip = ResetMask(clip)

ColorKeyMask [RGB32]

ColorKeyMask(clip clip, int color, int tolerance)

Sets the alpha-channel (similar as Mask does) but generates it by comparing the color. Each pixel with a color differing less than tolerance is set to transparent, otherwise it is left unchanged (it is NOT set to opaque).

All of this is kind of abstract. Here is an example that ShowsOffLayer.

SourceForge Logo


Edit this document | View document history
Document last modified Mon, 22 Nov 2004 18:35:51