fmtconv — format conversion tools for Vapoursynth and Avisynth+

Abstract

Authors:  Firesledge (aka Cretindesalpes)
Version:  r30
Download:  http://ldesoras.free.fr/prod.html
Category:  Format tools
Requirements: Vapoursynth r55 or Avisynth+ 3.7.0
License:  WTFPL

Table of contents

  1. Introduction
  2. Usage
    1. Loading
    2. Examples for Vapoursynth
    3. Examples for Avisynth+
    4. Compiling from the source code
  3. Filter description
    1. bitdepth
    2. convert
    3. matrix
    4. matrix2020cl
    5. primaries
    6. resample
    7. transfer
    8. stack16tonative, nativetostack16
  4. Troubleshooting
  5. Changelog

I) Introduction

Fmtconv is a format-conversion plug-in for the Vapoursynth and Avisynth+ video processing engines. It does:

It supports:

Fmtconv is focussed primarily on quality and exactness rather than execution speed. This does not mean it is slow or unoptimized, but fmtconv is clearly not on par with the fastest equivalent 8-bit filters.

II) Usage

Loading fmtconv

Using the Python 3.8 interface (or a higher version, it depends on your Vapoursynth version):

import vapoursynth as vs
core = vs.core
core.std.LoadPlugin (path=r'C:\path\fmtconv.dll')

Of course you can avoid the LoadPlugin command by copying the plug-in file to the autoloading directory. Check the Vapoursynth manual for more information.

Examples for Vapoursynth

A basic example

Requires FFmpegSource2:

# Load Vapoursynth
import vapoursynth as vs
core = vs.core

# Load the plug-ins
core.std.LoadPlugin (path=r'C:\path\fmtconv.dll')
core.std.LoadPlugin (path=r'C:\path\ffms2.dll')

# Load the video clip into c using FFmpegSource
c = core.ffms2.Source (source=r'C:\path\video.mkv')

# Change the resolution. The output clip is now in 16 bits.
c = c.fmtc.resample (w=1280, h=720)

# Dither the result, back to 8 bits
c = c.fmtc.bitdepth (bits=8)

# Send the processed clip to the calling process
c.set_output ()

Resizing and chroma subsampling conversions

Simple resize with 16- or 32-bit output:

c = c.fmtc.resample (w=1280, h=720)

Bobbing an interlaced stream (here, Top Field First):

c = c.std.SeparateFields (tff=True)
c = c.fmtc.resample (scalev=2, kernel="cubic", interlaced=1, interlacedd=0)

Converting a progressive stream from YUV 4:2:2 to 4:2:0 and back to 8 bits:

c = c.fmtc.resample (css="420")
c = c.fmtc.bitdepth (bits=8)

Same as above, with interlaced content:

tff = True
c = c.std.SeparateFields (tff=tff)
c = c.fmtc.resample (css="420", interlaced=1)
c = c.fmtc.bitdepth (bits=8)
c = c.std.DoubleWeave (tff=tff)
c = c.std.SelectEvery (cycle=2, offsets=0)

Colorspace conversions

Y’Cb’Cr’ 4:2:0 to R’G’B’:

c = c.fmtc.resample (css="444")
c = c.fmtc.matrix (mat="601", col_fam=vs.RGB)
c = c.fmtc.bitdepth (bits=8)

R’G’B’ to Y’Cb’Cr’ 4:2:0:

c = c.fmtc.matrix (mat="601", col_fam=vs.YUV, bits=16)
c = c.fmtc.resample (css="420")
c = c.fmtc.bitdepth (bits=8)

Y’Cb’Cr colormatrix conversion from BT. 601 to BT. 709. For example to insert a PAL DVD content into an HDTV stream. Note that we need to convert the clip to 4:4:4 in an intermediate step because matrix can only process 4:4:4.

c = c.fmtc.resample (css="444")
c = c.fmtc.matrix (mats="601", matd="709")
c = c.fmtc.resample (css="420")
c = c.fmtc.bitdepth (bits=8)

Same as above, but with a 525-line content, requiring a gamut conversion. We have to insert an intermediate step in linear RGB. For this, we use the BT. 1886 transfer curve in both directions:

c = c.fmtc.resample (css="444")
c = c.fmtc.matrix (mats="601")
c = c.fmtc.transfer (transs="1886", transd="linear")
c = c.fmtc.primaries (prims="601-525", primd="709")
c = c.fmtc.transfer (transs="linear", transd="1886")
c = c.fmtc.matrix (mat="709")
c = c.fmtc.resample (css="420")
c = c.fmtc.bitdepth (bits=8)

Conversion from full range to TV-range:

c = c.fmtc.bitdepth (fulls=True, fulld=False)

Displaying an anamorphic 1440x1080 HDTV content on a standard computer display:

c = c.fmtc.resample (w=1920, h=1080, css="444")
c = c.fmtc.matrix (mat="709", col_fam=vs.RGB)
c = c.fmtc.transfer (transs="1886", transd="srgb")
c = c.fmtc.bitdepth (bits=8)

Displaying a UHDTV HDR content encoded with BT.2100 ICTCP-PQ on a standard computer display. Conversion to sRGB (SDR) is done by reducing the contrast from an arbitrary factor and clipping the pixel values at the end. Obviously this is a poor solution, a tone mapping algorithm would be more suited for this task. With PQ, the linear values go way above 1.0 which is 203 cd/m2 for the reference white, so even if we reduce the contrast, we convert data to float to prevent information loss during the subsequent color conversion steps (this is optional):

c = c.fmtc.resample (css="444") # -> I'Ct'Cp' 4:4:4
c = c.fmtc.matrix (mats="ICtCp_PQ", matd="rgb") # -> L'M'S'
c = c.fmtc.transfer (transs="2084", transd="linear", cont=0.2, flt=True) # -> LMS
c = c.fmtc.matrix (mats="lms", matd="rgb") # -> RGB
c = c.fmtc.primaries (prims="2100", primd="srgb")
c = c.fmtc.transfer (transs="linear", transd="srgb")
c = c.fmtc.bitdepth (bits=8)

Examples for Avisynth+

Soon…

Compiling from the source code

Visual C++

Visual Studio 2019 or later is required, previous versions are not supported anymore. Just load build/win/fmtconv.sln and run the compiler.

You can also import all the *.cpp, *.h and *.hpp files located in the src directory and its subfolders. Then:

GNU/Linux and other Unix-like systems

On Linux and similar GNU-based systems (including MSYS2 and Cygwin), the build directory contains autotools settings:

cd build/unix
./autogen.sh
./configure
make
make install

You can add some options to the configure command:

Only the Vapoursynth plug-in can be built in the GNU-based environment.

III) Filters description

bitdepth

VapoursynthAvisynth+
fmtc.bitdepth (
	clip       : vnode     ;
	csp        : int  : opt;
	bits       : int  : opt;
	flt        : int  : opt;
	planes     : int[]: opt; (all)
	fulls      : int  : opt; (depends)
	fulld      : int  : opt; (fulls)
	dmode      : int  : opt; (3)
	ampo       : float: opt; (1)
	ampn       : float: opt; (0)
	dyn        : int  : opt; (False)
	staticnoise: int  : opt; (False)
	cpuopt     : int  : opt; (-1)
	patsize    : int  : opt; (32)
	tpdfo      : int  : opt; (0)
	tpdfn      : int  : opt; (0)
	corplane   : int  : opt; (0)
)
fmtc_bitdepth (
	clip   c,

	int    bits (-1),
	bool   flt (undefined),
	string planes ("all"),
	bool   fulls (depends),
	bool   fulld (fulls),
	int    dmode (3),
	float  ampo (1),
	float  ampn (0),
	bool   dyn (false),
	bool   staticnoise (false),
	int    cpuopt (-1),
	int    patsize (32),
	bool   tpdfo (false),
	bool   tpdfn (false),
	bool   corplane (false)
)

Bitdepth conversion with optional dithering.

Dithering is performed when meeting at least one of these conditions:

Video compression seems to retrain better pure ordered (Bayer) dithering. Therefore this is the recommended method to avoid color banding in 8 bit signals, unless you encode at high bitrates. If you don’t care about video compression, error diffusion, void and cluster and quasirandom sequence methods give the most accurate results. To avoid discontinuities between purely flat areas and dithered areas (also called noise modulation), you can add a bit of noise, ideally in triangular distribution.

