From Avisynth wiki
Jump to: navigation, search
Author tp7
Version v1.2
Download //
Category Masking
License GPLv2



TColorMask This is a port of the great tophf's script t_colormask. It masks colors but unlike the old ColorKeyMask it works on YV12. The main reason for this plugin is performance. The API and output are not identical, please refer to the Difference section for details.


Syntax and Parameters

tcolormask (clip, string "colors, int "tolerance", bool "bt601", bool "gray", int "lutthr", bool "mt")

clip   =
Input clip.

string  colors = ""
String of colors. Line and block comments are allowed.

int  tolerance = 10
Pixel value will pass if its absolute difference with color is less than tolerance (luma) or half the tolerance (chroma).

bool  bt601 = false
Use bt601 matrix for conversion of colors.

bool  gray = false
Set chroma of output clip to 128.

int  lutthr = 9
If specified more than lutthr colors, LUT will be used instead of direct SIMD computations.

bool  mt = true
Enable multithreading. It actually uses only two threads as any more threading doesn't seem to be useful.


Unlike the old script, this plugin uses a single string to specify all colors and doesn't do any blurring. Wrapper functions are provided for convenience in the bin/tcolormask_wrappers.avs script.

Also since we process chroma and luma together to avoid having to merge planes later, output is not identical. Basically it appears a bit less blurred and doesn't contain any non-binary values produced by chroma resizing. This will not be fixed and there's no workaround. You'll most likely be blurring the output clip anyway.


This plugin uses direct SIMD computations to do its dirty work. SIMD appears to be faster than LUT for the most common cases, but unfortunately its speed depends on the number of specified colors and at some point it does get slower than LUT. That's why the alternative is also provided. If specified more than lutthr (9 by default) colors, the plugin will use the LUT routine to avoid performance degradation.

See performance table on GitHub.


tcolormask with default values, except colors:

tcolormask("$E0C0AB", tolerance=10, bt601=false, gray=false, lutthr=9, mt=true)


Version      Date            Changes
v1.2 2013/11/30 - x64 build added. - Function from tcolormask_wrappers will not work with x64 build of AviSynth+. v1.1 2013/07/26 - This plugin now only works with AviSynth 2.6 alpha 4. If you need support for older versions, download v1.0.1. - Also, YV16 colorspace is now supported. v1.0 2013/07/08 - Actually working now.

External Links

  • GitHub - Source code repository.

Back to External Filters

Personal tools