The internal noise generator is deterministic and will give the same result each run.

The internal processing is done in floating point as soon as the input is floating point or a range conversion is detected.

The _ColorRange frame property is set if at least one of the fulls or fulld parameter has been explicitely defined.

Parameters

clip

The input clip. Mandatory. Supported input formats:

csp

Vapoursynth The destination format, as a Vapoursynth constant. Can only change the bitdepth and the data type (integer or float). Supported destination colorspaces are the same as for the input clip.

bits

Destination bitdepth. It’s sometimes more convenient to provide only the number of bits rather than the full format. When there is no ambiguity between bitdepth and data type, the data type is automatically selected depending on the bitdepth. For example, specifying 32 bits is enough to switch the output to float.

Avisynth+ A negative value means that the parameter is left undefined.

flt

Set it to 1 to convert to float, and to 0 for integer data. As long as only 32-bit floating point data is supported, you don’t need to specify the bitdepth for a float conversion.

planes

A list of planes to process. The content of an unprocessed plane should be considered as garbage.

Vapoursynth Planes as index (0 to 2), in any order.

Avisynth+ This is a string made of concatenated substrings for each plane, in any order. The planes are identified by their index, as well as the following aliases:

"0", "y", "r"Y or red
"1", "u", "g"U or green
"2", "v", "b"V or blue
"3", "a"Alpha channel
"all"All the planes

fulls, fulld

Indicates if the clip is full-range (True) or TV-range (False). fulls is for input, fulld for output. Reference black and white have different values depending on the range. In 8 bits, pixel values scale from 0 to 255 in full range, and 16 to 235 in TV-range (16 to 240 for the YUV chroma planes). This value has no meaning for float data.

The default value depends on the colorspace. For example, full-range is assumed for RGB and YCoCg colorspaces. Others are assumed TV-range. These parameters are mainly intended to guide conversions between integer and floating-point data. They can also be used for range conversions. Pixel values are not clipped during a conversion between two TV-range formats.

Avisynth+ Alpha planes are always processed as full-range.

dmode

Dithering mode, when applicable.

0Ordered dithering (Bayer matrix).
1No dither, round to the closest value.
2Round, may be a bit faster but possibly less accurate.
3Sierra-2-4A error diffusion, aka “Filter Lite”. Quick and excellent quality, similar to Floyd-Steinberg.
4Stucki error diffusion. Preserves delicate edges better but distorts gradients.
5Atkinson error diffusion. Generates distinct patterns but keeps clean the flat areas (noise modulation).
6Classic Floyd-Steinberg error diffusion, modified for serpentine scan (avoids worm artefacts).
7Ostromoukhov error diffusion. Slow, available only for integer input at the moment. Avoids usual F-S artefacts.
8Void and cluster halftone dithering. This is a way to generate blue-noise dither and has a much better visual aspect than ordered dithering.
9Dither using quasirandom sequences. Good intermediated between Void and cluster and error diffusion algorithms.

When using error-diffusion dithering on interlaced content, you should separate the fields first before converting them.

ampo

The ordered dither peak-to-peak amplitude, depends on the target bitdepth. ≥ 0. On error diffusion algorithms, it increases the collected error amount, helping to extend the range of the dithering while preserving its natural pattern (especially Atkinson’s). This gives a better looking result than just adding noise.

ampn

The noise peak-to-peak amplitude, depends on the target bitdepth. ≥ 0. Currently, the maximum value is 4. The noise is added before dithering. It reduces the SNR but a small amount may give a better, more uniform visual appearance.

dyn

Indicates if the ordered dither pattern is dynamic (True) or static (False). If dynamic, the pattern is changed or rotated each frame.

staticnoise

If set to 1, the noise generated with ampn is static and remains the same every frame.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings), 1: limit to SSE2, 10: limit to AVX2.

patsize

Width of the pattern used in the Void and cluster algorithm. The only valid values are power of 2 ranging from 4 to 1024: 4, 8, 16, 32, 64, 128, 256, 512 and 1024.

tpdfo

Set it to 1 to enable the triangular probability distribution function (TPDF) for halftone-based dithering algorithms. It has no effect on error diffusion methods. 0 is the standard rectangular distribution (RPDF). Note that when triangular distribution is enabled, the maximum halftone amplitude is multiplied by 1.414 at constant ampo.

tpdfn

Same as tpdfo, but for the additive noise part. TPDF noise looks more natural than RPDF noise, and is a crude approximation of a gaussian noise, with a bounded amplitude. Maximum noise amplitude is multiplied by 1.414 at constant ampn, so the introduced noise power is kept approximately constant.

corplane

Set it to 1 to keep the dither and noise patterns correlated for all the planes. When processing a RGB picture, it helps to prevent colored noise on grey features.

convert

fmtc.convert (
	# Input
	clip       : vnode       ;

	# Resizing/resampling
	w          : int    : opt;
	h          : int    : opt;
	sx         : float[]: opt; (0)
	sy         : float[]: opt; (0)
	sw         : float[]: opt; (0)
	sh         : float[]: opt; (0)
	scale      : float  : opt; (0)
	scaleh     : float  : opt; (0)
	scalev     : float  : opt; (0)
	kernel     : data[] : opt; ("spline36")
	kernelh    : data[] : opt; (kernel)
	kernelv    : data[] : opt; (kernel)
	impulse    : float[]: opt;
	impulseh   : float[]: opt; (impulse)
	impulsev   : float[]: opt; (impulse)
	taps       : int[]  : opt; (4)
	tapsh      : int[]  : opt; (taps)
	tapsh      : int[]  : opt; (taps)
	a1         : float[]: opt;
	a2         : float[]: opt;
	a3         : float[]: opt;
	kovrspl    : int[]  : opt; (1)
	fh         : float[]: opt; (1)
	fv         : float[]: opt; (1)
	cnorm      : int[]  : opt; (True)
	totalh     : float[]: opt; (0)
	totalv     : float[]: opt; (0)
	invks      : int[]  : opt; (False)
	invksh     : int[]  : opt; (invks)
	invksv     : int[]  : opt; (invks)
	invkstaps  : int[]  : opt; (4)
	invkstapsh : int[]  : opt; (invkstaps)
	invkstapsv : int[]  : opt; (invkstaps)
	center     : int[]  : opt; (True)

	# Output clip format
	csp        : int    : opt;
	css        : data   : opt;
	col_fam    : int    : opt;
	bits       : int    : opt;
	flt        : int    : opt;

	# Output dithering
	dmode      : int    : opt; (3)
	ampo       : float  : opt; (1)
	ampn       : float  : opt; (0)
	dyn        : int    : opt; (False)
	staticnoise: int    : opt; (False)

	# Common sub-format spec
	cplace     : data   : opt; ("mpeg2")
	mat        : data   : opt;
	coef       : float[]: opt;
	interlaced : int    : opt; (2)
	tff        : int    : opt; (2)
	useflt     : int    : opt; (False)

	# Input clip sub-format spec
	fulls      : int    : opt; (depends on the colorspace)
	cplaces    : data   : opt; (cplace)
	mats       : data   : opt;

	# Output clip sub-format spec
	fulld      : int    : opt; (fulls)
	cplaced    : data   : opt; (cplace)
	matd       : data   : opt;

	# Transfer curve parameters
	transs     : data[] : opt;
	transd     : data[] : opt;
	cont       : float  : opt;
	gcor       : float  : opt;

	cpuopt     : int    : opt; (-1)
)

Multi-purpose conversion function.

Not available yet.

matrix

fmtc.matrix (
	clip     : vnode       ;
	mat      : data   : opt;
	mats     : data   : opt;
	matd     : data   : opt;
	fulls    : int    : opt; (depends)
	fulld    : int    : opt; (depends)
	coef     : float[]: opt;
	csp      : int    : opt;
	col_fam  : int    : opt;
	bits     : int    : opt;
	singleout: int    : opt; (-1)
	cpuopt   : int    : opt; (-1)
)
fmtc_matrix (
	clip   c,
	string mat (undefined),
	string mats (undefined),
	string matd (undefined),
	bool   fulls (depends),
	bool   fulld (depends),
	arrayf coef (undefined),
	string csp (undefined),
	string col_fam (undefined),
	int    bits (undefined),
	int    singleout (-1),
	int    cpuopt (-1)
)

Colorspace conversion or simple cross-plane matrix.

For Y’Cb’Cr’ and Y’Co’Cg’ colorspaces, 4:4:4 is required (no chroma subsampling). To process a subsampled colorspace, you must convert it to 4:4:4 first.

The output is not dithered, therefore you should output at a higher bitdepth than the input and dither afterward with bitdepth to avoid potential banding.

When the destination color family (R’G’B’, Y’Cb’Cr’ or Y’Co’Cg’) is not specified (via col_fam or csp), the function tries to deduce it from the matrix settings and the source color family. If it cannot be deduced, the color family remains unchanged.

Please note that this function doesn’t do conversions based on the color primaries. The R’G’B’ data are always releative to their specified standard. For example, converting Y’Cb’Cr’ data straight from BT.2020 to BT.709 doesn’t make sense as these colorspaces are defined with different primaries. For meaningful results, convert to R’G’B’ then to linear RGB and use primaries to perform the intermediary conversion.

The _ColorRange frame property is set if the fulld parameter has been explicitely defined or if a preset is used. If the destination colorspace is a standardized one (as deduced from the specified matrix), the _Matrix and _ColorSpace properties are set, otherwise they are deleted from the frame.

Avisynth+If an alpha channel is present in both the source and destination colorspaces, it is copied and its bitdepth is possibly adapted to the destination format. If there is no alpha channel in the source, full opacity is assumed. If there is no alpha channel in the destination, the plane is lost.

Parameters

clip

The input clip. Mandatory. Supported input formats:

Vapoursynth 9-bit integer data is supported too.

Avisynth+ Colorspaces with an alpha channel are supported too.

mat

Predefined matrix for conversions to and from R’G’B’. The direction is deduced from the specified input and output colorspaces. Possible values are:

"601"ITU-R BT.601 / ITU-R BT.470-2 / SMPTE 170M. For Standard Definition content.
"709"ITU-R BT.709. For High Definition content.
"2020"
"2100"
ITU-R BT.2020 and ITU-R BT.2100, non constant luminance mode. For UHDTV content.
"240"SMPTE 240M
"FCC"
"470-525"
FCC Title 47
"YCoCg"
"YCgCo"
Y’Co’Cg’
"YDzDx"Y’D’ZD’X, SMPTE ST 2085
"RGB"R’G’B’. Identity, no cross-plane calculations.

mats, matd

Source and destinations matrices for YUV. Use both when you want to do a conversion between BT.601 and BT.709. Values are the same as mat, with the addition of:

"LMS"Intermediate colorspace for ICTCP transforms. The LMS colorspace is conveyed on RGB planes.
"ICtCp_PQ"ITU-R BT.2100-2 ICTCP with perceptual quantization (PQ).
"ICtCp_HLG"ITU-R BT.2100-2 ICTCP with hybrid log-gamma transfer function (HLG).

When using one of these additional values, make sure to set the other mats or matd with "rgb" to clarify the conversion direction. ICTCP transforms from R’G’B’ require the following steps:

For the inverse conversion, reverse the steps. Beware, chromatic information for pixels of the highest luminance range cannot be represented in integer ICTCP and will be clipped because of the large matrix coefficients.

fulls, fulld

Indicates if the clip is full-range (True) or TV-range (False). fulls is for input, fulld for output. Reference black and white have different values depending on the range. In 8 bits, pixel values scale from 0 to 255 in full range, and 16 to 235 in TV-range (16 to 240 for the YUV chroma planes). This value has no meaning for float data.

The default value depends on the colorspace. For example, full-range is assumed for R’G’B’ and Y’Co’Cg’ colorspaces. Others are assumed TV-range. These parameters are mainly intended to guide conversions between integer and floating-point data. They can also be used for range conversions. Pixel values are not clipped during a conversion between two TV-range formats.

coef

A list of 12 coefficients for a custom matrix. The coefficients should be scaled assuming the input is floating point, even if the actual input is integer. This means luma and R’G’B’ signals range from 0 to 1, and chroma signals from −0.5 to +0.5. Coefficients are listed by rows. Each row is terminated with a fourth coefficient, the additive constant (still in floating-point range). This means the matrix is actually 4×3 and during the multiplication, the input column-vector has an implicit 1 appended to its end. For example, with an R’G’B’ input:

Y
Cb
Cr
=
c0 c1 c2 c3
c4 c5 c6 c7
c8 c9 c10 c11
×
R
G
B
1
Y = R × c0 + G × c1 + B × c2 + c3 
Cb = R × c4 + G × c5 + B × c6 + c7 
Cr = R × c8 + G × c9 + B × c10 + c11 

Vapoursynth List is a regular array.

Avisynth+ List can be an array of float values if supported by the scripting language, or a string containing the values printed and separated with spaces.

csp

The destination format. It cannot change the data type (integer or float) nor the chroma subsampling. If the colorspace family is set to GRAY (or Y), single-plane processing is enabled. The output plane is selected with singleout (0 if not specified). Only planar colorspaces are allowed.

Vapoursynth The format is a Vapoursynth built-in constant.

Avisynth+ The format is a string with the same kind of content as the result from BuildPixelType or the pixel_type parameter from BlankClip. For example: "RGBP48", "YV12", "YUV444PS"

col_fam

Explicit specification of the destination color family, as Vapoursynth constant. Supersedes the color family from csp. You can only specify colorspace with the same number of planes as the input clip.

bits

Explicit specification of the destination bitdepth. The only allowed values are 8, 10, 12, 14, 16 and 32. However you cannot reduce the bitdepth, only keep it constant or increase it. Supersedes the bitdepth from csp.

Vapoursynth 9 bits is allowed too.

singleout

Enable single-plane processing. This is useful to obtain only the luma from an R’G’B’ input, for example. The parameter is the plane index, ranging from 0 to 2. A negative value specifies that all planes should be processed. If singleout is ≥ 0, it supersedes the colorspace family specified in csp.

Note: when extracting a chroma plane, results between int with TV range and float data type may slightly differ. This is because in float, a neutral chroma (0%) is converted to the exact value of a medium gray (50%). In integer, the chroma output value is mapped 1–1 to the luma channel. However in TV-range, medium gray is not located exactly at the half of the data range, it lies slightly below.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings), 1: limit to SSE2, 7: limit to AVX, 10: limit to AVX2.

matrix2020cl

fmtc.matrix2020cl (
	clip    : vnode     ;
	full    : int  : opt; (False)
	csp     : int  : opt;
	bits    : int  : opt;
	cpuopt  : int  : opt; (-1)
)
fmtc_matrix2020cl (
	clip   c,
	bool   full (false),
	string csp (undefined),
	int    bits (undefined),
	int    cpuopt (-1)
)

Colorspace conversion using the ITU-R BT.2020 constant luminance matrix.

The function converts between linear RGB and Y’Cb’Cr’ colorspaces. This conversion cannot be achieve with a classic linear matrix. The output colorspace, hence the direction of the conversion, is automatically deduced from the input colorspace.

For Y’Cb’Cr’ colorspaces, 4:4:4 is required (no chroma subsampling). To process a subsampled colorspace, you must convert it to 4:4:4 first.

The RGB colorspace is always 16 bits when using integers, or 32 bits in float. The output is not dithered, therefore you should output at a higher bitdepth than the input and dither afterward with bitdepth to avoid potential banding.

Please note that the RGB content is always assumed to be linear light. The BT.2020 gamma curve is used in both directions. When operating on floating point data, the function uses the 12-bit variant of the scaling coefficients.

The _Matrix, _ColorSpace and _Transfer frame properties are set according to the transformation. The _ColorRange property is set if the full parameter has been explicitely defined.

Avisynth+If an alpha channel is present in both the source and destination colorspaces, it is copied and its bitdepth is possibly adapted to the destination format. If there is no alpha channel in the source, full opacity is assumed. If there is no alpha channel in the destination, the plane is lost.

Parameters

clip

The input clip. Mandatory. Supported input formats:

Vapoursynth 9-bit integer data is supported too.

Avisynth+ Colorspaces with an alpha channel are supported too.

full

Indicates if the Y’Cb’Cr’ clip is full-range (True) or TV-range (False). Reference black and white have different values depending on the range. In 8 bits, pixel values scale from 0 to 255 in full range, and 16 to 235 in TV-range (16 to 240 for the YUV chroma planes). This value has no meaning for float data.

csp

It must be compatible with what is logically expected as output (RGB or YUV). It cannot change the data type (integer or float) nor the chroma subsampling. If the output is integer RGB, the bitdepth must be 16. Only planar colorspaces are allowed.

Vapoursynth The format is a Vapoursynth built-in constant.

Avisynth+ The format is a string with the same kind of content as the result from BuildPixelType or the pixel_type parameter from BlankClip. For example: "RGBP48", "YV12", "YUV444PS"

bits

Explicit specification of the destination bitdepth. The only allowed values are 8, 10, 12, 14, 16 and 32. They are restricted by the output data type and format (16 bits for integer RGB). Supersedes the bitdepth from csp.

Vapoursynth 9 bits is allowed too.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings).

primaries

fmtc.primaries (
	clip  : vnode       ;
	rs    : float[]: opt;
	gs    : float[]: opt;
	bs    : float[]: opt;
	ws    : float[]: opt;
	rd    : float[]: opt;
	gd    : float[]: opt;
	bd    : float[]: opt;
	wd    : float[]: opt;
	prims : data   : opt;
	primd : data   : opt;
	wconv : int    : opt; (False)
	cpuopt: int    : opt; (-1)
)
fmtc_primaries (
	clip   c,
	arrayf rs (undefined),
	arrayf gs (undefined),
	arrayf bs (undefined),
	arrayf ws (undefined),
	arrayf rd (undefined),
	arrayf gd (undefined),
	arrayf bd (undefined),
	arrayf wd (undefined),
	string prims (undefined),
	string primd (undefined),
	bool   wconv (False),
	int    cpuopt (-1)
)

Performs a gamut conversion given a set of three primary colors and a reference white to another set of primary colors and a target reference white. Illuminant conversions are done using the Bradford method.

Pixel values are left intact after the transform, they are not bound to the target gamut and could be invalid colors. However, when using 16-bit unsigned integer they are clipped to representable data values.

All colors are given in xyY colorspace, with their x and y coordinates.

You must supply the full description of the original and target gamuts, with the built-in presets or by setting individual components.

Please note that this function does not work at the same level as matrix. The latter converts between gamma-compressed RGB and YUV-like colorspaces, while primaries operates on linear RGB colorspaces exclusively, whose specifications are given by the primaries. For more details, see Charles Poynton, A Guided Tour of Color Space, 1997.

The _Primaries frame property is set or deleted, depending on the target gamut.

Parameters

clip

The input clip. Mandatory. Supported colorspaces are 16-bit int or 32-bit float linear RGB. You should use the transfer function to convert between linear RGB and gamma-compressed R’G’B ’colorspaces.

rs, gs, bs, ws

Primaries for the source colorspace as red, green, blue and reference white. Each variable contains two components, x and y, in this order. The y value cannot be null.

Vapoursynth Parameters are regular arrays.

Avisynth+ Parameters can be arrays of two float values if supported by the scripting language, or strings containing both values printed and separated with a space.

rd, gd, bd, wd

Primaries for the target colorspace. If not specified, the value is copied from the source colorspace.

prims, primd

Primaries presets for the source and destination colorspaces. Superseded by individual r, g, b and w settings. Possible values are:

ValuePrimaryxyDescription
"709" or
"1361" or
"61966-2-1" or
"61966-2-4" or
"hdtv" or
"srgb"
R
G
B
W (D65)
0.640,
0.300,
0.150,
0.3127,
0.330
0.600
0.060
0.3290
ITU-R BT.709-5
ITU-R BT.1361
IEC 61966-2-1 (sRGB or sYCC)
IEC 61966-2-4
Annex B of SMPTE RP 177 (1993)
"470m" or
"ntsc"
R
G
B
W (C)
0.670,
0.210,
0.140,
0.3100,
0.330
0.710
0.080
0.3160
ITU-R BT.470-6 System M (historical)
NTSC (1953)
FCC
"470m93" or
"ntscj"
R
G
B
W (9305K)
0.670,
0.210,
0.140,
0.2848,
0.330
0.710
0.080
0.2932
ITU-R BT.470-6 System M — Japan (NTSC-J)
"470bg" or
"601-625" or
"1358-625" or
"1700-625" or
"pal" or
"secam"
R
G
B
W (D65)
0.640,
0.290,
0.150,
0.3127,
0.330
0.600
0.060
0.3290
ITU-R BT.470-6 System B, G (historical)
ITU-R BT.601-6 625
ITU-R BT.1358 625
ITU-R BT.1700 625 PAL and 625 SECAM
"170m" or
"240m" or
"601-525" or
"1358-525" or
"1700-525"
R
G
B
W (D65)
0.630,
0.310,
0.155,
0.3127
0.340
0.595
0.070
0.3290
SMPTE 170M (2004)
SMPTE 240M (1999)
ITU-R BT.601-6 525
ITU-R BT.1358 525
ITU-R BT.1700 NTSC
"filmc"R (Wratten 25)
G (Wratten 58)
B (Wratten 47)
W (C)
0.681,
0.243,
0.145,
0.3100,
0.319
0.692
0.049
0.3160
Generic film (colour filters using Illuminant C)
"2020" or
"2100" or
"uhdtv"
R
G
B
W (D65)
0.70792,
0.17024,
0.13137,
0.31271
0.29203
0.79652
0.04588
0.32902
ITU-R BT.2020
ITU-R BT.2100
"61966-2-2" or
"scrgb"
R
G
B
W (D65)
0.640,
0.300,
0.150,
0.31271
0.330
0.600
0.060
0.32902
IEC 61966-2-2 (scRGB)
"adobe98"R
G
B
W (D65)
0.640,
0.210,
0.150,
0.31271
0.330
0.710
0.060
0.32902
Adobe RGB (1998)
"adobewide"R
G
B
W (D50)
0.73469,
0.11416,
0.15664,
0.34567
0.26531
0.82621
0.01770
0.35850
Adobe Wide Gamut RGB
"apple"R
G
B
W (D65)
0.625,
0.280,
0.155,
0.31271
0.265
0.826
0.018
0.32902
Apple RGB
"photopro" or
"romm"
R
G
B
W (D50)
0.7347,
0.1596,
0.0366,
0.34567
0.2653
0.8404
0.0001
0.35850
PhotoPro
ROMM
"ciergb"R
G
B
W (E)
0.7347,
0.2738,
0.1666,
1 / 3
0.2653
0.7174
0.0089
1 / 3
CIE RGB (1931)
"ciexyz"R
G
B
W (E)
1.0,
0.0,
0.0,
1 / 3
0.0
1.0
0.0
1 / 3
CIE XYZ (1931)
"p3dci"R
G
B
W
0.680,
0.265,
0.150,
0.314
0.320
0.690
0.060
0.351
SMPTE ST 2113 P3-DCI
SMPTE RP 431-2
"p3d65"R
G
B
W (D65)
0.680,
0.265,
0.150,
0.3127
0.320
0.690
0.060
0.3290
SMPTE ST 2113 P3-D65
SMPTE EG 432-1
Apple Display P3
"p3d60"R
G
B
W (D60)
0.680,
0.265,
0.150,
0.32168
0.320
0.690
0.060
0.33767
ACES P3-D60
"p3p"R
G
B
W
0.740,
0.220,
0.090,
0.314,
0.270
0.780
−0.090
0.351
DCI P3+
"cinegam"R
G
B
W (D65)
0.740,
0.170,
0.080,
0.3127,
0.270
1.140
−0.100
0.329
Cinema Gamut
"3213"R
G
B
W (D65)
0.630,
0.295,
0.155,
0.3127
0.340
0.605
0.077
0.3290
EBU Tech. 3213-E
"aces"R
G
B
W (D60)
0.7347,
0.0,
0.0001,
0.32168,
0.2653
1.0
-0.077
0.33767
ACES
SMPTE ST 2065-1
"ap1"
"acescc"
"acescct"
R
G
B
W (D60)
0.713,
0.165,
0.128,
0.32168,
0.293
0.830
-0.044
0.33767
ACESproxy AP1
ACEScc
ACEScct
"sgamut" or
"sgamut3"
R
G
B
W (D65)
0.730,
0.140,
0.100,
0.3127
0.280
0.855
-0.050
0.3290
Sony S-Gamut
Sony S-Gamut3
"sgamut3cine"R
G
B
W (D65)
0.766,
0.225,
0.089,
0.3127
0.275
0.800
-0.087
0.3290
Sony S-Gamut3.Cine
"alexa"R
G
B
W (D65)
0.6840,
0.2210,
0.0861,
0.3127
0.3130
0.8480
-0.1020
0.3290
Arri ALEXA
"vgamut"R
G
B
W (D65)
0.730,
0.165,
0.100,
0.3127
0.280
0.840
-0.03
0.3290
Panasonic V-Gamut
"p22"R
G
B
W (D93)
0.625,
0.280,
0.155,
0.28315
0.340
0.595
0.070
0.29711
Sony P22
"fs"R
G
B
W (D65)
0.7347,
0.140,
0.100,
0.31272
0.2653
0.860
−0.02985
0.32903
Free Scale-gamut
"davinci"R
G
B
W (D65)
0.8000,
0.1682,
0.0790,
0.3127
0.3130
0.9877
−0.1155
0.3290
DaVinci wide gamut
"dragon"R
G
B
W (D60)
0.75304,
0.29957,
0.07964,
0.32168,
0.32783
0.70070
-0.05494
0.33767
DRAGONcolor
"dragon2"R
G
B
W (D60)
0.75304,
0.29957,
0.14501,
0.32168,
0.32783
0.70070
0.05110
0.33767
DRAGONcolor2
"red"R
G
B
W (D60)
0.69975,
0.30426,
0.13491,
0.32168,
0.32905
0.62364
0.03472
0.33767
REDcolor
"red2"R
G
B
W (D60)
0.87868,
0.30089,
0.09540,
0.32168,
0.32496
0.67905
−0.02939
0.33767
REDcolor2
"red3"R
G
B
W (D60)
0.70118,
0.30060,
0.10815,
0.32168,
0.32901
0.68379
−0.00869
0.33767
REDcolor3
"red4"R
G
B
W (D60)
0.70118,
0.30060,
0.14533,
0.32168,
0.32901
0.68379
0.05162
0.33767
REDcolor4
"redwide"R
G
B
W (D65)
0.780308,
0.121595,
0.095612,
0.3217,
0.304253
1.493994
−0.084589
0.3290
REDWideGamutRGB
"awg4"R
G
B
W (D65)
0.7347,
0.1424,
0.0991,
0.3217,
0.2653
0.8576
−0.0308
0.3290
Arri Wide Gamut 4

wconv

Indicates we want a full conversion for the white point.

If set to False, chromatic adaptation will be used, so the white will stay white on the destination illuminant and colors will be adapted to implement a real illuminant change. This is generally what you want when converting between gamuts: the eye adapts to the new white and colors should be matched accordingly.

If set to True, the chromatic adaptation is bypassed. The white from the source colorspace will appear with a tint if the target colorspace has a different white point. Use this if you want to emulate what a picture displayed with a monitor using the source illuminant looks like on a display using the target illuminant. This is also what you want when converting to and from XYZ for further operations in this colorspace.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings), 1: limit to SSE2, 7: limit to AVX, 10: limit to AVX2.

resample

fmtc.resample (
	clip       : vnode       ;
	w          : int    : opt;
	h          : int    : opt;
	sx         : float[]: opt; (0)
	sy         : float[]: opt; (0)
	sw         : float[]: opt; (0)
	sh         : float[]: opt; (0)
	scale      : float  : opt; (0)
	scaleh     : float  : opt; (0)
	scalev     : float  : opt; (0)
	kernel     : data[] : opt; ("spline36")
	kernelh    : data[] : opt; (kernel)
	kernelv    : data[] : opt; (kernel)
	impulse    : float[]: opt;
	impulseh   : float[]: opt; (impulse)
	impulsev   : float[]: opt; (impulse)
	taps       : int[]  : opt; (4)
	tapsh      : int[]  : opt; (taps)
	tapsv      : int[]  : opt; (taps)
	a1         : float[]: opt;
	a2         : float[]: opt;
	a3         : float[]: opt;
	a1h        : float[]: opt; (a1)
	a2h        : float[]: opt; (a2)
	a3h        : float[]: opt; (a3)
	a1v        : float[]: opt; (a1)
	a2v        : float[]: opt; (a2)
	a3v        : float[]: opt; (a3)
	kovrspl    : int[]  : opt; (1)
	fh         : float[]: opt; (1)
	fv         : float[]: opt; (1)
	cnorm      : int[]  : opt; (True)
	total      : float[]: opt; (0)
	totalh     : float[]: opt; (total)
	totalv     : float[]: opt; (total)
	invks      : int[]  : opt; (False)
	invksh     : int[]  : opt; (invks)
	invksv     : int[]  : opt; (invks)
	invkstaps  : int[]  : opt; (4)
	invkstapsh : int[]  : opt; (invkstaps)
	invkstapsv : int[]  : opt; (invkstaps)
	csp        : int    : opt;
	css        : data   : opt;
	planes     : float[]: opt; (3)
	fulls      : int    : opt; (depends)
	fulld      : int    : opt; (fulls)
	center     : int[]  : opt; (True)
	cplace     : data   : opt; ("mpeg2")
	cplaces    : data   : opt; (cplace)
	cplaced    : data   : opt; (cplace)
	interlaced : int    : opt; (2)
	interlacedd: int    : opt; (interlaced)
	tff        : int    : opt; (2)
	tffd       : int    : opt; (tff)
	flt        : int    : opt; (False)
	cpuopt     : int    : opt; (-1)
)
fmtc_resample (
	clip   c,
	int    w (undefined),
	int    h (undefined),
	arrayf sx (0),
	arrayf sy (0),
	arrayf sw (0),
	arrayf sh (0),
	float  scale  (0),
	float  scaleh (0),
	float  scalev (0),
	string kernel  ("spline36"),
	string kernelh (kernel),
	string kernelv (kernel),
	arrayf impulse  (undefined),
	arrayf impulseh (impulse),
	arrayf impulsev (impulse),
	arrayi taps (4),
	arrayi tapsh (taps),
	arrayi tapsv (taps),
	arrayf a1 (undefined),
	arrayf a2 (undefined),
	arrayf a3 (undefined),
	arrayf a1h (a1),
	arrayf a2h (a2),
	arrayf a3h (a3),
	arrayf a1v (a1),
	arrayf a2v (a2),
	arrayf a3v (a3),
	int    kovrspl (1),
	arrayf fh (1),
	arrayf fv (1),
	bool   cnorm (true),
	arrayf total (0),
	arrayf totalh (total),
	arrayf totalv (total),
	arrayb invks  (false),
	arrayb invksh (invks),
	arrayb invksv (invks),
	arrayi invkstaps  (4),
	arrayi invkstapsh (invkstaps),
	arrayi invkstapsv (invkstaps),
	string csp (undefined),
	string css (undefined),
	arrayf planes (all),
	int    fulls (depends),
	int    fulld (fulls),
	arrayb center (true),
	string cplace  ("mpeg2"),
	string cplaces (cplace),
	string cplaced (cplace),
	int    interlaced (2),
	int    interlacedd (interlaced),
	int    tff (2),
	int    tffd (ttf),
	bool   flt (false),
	int    cpuopt (-1)
)

Resizes the planes of a clip. This function can change the chroma subsampling.

Output is always 16-bit integer (default for integer input) or 32-bit float. Use fmtc.bitdepth to convert the result to a lower bitdepth. It is possible to select the internal precision: float, or 16-bit integers with a 32-bit accumulator for the convolution. Internal conversion from float or 32-bit integers to 16 bits is done by quick rounding (no dithering). The integer operation path is available only when input and output formats are integer too.

The function can resize interlaced content, but only if presented as separated, interleaved fields. It uses the _Field and _FieldBased frame properties to detect interlaced content and field parity, maintaining the correct chroma and luma relative positions. If this automatic detection is not desired, you can specify manually the interlaced and tff parameters. Simple intra-field deinterlacing (“bob”) can be achieved this way, by specifying scalev=2.

Excepted impulse*, array parameters allow to specify plane-specific values. When specifying less than 3 values, the last specified value will be reused for the next planes. However planes works slightly differently, check the related paragraph for details.

Avisynth+ Arrays can be specified as values printed in a string and separated with spaces.

Note: field resizing is not always the best way to handle interlaced content, especially for upscales. You’ll probably have better results by using a “smart” deinterlacer (making use of temporal information and anti-aliasing), resizing the progressive content at double rate then reinterlacing. Simple field resampling is more or less equivalent to this method, using a naive bob.

Avisynth+ Interlacing parameters are automatically detected with global clip information which can be overriden by frame properties.

The function can also be used to compute horizontal and vertical convolutions. If you do so, don’t forget to set:

The function handles the following frame properties:

PropertyRead conditionWrite condition
_FieldBasedAutomatic interlacing detectionInterlaced
content
_FieldInterlaced content
_ChromaLocationDepends on cplace parameters
_ColorRangefulld is explicitly set

Parameters

clip

Clip to be resized. Mandatory. Supported input formats:

w, h

New picture width and height in pixels, > 0. If not specified, it will keep the original dimensions. The dimensions must be compatible with the destination chroma subsampling. They take precedence over the scale, scaleh and scalev parameters.

sx, sy

Coordinate of the top-left corner of the picture sub-area used as source for the resizing. They can be fractional. If negative, the picture is extended by replicating the left pixel column.

These parameters are arrays, so it’s possible to specify a different value for each plane. The last value is used for the unspecified planes. The coordinates are always related to the pixel dimensions, you don’t need to scale them with the chroma subsampling.

sw, sh

Size in pixels of the sub-area to resize. They can be fractional. If 0, the area has the same size as the source clip. If negative, they define coordinates relative to the bottom-right corner, in a Crop-like manner. These parameters are arrays like sx and sy.

scale, scaleh, scalev

Use these parameters to set relative dimensions, > 0. For example scale=0.5 will halve the picture size. The computed dimensions will be compatible with the destination chroma subsampling. Zero is ignored.

kernel

Kernel used by the resizer. Possible values are:

"point"Nearest neighbour interpolation. Same as Avisynth’s PointResize.
"rect" or "box"Box filter.
"linear" or
"bilinear"
Bilinear interpolation. Same as Avisynth’s BilinearResize.
"cubic" or
"bicubic"
Bicubic interpolation. Same as BicubicResize. The b and c variables are mapped on a1 and a2 and are both set to 1/3 by default.
"lanczos"Sinc function windowed by the central lobe of a sinc. Use taps to specify its impulse length. Same as LanczosResize.
"blackman"Blackman-Harris windowed sinc. Use taps to control its length. Same as BlackmanResize.
"blackmanminlobe"Another kind of Blackman windowed sinc, with a bit less ringing. Use taps for you know what.
"spline16"Standard cubic spline based kernel, 4 sample points. Same as Spline16Resize.
"spline36"Spline, 6 sample points. Same as Spline36Resize.
"spline64"Spline, 8 sample points. Same as Spline64Resize.
"spline"Generic natural cubic splines, number of sample points is twice the taps parameter, so you can use taps = 6 to get a more or less Spline144Resize equivalent.
"gauss" or
"gaussian"
Gaussian kernel. The p parameter is mapped on a1 and controls the curve width. The higher p, the sharper. It is set to 30 by default. This resizer is the same as GaussResize, but taps offers a control on the filter impulse length. For low p values (soft and blurry), it’s better to increase the number of taps to avoid truncating the gaussian curve too early and creating artifacts.
"sinc"Truncated sinc function. Use taps to control its length. Same as SincResize.
"impulse"Custom kernel. See the impulse parameter.

impulse, impulseh, impulsev

Offers the possibility to create your own kernel (useful for convolutions). Add your coefficents in the array. The number of coefficients must be odd. The curve is linearly interpolated between the provided points. You can oversample the impulse by setting kovrspl to a value > 1. To activate the custom kernel, set kernel="impulse".

taps, tapsh, tapsv

Some kernels have a variable number of sample points, given by this parameter. Actually this counts half the number of lobes (or equivalent); in case of downscaling, the actual number of sample points may be greater than the specified value. Range: 1–128

a1, a2, a3, a1h, a2h, a3h, a1v, a2v, a3v

Specific parameters, depending on the selected kernel.

kovrspl

Specifies here how many times the kernel is oversampled when you provide a custom impluse response. ≥ 1.

fh, fv

Horizontal and vertical frequency factors, also known as inverse kernel support. They are multipliers on the theoretical kernel cutoff frequency in both directions. Values below 1.0 spatially expand the kernel and blur the picture. Values over 1.0 shrink the kernel and let higher frequencies pass. The result will look sharper but more aliased. The multiplicator is applied after the kernel scaling in case of downsizing. Negative values force the processing, even if the horizontal size doesn’t change. The filter will use the absolute parameter value.

cnorm

If set to true, the impulse sum is normalised to 1 for each pixel. This is the normal behaviour when resizing, to make sure the energy is constant for all pixels. If you use the resizer as a convolution engine, it is advised to disable the normalisation.

total, totalh, totalv

When cnorm is activated, these parameters specify the normalisation value for the corresponding kernel. 0 means that the normalisation value is the sum of the coefficients. The Masktools’mt_convolution function has a single parameter for this use: total = totalh × totalv. Because the convolution is computed with floating point data, there is no saturation of intermediate results, therefore the balance between totalh and totalv is not important, only their product will be taken into account. Note that because kernels are single-dimention, the “parent” total parameter here is the sum of the coefficients for each direction, not the product of totalh and totalv.

invks, invksh, invksv

Set these parameter to True to activate the kernel inversion mode for the specified direction (use invks for both). Inverting the kernel allows to “undo” a previous upsizing by compensating the loss in high frequencies, giving a sharper and more accurate output than classic kernels, closer to the original. This is particularly useful for clips upscaled with a bilinear kernel. All the kernel-related parameters specify the kernel to undo. The target resolution must be as close as possible to the initial resolution. The kernel inversion is mainly intended to downsize an upscaled picture. Using it for upsizing will not restore details but will give a sligthly sharper look, at the cost of a bit of aliasing and ringing. This mode is somewhat equivalent to the debilinear plug-in but works with a different principle.

invkstaps, invkstapsh, invkstapsv

In kernel inversion mode (invks=True), this parameter sets the number of taps for the inverted kernel. Use it as a tradeof between softness and ringing. Range: 1–128

csp

Can only change the bitdepth and the data type (integer or float). Only 16-bit integer (xxxP16) and 32-bit float data types are allowed.

Vapoursynth The format is a Vapoursynth built-in constant.

Avisynth+ The format is a string with the same kind of content as the result from BuildPixelType or the pixel_type parameter from BlankClip.

css

Destination chroma subsampling, for YUV (and YCoCg) colorspaces. Supersedes the chroma subsampling from csp. You can also specify the subsampling with the predefined values or with a two-digit string. The first digit for the horizontal subsampling, and the second for the vertical subsampling. Only power-of-2 numbers are allowed. For example "41" is equivalent to 4:1:1 and "22" to 4:2:0.

The predefined values are:

"444" or "4:4:4"4:4:4, no chroma subsampling.
"422" or "4:2:2"4:2:2, horizontal 2x chroma subsampling.
"420" or "4:2:0"4:2:0, horizontal and vertical 2x chroma subsampling.
"411" or "4:1:1"4:1:1, horizontal 4x chroma subsampling.

planes

This array decribes how each plane should be processed. It’s similar to the y, u and v parameters in Masktools 2.

−65535
to +0.5
All the pixels of the plane will be set to −x (the opposite of the specified value). The range depends on the output data type. Remember, in floating-point YUV, the chroma planes range from −0.5 to +0.5.
1The plane will not be processed. This means that the content of the output plane is pure garbage.
2The plane of the input clip will be copied and possibly cropped. Areas out of the input picture are left unprocessed (garbage). Range (full or TV) conversions are ignored.
3The plane will be processed (default).

Avisynth+ The parameter can also be specified as a string. See the planes parameter from the fmtc_bitdepth function for more details.

fulls, fulld

Indicates if the clip is full-range (True) or TV-range (False). fulls is for input, fulld for output. Reference black and white have different values depending on the range. In 8 bits, pixel values scale from 0 to 255 in full range, and 16 to 235 in TV-range (16 to 240 for the Y’Cb’Cr’ chroma planes). This value has no meaning for float data.

The default value depends on the colorspace. For example, full-range is assumed for RGB and YCoCg colorspaces. Others are assumed TV-range. These parameters are mainly intended to guide conversions between integer and floating-point data. They can also be used for range conversions. Pixel values are not clipped during a conversion between two TV-range formats.

center

Like the Avisynth standard resizers, this resizer preserves the position of the picture center. Disable this parameter if you may want to resize by preserving the top-left corner position. Similarly, if you are convolving without resizing, setting it to false ensures you that the same kernel will be applied to all pixels.

cplace, cplaces, cplaced

Placement of the chroma samples. cplaces specifies the source clip only, cplaced the destination clip. Can be one of these strings:

"MPEG1"
"JPEG"
"center"
4:2:0 subsampling used in MPEG-1 and JPEG. Chroma samples are located on the center of each group of 4 pixels.
"MPEG2"
"left"
Subsampling used in MPEG-2 4:2:x and most other formats. Chroma samples are located on the left pixel column of the group.
"DV"For 4:2:0 modes, it’s like MPEG-2 but U and V channels are “co-sited” vertically: V on the top row, and U on the bottom row. For 4:1:1, chroma is located on the leftmost column.
"top_left"
"tl"
Chroma samples are located on the top-left luma sample of each pixel group.

The chroma placement is ignored when center is set to False or kernel to "point". You’ll find below an overview of common chroma placement and subsampling combinations:

Chroma placement

interlaced, interlacedd

Specifies if the clip is made of frames or fields. interlacedd overrides interlaced for output.

0Frames are progressive content.
1Frames are actually the separated fields of an interlaced stream. Specify tff or provide the _Field property in all the frames.
2Automatic detection, depends on the _FieldBased frame property. If not found, the frame is considered progressive.

tff, tffd

When processing interlaced content, specifies the field parity. tffd overrides tff for output.

0Bottom field first (BFF). This means all even fields are top, and all odd fields are bottom.
1Top field first (TFF). This means all even fields are bottom, and all odd fields are top.
2Automatic detection, depends on the _Field frame property. If not found, the frame is considered progressive.

flt

Flag to force floating point operations. When set to False, integer operations are used, but only if both input and output formats are integer. If it’s not the case, floating point operations are silently used as fallback.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings), 1: limit to SSE2, 10: limit to AVX2.

transfer

fmtc.transfer (
	clip    : vnode       ;
	transs  : data[] : opt;
	transd  : data[] : opt;
	cont    : float  : opt;
	gcor    : float  : opt;
	bits    : int    : opt;
	flt     : int    : opt;
	fulls   : int    : opt; (True)
	fulld   : int    : opt; (True)
	logceis : int    : opt; (800)
	logceid : int    : opt; (800)
	cpuopt  : int    : opt; (-1)
	blacklvl: float  : opt; (0)
	sceneref: int    : opt; (undefined)
	lb      : float  : opt;
	lw      : float  : opt;
	lw_s    : float  : opt; (lw)
	lw_d    : float  : opt; (lw)
	ambient : float  : opt;
	match   : int    : opt; (1)
	gy      : int    : opt;
	debug   : int    : opt; (0)
	sig_c   : float  : opt; (6.5)
	sig_t   : float  : opt; (0.5)

)
fmtc_transfer (
	clip   c,
	string transs (undefined),
	string transd (undefined),
	float  cont (1),
	float  gcor (1),
	int    bits (undefined),
	bool   flt (undefined),
	bool   fulls (true),
	bool   fulld (true),
	int    logceis (800),
	int    logceid (800),
	int    cpuopt (-1),
	float  blacklvl (0),
	bool   sceneref (undefined),
	float  lb (undefined),
	float  lw (undefined),
	float  lw_s (lw),
	float  lw_d (lw),
	float  ambient (undefined),
	int    match (1),
	bool   gy (undefined),
	int    debug (0),
	float  sig_c (6.5),
	float  sig_t (0.5)
)

Applies electro-optical and opto-electrical transfer characteristics to the video signal to convert between linear and gamma-corrected modes.

The function offers four conversions in a row; all are optional:

It is possible to specify the linear step as scene-referred or display-referred. The latter is the default.

By default, the function tries to match the reference white levels between the transfer functions by automatically scaling the linear light values. In the linear range, reference white is generally associated to the normalised value 1.0, peak white might be much higher. This is important to remember when dealing with HDR content, especially when using integer data types which do not allow overflow (normalised values above 1.0). An additional contrast step might be required to fit the content into the desired range, when linear values are used as input or output. Please refer to the curve table below to check the luminance information.

This function is for simple conversions only, it doesn’t do sophisticated tone mapping.

As input, the function accepts only RGB and grayscale colorspaces.

As output, the data type can be changed while the colorspace is kept. Only 16-bit integer and 32-bit float are supported. Use bitdepth to properly convert the output to a lower bitdepth.

The signal may be clipped depending on the transfer specification or the domain requirement of the functions.

The function sets the _ColorRange and _Transfer frame properties.

Avisynth+ Colorspaces with an alpha channel are supported too, but the channel is left untouched.

Processing diagram for the display-referred mode
Processing diagram for the display-referred mode.
Processing diagram for the scene-referred mode
Processing diagram for the scene-referred mode

Parameters

clip

The input clip. Supported input formats:

transs, transd

Transfer characteristics for input and output, respectively. The characteristic may be an OETF, an EOTF, or just remain unspecified. It is direct or inverted according to where it is applied, output or input. The intermediate state is assumed linear light. The curve set is the same as the list in ISO/IEC 23008-2 (HEVC), with a few additions from various camera manufacturers or NLE systems.

Most curves map their value from the 0–1 range to 0–1, but some are for high dynamic range or wide gamut signals and locate their value for peak white much higher. Generally, display-referred linear scales are mapped to a known range in cd/m2, whereas scene-referred linear scales are arbitrary.

ValueLinear rangeTypeRangeDescription
"709" 0…1OETFSDRITU-R BT.709
"470m" 0…1SDRITU-R BT.470-6 System M, FCC (assumed display gamma 2.2)
Actually uses the same curve as IEC 61966-2-1.
"470bg" 0…1SDRITU-R BT.470-6 System B, G (assumed display gamma 2.8)
"601" 0…1OETFSDRITU-R BT.601
"240" 0…1SDRSMPTE 240M
"linear"
""
UnspecifiedLinear (bypass)
"log100" 0…1Logarithmic transfer characteristic (100:1 range)
"log316" 0…1Logarithmic transfer characteristic (100√10:1 range)
"61966-2-4" UnspecifiedOETFSDRIEC 61966-2-4, xvYCC. Same as BT.709, but with an extended range, including negative values.
"1361" −0.25…1.33ITU-R BT.1361 extended colour gamut system
"61966-2-1"
"srgb"
"sycc"
0…1EOTFSDRIEC 61966-2-1, sRGB or sYCC
Apple Display P3
"2020_10" 0…1SDRITU-R BT.2020 for 10-bit system
"2020_12"
"2020"
0…1SDRITU-R BT.2020 for 12-bit system
"pq"
"2084"
0…1EOTFHDRSMPTE ST 2084 for 10, 12, 14 and 16-bit systems
ITU-R BT.2100-2 PQ (perceptual quantization)
Linear 1.0 is peak white and corresponds to a display luminance level of 10 000 cd/m2. Reference white is 203 cd/m2.
"428"
"428-1"
0…1SDRSMPTE ST 428-1, DCI-P3 (with XYZ values)
Linear 48 / 52.37 corresponds to a reference display luminance level of 48 cd/m2.
"hlg" 0…1OETFHDRITU-R BT.2100 HLG (hybrid log-gamma), ARIB STD-B67
Reference white is at 75 % of the coding range, giving 203 cd/m2 when peak white is set to 1000 cd/m2. Set lw to specify explicitely the peak white luminance.
"1886" 0…1EOTFSDRITU-R BT.1886. Intended to mimicing a CRT display curve. Peak white is 100 cd/m2.
"1886a" 0…1EOTFSDRITU-R BT.1886, alternative approximation
"filmstream"0…1OETFThomson FilmStream
Linear 1.0 is the sensor clipping level, corresponding to 3840 on a linear 12-bit scale.
"slog" −0.006…10OETFSony S-Log
Linear 1.0 is the reference white, peak white is at 10.0.
"slog2" −0.0085…14.13OETFSony S-Log 2
Linear 1.0 is the reference white, peak white is at 14.13.
"slog3" 0…38.421OETFSony S-Log3.
"logc2" UnspecifiedOETFArri Log C Alexa 2.x, linear scene exposure
Peak white is 57.45 linear. The negative part of the range allows coding sensor noise. logceis and logceid set the Exposure Index (EI).
"logc3" UnspecifiedOETFArri Log C Alexa 3.x, linear scene exposure
Peak white is 55.08 linear. The negative part of the range allows coding sensor noise. logceis and logceid set the Exposure Index (EI).
"logc4" UnspecifiedOETFArri LogC4, linear scene exposure
Peak white is 469.80 but this is only a hardware limit.
"canonlog" 0…8.00903OETFCanon-Log
Peak white is 8.00903 in linear scale and 1.08676 in compressed scale.
"adobergb" 0…1SDRAdobe RGB (1998 and Wide Gamut).
Reference white is 160 cd/m2.
"romm" 0…1SDRProPhoto, ROMM.
Reference white is 142 cd/m2.
"acescc" −65504…65504OETFACEScc. Values are actually bounded to the ACES 16-bit float range.
"acescct" −65504…65504OETFACEScct. Values are actually bounded to the ACES 16-bit float range.
"erimm" 0…316.2OETFERIMM
"vlog" 0…1Panasonic V-Log
"davinci" −0.01…100OETFBlackmagic Design DaVinci Intermediate
"log3g10" −0.01…184.32HDRRED Log3G10
"redlog" 0…1REDlog
"cineon" −0.006…13.522Cineon and REDlogFilm
"panalog" −0.01…6.100Panalog
"sigmoid" UnspecifiedSigmoid curve applied on linear data
"lstar" 0…unspecifiedL* curve from CIELAB (L*a*b) and CIELUV (L*u*v*) 1976. Linear 1.0 is reference white, peak white is unspecified.

cont

Optional contrast adjustment to apply to the linear signal. This is a multiplicative value, 1 is neutral. Contrast is modified before the gamma correction. This parameter is useful to match the reference or peak white points between transfer functions which have not the same reference.

gcor

Optional gamma correction to apply to the linear signal. This is a power value, 1 is a bypass. Comes after contrast adjustment. In display-referred mode, the invariant (neutral) point of the correction is the reference white.

bits

Sets the output bitdepth. Currently only 16-bit integer and 32-bit float are supported. The data type is adapted automatically if required. This parameter shouldn’t conflict with flt.

flt

Set it to 0 to convert the output to integer, or to 1 to convert to floating point data.

fulls, fulld

Indicates if the clip is full-range (True) or TV-range (False). fulls is for input, fulld for output. Reference black and white have different values depending on the range. In 8 bits, pixel values scale from 0 to 255 in full range, and 16 to 235 in TV-range (16 to 240 for the Y’Cb’Cr’ chroma planes). This value has no meaning for float data.

logceis, logceid

Exposure index (EI) for the Arri Log C Alexa 2.x and 3.x curves. Allowed values are: 160, 200, 250, 320, 400, 500, 640, 800 (default), 1000, 1280 and 1600.

cpuopt

Limits the CPU instruction set. −1: automatic (no limitation), 0: default instruction set only (depends on the compilation settings), 1: limit to SSE2, 10: limit to AVX2.

blacklvl

This parameter is deprecated, please use lb and lw instead.

Black level value (linear range) for the electro-optical transfer function. It shifts and stretches the transfer curve in order to make the black value in gamma-encoded range match the specified level in linear range. Raising the black level is equivalent to increasing the brightness setting combined with a slight contrast reduction not to alter the white. The parameter should be ≥ 0. There is no specific unit, it’s just a value from the target linear range, generally in 0–1. Internally, it is converted to lb, so it uses lw as reference. If the latter is not specified by the user, it uses 100 cd/m2, even if the transfer function is HDR. Ignored when the linear light is scene-referred.

sceneref

Indicates that the linear light step is scene-referred. When set to False, the linear light is display-referred. This helps removing ambiguity when BT.2100 transfer functions (PQ and HLG) are used. Direct or inverse OOTFs are switched as required.

lb

Indicate the black level for the source transfer function, in cd/m2. This parameters is taken into account when display-referred transfer functions are used. The EOTF (source) function uses lb as brightness setting.

lw, lws, lwd

Indicate the peak white levels in cd/m2. lws is for the source transfer function, and lwd for the destination one. These parameters are taken into account to scale the luminance when the following conditions are met:

Minimum lw value is 0.1 cd/m2. System gamma may be changed according to the lw parameter. Unless specified, HDR functions use a peak white of 1000 cd/m2. Similarly, SDR and other functions use 100 cd/m2 by default. It is strongly recommended to manually set lw when using the HLG curve, otherwise the automatic LW estimation could result in something unexpected.

ambient

Default ambient luminance for display-referred transfer functions, in cd/m2. This adapts automatically the OOTF system gamma.

match

Selects the luminance matching between the transfer functions.

0No specific match. Linear values are not scaled.
1Matches the reference white. 1 is the reference white level.
2Tries to match the display luminance.

Display luminance matching is available only for display-referred transfers. It is automatically disabled when sceneref is True. Linear scale in luminance match is at least 100 cd/m2, but the exact value is unspecified and depends on the involved transfer functions.

gy

Overrides default gamma processing. When set to False, gamma is applied on each component separately. Processing is fast, but possibly distorts the colors. When set to True, gamma is applied to the luminance only, leaving the colors undistorted. When the parameter is unspecified, the gamma processing is selected depending on the transfer functions. More specifically, the HLG OOTF curve requires applying the gamma on luminance. Other curves use standard gamma processing.

debug

When this parameter is not null, a property is attached to the processed frames. It contains a text string with debugging information about light levels and system gamma used at each stage of the processing. The name of the property is "FmtcTransferDbg" followed with the parameter value, so multiple calls to transfer can be checked simultaneously.

sig_c

Curvature value for the sigmoid curve, in range 0.1–10. You can use the "sigmoid" curve instead of the "linear" one to prevent exagerated ringing when resizing in linear light. This is not a real transfer function but it fits well here in a workflow. The higher the curvature value, the more non-linear the function. The sigmoid curve with its parameters can be visualised here.

sig_t

Inflection point for the sigmoid curve, in range 0–1. The closer to 1, the more the curve looks like a standard power curve.

stack16tonative, nativetostack16

fmtc.stack16tonative (
	clip: clip;
)
fmtc.nativetostack16 (
	clip: clip;
)

Converts between 16-bit clips and stack16 clips. A stack16 clip is a 8-bit clip containing the picture made of the most significant byte of each pixel, stacked on the top of a picture made of their least significant byte. These functions are meant to offer interoperability with Avisynth plug-ins using this format.

Parameters

clip

The input clip. Mandatory. Can be only 8-bit integer for stack16tonative and 16-bit integer for nativetostack16.

IV) Troubleshooting

I’m waiting for your complaints.

V) Changelog

r31, 202x-xx-xx

r30, 2022-08-29

r29, 2022-04-11

r28, 2021-11-20

r27, 2021-10-30

r26, 2021-10-19

r25, 2021-09-19

r24, 2021-08-16

r23, 2021-07-14

r22, 2019-12-11

r21, 2019-12-08

r20, 2016-03-25

r19, 2016-03-19

r18, 2016-03-08

r17, 2015-07-08

r16, 2015-07-01

r15, 2015-05-22

r14, 2015-05-20

r13, 2015-05-18

r12, 2015-05-08

r11, 2015-05-07

r10, 2015-05-06

r9, 2015-05-06

r8, 2013-11-30

r7, 2013-11-27

r6, 2013-08-24

r5, 2013-08-18

r4, 2012-12-09

r3, 2012-11-23

r2, 2012-11-18

r1, 2012-11-16