Skip to content

color

Type Aliases:

Classes:

Attributes:

  • ColorRangeT

    Deprecated alias of ColorRangeLike

  • MatrixT

    Deprecated alias of MatrixLike

  • PrimariesT

    Deprecated alias of PrimariesLike

  • TransferT

    Deprecated alias of TransferLike

ColorRangeT module-attribute

ColorRangeT = ColorRangeLike

Deprecated alias of ColorRangeLike

MatrixT module-attribute

MatrixT = MatrixLike

Deprecated alias of MatrixLike

PrimariesT module-attribute

PrimariesT = PrimariesLike

Deprecated alias of PrimariesLike

TransferT module-attribute

TransferT = TransferLike

Deprecated alias of TransferLike

ColorRangeLike

ColorRangeLike = int | ColorRange | ColorRange | HoldsPropValue

Type alias for values that can be used to initialize a ColorRange.

MatrixLike

MatrixLike = int | MatrixCoefficients | Matrix | HoldsPropValue

Type alias for values that can be used to initialize a Matrix.

PrimariesLike

PrimariesLike = int | ColorPrimaries | Primaries | HoldsPropValue

Type alias for values that can be used to initialize a Primaries.

TransferLike

TransferLike = int | TransferCharacteristics | Transfer | HoldsPropValue

Type alias for values that can be used to initialize a Transfer.

ColorRange

ColorRange(
    _: Any, string: str | None = None, pretty_string: str | None = None
)

Bases: PropEnum

Pixel Range (ITU-T H.265 Equations E-10 through E-20.

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the VideoNode.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param_or_video

    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

  • from_param_with_fallback

    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted

  • from_res

    Guess the color range from the frame resolution.

  • from_video

    Try to obtain the color range of a clip from the frame props or fallback to clip's resolution

  • is_full

    Check if ColorRange is full.

  • is_limited

    Check if ColorRange is limited.

  • is_unspecified

    Whether the value is unspecified.

  • pretty_string

    Get a pretty, displayable string of the enum member.

  • prop_key

    The key used in props to store the enum.

  • string

    Get the string representation used in resize plugin/encoders.

Attributes:

  • FULL

    Full (PC) dynamic range, 0-255 in 8 bits.

  • LIMITED

    Studio (TV) legal range, 16-235 in 8 bits.

  • value_vs (int) –

    VapourSynth (props) value.

  • value_zimg (int) –

    zimg (resize plugin) value.

Source code in vstools/enums/base.py
34
35
36
def __init__(self, _: Any, string: str | None = None, pretty_string: str | None = None) -> None:
    self._string = fallback(string, self._name_.lower())
    self._pretty_string = fallback(pretty_string, capwords(self._string.replace("_", " ")))

FULL class-attribute instance-attribute

FULL = 0

Full (PC) dynamic range, 0-255 in 8 bits.

Note that float clips should ALWAYS be FULL range! RGB clips will ALWAYS be FULL range!

LIMITED class-attribute instance-attribute

LIMITED = 1

Studio (TV) legal range, 16-235 in 8 bits.

This is primarily used with YUV integer formats.

value_vs property

value_vs: int

VapourSynth (props) value.

value_zimg property

value_zimg: int

zimg (resize plugin) value.

apply

apply(clip: VideoNode) -> VideoNode

Applies the property to the VideoNode.

Source code in vstools/enums/base.py
67
68
69
70
71
def apply(self, clip: vs.VideoNode) -> vs.VideoNode:
    """
    Applies the property to the VideoNode.
    """
    return clip.std.SetFrameProp(self.prop_key, self.value)

ensure_presence classmethod

ensure_presence(
    clip: VideoNode, value: Any, func: FuncExcept | None = None
) -> VideoNode

Ensure the presence of the property in the VideoNode.

Source code in vstools/enums/base.py
153
154
155
156
157
158
159
160
@classmethod
def ensure_presence(cls, clip: vs.VideoNode, value: Any, func: FuncExcept | None = None) -> vs.VideoNode:
    """
    Ensure the presence of the property in the VideoNode.
    """
    enum_value = cls.from_param_or_video(value, clip, True, func)

    return clip.std.SetFrameProp(enum_value.prop_key, enum_value.value)

ensure_presences staticmethod

ensure_presences(
    clip: VideoNode,
    prop_enums: Iterable[type[PropEnum] | PropEnum],
    func: FuncExcept | None = None,
) -> VideoNode

Ensure the presence of multiple PropEnums at once.

Source code in vstools/enums/base.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@staticmethod
def ensure_presences(
    clip: vs.VideoNode, prop_enums: Iterable[type[PropEnum] | PropEnum], func: FuncExcept | None = None
) -> vs.VideoNode:
    """
    Ensure the presence of multiple PropEnums at once.
    """
    return clip.std.SetFrameProps(
        **{
            value.prop_key: value.value
            for value in (
                prop_enum if isinstance(prop_enum, PropEnum) else prop_enum.from_video(clip, True, func)
                for prop_enum in prop_enums
            )
        },
    )

from_param_or_video classmethod

from_param_or_video(
    value: Any,
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self

Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

If strict=False, gather the heuristics using the clip's size or format.

Parameters:

  • value

    (Any) –

    Value to cast.

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Clip to get prop from.

  • strict

    (bool, default: False ) –

    Be strict about the frame properties. Default: False.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Source code in vstools/enums/base.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@classmethod
def from_param_or_video(
    cls,
    value: Any,
    src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

    If `strict=False`, gather the heuristics using the clip's size or format.

    Args:
        value: Value to cast.
        src: Clip to get prop from.
        strict: Be strict about the frame properties. Default: False.
        func_except: Function returned for custom error handling.
    """
    prop = cls.from_param_with_fallback(value, None)

    # Delay the `from_video` call here to avoid unnecessary frame rendering
    if prop is None:
        return cls.from_video(src, strict, func_except)

    return prop

from_param_with_fallback classmethod

from_param_with_fallback(value: Any, fallback: None = None) -> Self | None
from_param_with_fallback(value: Any, fallback: T) -> Self | T
from_param_with_fallback(
    value: Any, fallback: T | None = None
) -> Self | T | None

Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted or represents an unspecified enum member.

Parameters:

  • value

    (Any) –

    The input value to convert into an enum member.

  • fallback

    (T | None, default: None ) –

    The value to return if the input cannot be converted. Defaults to None.

Returns:

  • Self | T | None

    The corresponding enum member if conversion succeeds, otherwise the provided fallback value.

Source code in vstools/enums/base.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@classmethod
def from_param_with_fallback[T](cls, value: Any, fallback: T | None = None) -> Self | T | None:
    """
    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted
    or represents an unspecified enum member.

    Args:
        value: The input value to convert into an enum member.
        fallback: The value to return if the input cannot be converted. Defaults to `None`.

    Returns:
        The corresponding enum member if conversion succeeds, otherwise the provided `fallback` value.
    """
    with suppress(NotFoundEnumValueError, CustomValueError):
        # Will raise a NotFoundEnumValueError if the value can't be casted
        casted = cls.from_param(value)

        # If unspecified, fallbacks to `fallback` value
        if casted.is_unspecified():
            raise CustomValueError

        return casted

    return fallback

from_res classmethod

from_res(frame: VideoNode | VideoFrame) -> ColorRange

Guess the color range from the frame resolution.

Source code in vstools/enums/color.py
692
693
694
695
696
697
698
699
700
701
702
703
704
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> ColorRange:
    """
    Guess the color range from the frame resolution.
    """
    from ..utils import get_var_infos

    fmt, _, _ = get_var_infos(frame)

    if fmt.color_family == vs.RGB:
        return cls.FULL

    return cls.LIMITED

from_video classmethod

from_video(
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func: FuncExcept | None = None,
) -> ColorRange

Try to obtain the color range of a clip from the frame props or fallback to clip's resolution if the prop is undefined, strict=False and src is a clip.

Parameters:

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the frame props. Sets the ColorRange as MISSING if prop is not there.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Raises:

Source code in vstools/enums/color.py
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> ColorRange:
    """
    Try to obtain the color range of a clip from the frame props or fallback to clip's resolution
    if the prop is undefined, strict=False and src is a clip.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the frame props. Sets the ColorRange as MISSING if prop is not there.
        func: Function returned for custom error handling.

    Returns:
        ColorRange object.

    Raises:
        UndefinedColorRangeError: If the color range is undefined or can not be determined from the frameprops.
    """
    return _base_from_video(cls, src, UndefinedColorRangeError, strict, func)

is_full

is_full() -> bool

Check if ColorRange is full.

Source code in vstools/enums/color.py
686
687
688
689
690
def is_full(self) -> bool:
    """
    Check if ColorRange is full.
    """
    return not self.value

is_limited

is_limited() -> bool

Check if ColorRange is limited.

Source code in vstools/enums/color.py
680
681
682
683
684
def is_limited(self) -> bool:
    """
    Check if ColorRange is limited.
    """
    return bool(self.value)

is_unspecified

is_unspecified() -> bool

Whether the value is unspecified.

Source code in vstools/enums/base.py
73
74
75
76
77
def is_unspecified(self) -> bool:
    """
    Whether the value is unspecified.
    """
    return False

pretty_string

pretty_string() -> str

Get a pretty, displayable string of the enum member.

Source code in vstools/enums/base.py
45
46
47
48
49
50
@cachedproperty
def pretty_string(self) -> str:
    """
    Get a pretty, displayable string of the enum member.
    """
    return self._pretty_string

prop_key classmethod

prop_key() -> str

The key used in props to store the enum.

Source code in vstools/enums/base.py
59
60
61
62
63
64
65
@classproperty
@classmethod
def prop_key(cls) -> str:
    """
    The key used in props to store the enum.
    """
    return f"_{cls.__name__}"

string

string() -> str

Get the string representation used in resize plugin/encoders.

Source code in vstools/enums/base.py
52
53
54
55
56
57
@cachedproperty
def string(self) -> str:
    """
    Get the string representation used in resize plugin/encoders.
    """
    return self._string

Matrix

Matrix(_: Any, string: str | None = None, pretty_string: str | None = None)

Bases: PropEnum

Matrix coefficients (ITU-T H.265 Table E.5).

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the VideoNode.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param_or_video

    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

  • from_param_with_fallback

    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted

  • from_res

    Guess the matrix based on the clip's resolution.

  • from_video

    Try to obtain the matrix of a clip from the frame props or fallback to clip's resolution

  • is_unspecified

    Check if the matrix is Matrix.UNSPECIFIED.

  • pretty_string

    Get a pretty, displayable string of the enum member.

  • prop_key

    The key used in props to store the enum.

  • string

    Get the string representation used in resize plugin/encoders.

Attributes:

Source code in vstools/enums/base.py
34
35
36
def __init__(self, _: Any, string: str | None = None, pretty_string: str | None = None) -> None:
    self._string = fallback(string, self._name_.lower())
    self._pretty_string = fallback(pretty_string, capwords(self._string.replace("_", " ")))

BT2020_CL class-attribute instance-attribute

BT2020_CL = (10, '2020cl', 'BT.2020 constant luminance')

KR = 0.2627; KB = 0.0593

Rec. ITU-R BT.2020-2 constant luminance system

See ITU-T H.265 Equations E-49 to E-58

BT2020_NCL class-attribute instance-attribute

BT2020_NCL = (9, '2020ncl', 'BT.2020 non-constant luminance')

KR = 0.2627; KB = 0.0593

Rec. ITU-R BT.2020-2 non-constant luminance system

Rec. ITU-R BT.2100-2 Y'CbCr

See ITU-T H.265 Equations E-28 to E-30

BT470_BG class-attribute instance-attribute

BT470_BG = (5, '470bg', 'BT.470bg')

KR = 0.299; KB = 0.114

(Functionally the same as Matrix.ST170_M)

Rec. ITU-R BT.470-6 System B, G (historical)

Rec. ITU-R BT.601-7 625

Rec. ITU-R BT.1358-0 625 (historical)

Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM

IEC 61966-2-1 sYCC

IEC 61966-2-4 xvYCC601

See ITU-T H.265 Equations E-28 to E-30

BT709 class-attribute instance-attribute

BT709 = (1, '709', 'BT.709')

Kr = 0.2126; Kb = 0.0722

Rec. ITU-R BT.709-6

Rec. ITU-R BT.1361-0 conventional colour gamut system and extended colour gamut system (historical)

IEC 61966-2-4 xvYCC709

SMPTE RP 177 (1993) Annex B

CHROMATICITY_DERIVED_CL class-attribute instance-attribute

CHROMATICITY_DERIVED_CL = (
    13,
    "chromacl",
    "Chromaticity derived constant luminance",
)

Chromaticity-derived constant luminance system

See ITU-T H.265 Equations E-22 to E-27

See ITU-T H.265 Equations E-49 to E-58

CHROMATICITY_DERIVED_NC class-attribute instance-attribute

CHROMATICITY_DERIVED_NC = (
    12,
    "chromancl",
    "Chromaticity derived non-constant luminance",
)

Chromaticity-derived non-constant luminance system

See ITU-T H.265 Equations E-22 to E-27 See ITU-T H.265 Equations E-28 to E-30

FCC class-attribute instance-attribute

FCC = (4, 'fcc', 'FCC')

KR = 0.30; KB = 0.11

FCC Title 47 Code of Federal Regulations (2003) 73.682 (a) (20)

See ITU-T H.265 Equations E-28 to E-30

ICTCP class-attribute instance-attribute

ICTCP = (14, 'ictcp', 'ICtCp')

ICtCp

Rec. ITU-R BT.2100-2 ICTCP

See ITU-T H.265 Equations E-62 to E-64 for transfer_characteristics value 16 (PQ)

See ITU-T H.265 Equations E-65 to E-67 for transfer_characteristics value 18 (HLG)

RGB class-attribute instance-attribute

RGB = (0, 'rgb', 'RGB')

The identity matrix.

Typically used for GBR (often referred to as RGB); however, may also be used for YZX (often referred to as XYZ)

IEC 61966-2-1 sRGB

SMPTE ST 428-1 (2006)

See ITU-T H.265 Equations E-31 to E-33

ST170_M class-attribute instance-attribute

ST170_M = (6, '170m', 'SMPTE ST 170m')

Kr = 0.299; Kb = 0.114

(Functionally the same as Matrix.BT470_BG)

Rec. ITU-R BT.601-7 525

Rec. ITU-R BT.1358-1 525 or 625 (historical)

Rec. ITU-R BT.1700-0 NTSC

SMPTE ST 170 (2004)

See ITU-T H.265 Equations E-28 to E-30

ST240_M class-attribute instance-attribute

ST240_M = (7, '240m', 'SMPTE ST 240m')

KR = 0.212; KB = 0.087

SMPTE ST 240 (1999, historical)

See ITU-T H.265 Equations E-28 to E-30

UNSPECIFIED class-attribute instance-attribute

UNSPECIFIED = (2, 'unspec')

Unspecified.

Image characteristics are unknown or are determined by the application.

YCGCO class-attribute instance-attribute

YCGCO = (8, 'ycgco', 'YCgCo')

KR = 0.2126; KB = 0.0722

See Implementation And Evaluation Of Residual Color Transform For 4:4:4 RGB Lossless Coding

apply

apply(clip: VideoNode) -> VideoNode

Applies the property to the VideoNode.

Source code in vstools/enums/base.py
67
68
69
70
71
def apply(self, clip: vs.VideoNode) -> vs.VideoNode:
    """
    Applies the property to the VideoNode.
    """
    return clip.std.SetFrameProp(self.prop_key, self.value)

ensure_presence classmethod

ensure_presence(
    clip: VideoNode, value: Any, func: FuncExcept | None = None
) -> VideoNode

Ensure the presence of the property in the VideoNode.

Source code in vstools/enums/base.py
153
154
155
156
157
158
159
160
@classmethod
def ensure_presence(cls, clip: vs.VideoNode, value: Any, func: FuncExcept | None = None) -> vs.VideoNode:
    """
    Ensure the presence of the property in the VideoNode.
    """
    enum_value = cls.from_param_or_video(value, clip, True, func)

    return clip.std.SetFrameProp(enum_value.prop_key, enum_value.value)

ensure_presences staticmethod

ensure_presences(
    clip: VideoNode,
    prop_enums: Iterable[type[PropEnum] | PropEnum],
    func: FuncExcept | None = None,
) -> VideoNode

Ensure the presence of multiple PropEnums at once.

Source code in vstools/enums/base.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@staticmethod
def ensure_presences(
    clip: vs.VideoNode, prop_enums: Iterable[type[PropEnum] | PropEnum], func: FuncExcept | None = None
) -> vs.VideoNode:
    """
    Ensure the presence of multiple PropEnums at once.
    """
    return clip.std.SetFrameProps(
        **{
            value.prop_key: value.value
            for value in (
                prop_enum if isinstance(prop_enum, PropEnum) else prop_enum.from_video(clip, True, func)
                for prop_enum in prop_enums
            )
        },
    )

from_param_or_video classmethod

from_param_or_video(
    value: Any,
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self

Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

If strict=False, gather the heuristics using the clip's size or format.

Parameters:

  • value

    (Any) –

    Value to cast.

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Clip to get prop from.

  • strict

    (bool, default: False ) –

    Be strict about the frame properties. Default: False.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Source code in vstools/enums/base.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@classmethod
def from_param_or_video(
    cls,
    value: Any,
    src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

    If `strict=False`, gather the heuristics using the clip's size or format.

    Args:
        value: Value to cast.
        src: Clip to get prop from.
        strict: Be strict about the frame properties. Default: False.
        func_except: Function returned for custom error handling.
    """
    prop = cls.from_param_with_fallback(value, None)

    # Delay the `from_video` call here to avoid unnecessary frame rendering
    if prop is None:
        return cls.from_video(src, strict, func_except)

    return prop

from_param_with_fallback classmethod

from_param_with_fallback(value: Any, fallback: None = None) -> Self | None
from_param_with_fallback(value: Any, fallback: T) -> Self | T
from_param_with_fallback(
    value: Any, fallback: T | None = None
) -> Self | T | None

Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted or represents an unspecified enum member.

Parameters:

  • value

    (Any) –

    The input value to convert into an enum member.

  • fallback

    (T | None, default: None ) –

    The value to return if the input cannot be converted. Defaults to None.

Returns:

  • Self | T | None

    The corresponding enum member if conversion succeeds, otherwise the provided fallback value.

Source code in vstools/enums/base.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@classmethod
def from_param_with_fallback[T](cls, value: Any, fallback: T | None = None) -> Self | T | None:
    """
    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted
    or represents an unspecified enum member.

    Args:
        value: The input value to convert into an enum member.
        fallback: The value to return if the input cannot be converted. Defaults to `None`.

    Returns:
        The corresponding enum member if conversion succeeds, otherwise the provided `fallback` value.
    """
    with suppress(NotFoundEnumValueError, CustomValueError):
        # Will raise a NotFoundEnumValueError if the value can't be casted
        casted = cls.from_param(value)

        # If unspecified, fallbacks to `fallback` value
        if casted.is_unspecified():
            raise CustomValueError

        return casted

    return fallback

from_res classmethod

from_res(frame: VideoNode | VideoFrame) -> Matrix

Guess the matrix based on the clip's resolution.

Parameters:

  • frame

    (VideoNode | VideoFrame) –

    Input clip or frame.

Returns:

Source code in vstools/enums/color.py
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> Matrix:
    """
    Guess the matrix based on the clip's resolution.

    Args:
        frame: Input clip or frame.

    Returns:
        Matrix object.
    """
    from ..utils import get_var_infos

    fmt, width, height = get_var_infos(frame)

    if fmt.color_family == vs.RGB:
        return Matrix.RGB

    if (width, height) <= (1024, 576):
        return Matrix.ST170_M if height <= 486 else Matrix.BT470_BG

    return Matrix.BT709

from_video classmethod

from_video(
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func: FuncExcept | None = None,
) -> Matrix

Try to obtain the matrix of a clip from the frame props or fallback to clip's resolution if the prop is undefined, strict=False and src is a clip.

Parameters:

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the frame props. Will ALWAYS error with Matrix.UNKNOWN.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Raises:

Source code in vstools/enums/color.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> Matrix:
    """
    Try to obtain the matrix of a clip from the frame props or fallback to clip's resolution
    if the prop is undefined, strict=False and src is a clip.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the frame props. Will ALWAYS error with Matrix.UNKNOWN.
        func: Function returned for custom error handling.

    Returns:
        Matrix object.

    Raises:
        UndefinedMatrixError: If the matrix is undefined or can not be determined from the frameprops.
    """
    return _base_from_video(cls, src, UndefinedMatrixError, strict, func)

is_unspecified

is_unspecified() -> bool

Check if the matrix is Matrix.UNSPECIFIED.

Source code in vstools/enums/color.py
180
181
182
183
184
def is_unspecified(self) -> bool:
    """
    Check if the matrix is Matrix.UNSPECIFIED.
    """
    return self is Matrix.UNSPECIFIED

pretty_string

pretty_string() -> str

Get a pretty, displayable string of the enum member.

Source code in vstools/enums/base.py
45
46
47
48
49
50
@cachedproperty
def pretty_string(self) -> str:
    """
    Get a pretty, displayable string of the enum member.
    """
    return self._pretty_string

prop_key classmethod

prop_key() -> str

The key used in props to store the enum.

Source code in vstools/enums/base.py
59
60
61
62
63
64
65
@classproperty
@classmethod
def prop_key(cls) -> str:
    """
    The key used in props to store the enum.
    """
    return f"_{cls.__name__}"

string

string() -> str

Get the string representation used in resize plugin/encoders.

Source code in vstools/enums/base.py
52
53
54
55
56
57
@cachedproperty
def string(self) -> str:
    """
    Get the string representation used in resize plugin/encoders.
    """
    return self._string

Primaries

Primaries(_: Any, string: str | None = None, pretty_string: str | None = None)

Bases: PropEnum

Color primaries (ITU-T H.265 Table E.3).

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the VideoNode.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param_or_video

    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

  • from_param_with_fallback

    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted

  • from_res

    Guess the primaries based on the clip's resolution.

  • from_video

    Try to obtain the primaries of a clip from the frame props or fallback to clip's resolution

  • is_unspecified

    Check if the primaries are Primaries.UNSPECIFIED.

  • pretty_string

    Get a pretty, displayable string of the enum member.

  • prop_key

    The key used in props to store the enum.

  • string

    Get the string representation used in resize plugin/encoders.

Attributes:

Source code in vstools/enums/base.py
34
35
36
def __init__(self, _: Any, string: str | None = None, pretty_string: str | None = None) -> None:
    self._string = fallback(string, self._name_.lower())
    self._pretty_string = fallback(pretty_string, capwords(self._string.replace("_", " ")))

BT2020 class-attribute instance-attribute

BT2020 = (9, '2020', 'BT.2020')

Rec. ITU-R BT.2020-2

Primary       x      y
Green     0.1700 0.7970
Blue      0.1310 0.0460
Red       0.7080 0.2920
White D65 0.3127 0.3290

Rec. ITU-R BT.2020-2

Rec. ITU-R BT.2100-2

BT470_BG class-attribute instance-attribute

BT470_BG = (5, '470bg', 'BT.470bg')

Rec. ITU-R BT.470-6 System B, G (historical)

Primary      x      y
Green     0.2900 0.6000
Blue      0.1500 0.0600
Red       0.6400 0.3300
White D65 0.3127 0.3290

Rec. ITU-R BT.470-6 System B, G (historical) Rec. ITU-R BT.601-7 625 Rec. ITU-R BT.1358-0 625 (historical) Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM

BT470_M class-attribute instance-attribute

BT470_M = (4, '470m', 'BT.470m')

Rec. ITU-R BT.470-6 System M (historical)

Primary     x      y
Green    0.2100 0.7100
Blue     0.1400 0.0800
Red      0.6700 0.3300
White C  0.3100 0.3160

Rec. ITU-R BT.470-6 System M (historical) NTSC Recommendation for transmission standards for colour television (1953) FCC Title 47 Code of Federal Regulations (2003) 73.682 (a) (20)

BT709 class-attribute instance-attribute

BT709 = (1, '709', 'BT.709')

Rec. ITU-R BT.709-6

Primary      x      y
Green     0.3000 0.6000
Blue      0.1500 0.0600
Red       0.6400 0.3300
White D65 0.3127 0.3290

Rec. ITU-R BT.709-6

Rec. ITU-R BT.1361-0 conventional colour gamutsystem and extended colour gamut system (historical)

IEC 61966-2-1 sRGB or sYCC

IEC 61966-2-4

SMPTE RP 177 (1993) Annex B

EBU3213_E class-attribute instance-attribute

EBU3213_E = (22, 'jedec-p22', 'JEDEC P22 (EBU 3213-E)')

EBU Tech. 3213-E (1975)

Primary      x      y
Green     0.2950 0.6050
Blue      0.1550 0.0770
Red       0.6300 0.3400
White D65 0.3127 0.3290

FILM class-attribute instance-attribute

FILM = (8, 'film', 'Film')

Generic film (colour filters using Illuminant C)

Primary    x      y
Green   0.2430 0.6920 #(Wratten 58)
Blue    0.1450 0.0490 #(Wratten 47)
Red     0.6810 0.3190 #(Wratten 25)
White C 0.3100 0.3160

ST170_M class-attribute instance-attribute

ST170_M = (6, '170m', 'SMPTE ST 170m')

(Functionally the same as Primaries.ST240_M)

Primary      x      y
Green     0.3100 0.5950
Blue      0.1550 0.0700
Red       0.6300 0.3400
White D65 0.3127 0.3290

Rec. ITU-R BT.601-7 525

Rec. ITU-R BT.1358-1 525 or 625 (historical)

Rec. ITU-R BT.1700-0 NTSC

SMPTE ST 170 (2004)

ST240_M class-attribute instance-attribute

ST240_M = (7, '240m', 'SMPTE ST 240m')

SMPTE ST 240 (1999, historical)

(Functionally the same as Primaries.ST170_M)

Primary      x      y
Green     0.3100 0.5950
Blue      0.1550 0.0700
Red       0.6300 0.3400
White D65 0.3127 0.3290

SMPTE ST 240 (1999, historical)

ST428 class-attribute instance-attribute

ST428 = (10, 'st428', 'SMPTE ST 428 (XYZ)')

SMPTE ST 428-1 (2006)

Primary        x   y
Green    (Y)  0.0 1.0
Blue     (Z)  0.0 0.0
Red      (X)  1.0 0.0
Centre White  1/3 1/3

(CIE 1931 XYZ)

ST431_2 class-attribute instance-attribute

ST431_2 = (11, 'st431-2', 'DCI-P3, DCI white point')

SMPTE RP 431-2 (2011)

Primary    x      y
Green   0.2650 0.6900
Blue    0.1500 0.0600
Red     0.6800 0.3200
White   0.3140 0.3510

SMPTE ST 2113 (2019) "P3DCI"

ST432_1 class-attribute instance-attribute

ST432_1 = (12, 'st432-1', 'DCI-P3 D65 white point')

SMPTE EG 432-1 (2010)

Primary      x      y
Green     0.2650 0.6900
Blue      0.1500 0.0600
Red       0.6800 0.3200
White D65 0.3127 0.3290

SMPTE EG 432-1 (2010)

SMPTE ST 2113 (2019) "P3D65"

UNSPECIFIED class-attribute instance-attribute

UNSPECIFIED = (2, 'unspec')

Unspecified.

Image characteristics are unknown or are determined by the application.

XYZ class-attribute instance-attribute

XYZ = ST428

apply

apply(clip: VideoNode) -> VideoNode

Applies the property to the VideoNode.

Source code in vstools/enums/base.py
67
68
69
70
71
def apply(self, clip: vs.VideoNode) -> vs.VideoNode:
    """
    Applies the property to the VideoNode.
    """
    return clip.std.SetFrameProp(self.prop_key, self.value)

ensure_presence classmethod

ensure_presence(
    clip: VideoNode, value: Any, func: FuncExcept | None = None
) -> VideoNode

Ensure the presence of the property in the VideoNode.

Source code in vstools/enums/base.py
153
154
155
156
157
158
159
160
@classmethod
def ensure_presence(cls, clip: vs.VideoNode, value: Any, func: FuncExcept | None = None) -> vs.VideoNode:
    """
    Ensure the presence of the property in the VideoNode.
    """
    enum_value = cls.from_param_or_video(value, clip, True, func)

    return clip.std.SetFrameProp(enum_value.prop_key, enum_value.value)

ensure_presences staticmethod

ensure_presences(
    clip: VideoNode,
    prop_enums: Iterable[type[PropEnum] | PropEnum],
    func: FuncExcept | None = None,
) -> VideoNode

Ensure the presence of multiple PropEnums at once.

Source code in vstools/enums/base.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@staticmethod
def ensure_presences(
    clip: vs.VideoNode, prop_enums: Iterable[type[PropEnum] | PropEnum], func: FuncExcept | None = None
) -> vs.VideoNode:
    """
    Ensure the presence of multiple PropEnums at once.
    """
    return clip.std.SetFrameProps(
        **{
            value.prop_key: value.value
            for value in (
                prop_enum if isinstance(prop_enum, PropEnum) else prop_enum.from_video(clip, True, func)
                for prop_enum in prop_enums
            )
        },
    )

from_param_or_video classmethod

from_param_or_video(
    value: Any,
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self

Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

If strict=False, gather the heuristics using the clip's size or format.

Parameters:

  • value

    (Any) –

    Value to cast.

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Clip to get prop from.

  • strict

    (bool, default: False ) –

    Be strict about the frame properties. Default: False.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Source code in vstools/enums/base.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@classmethod
def from_param_or_video(
    cls,
    value: Any,
    src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

    If `strict=False`, gather the heuristics using the clip's size or format.

    Args:
        value: Value to cast.
        src: Clip to get prop from.
        strict: Be strict about the frame properties. Default: False.
        func_except: Function returned for custom error handling.
    """
    prop = cls.from_param_with_fallback(value, None)

    # Delay the `from_video` call here to avoid unnecessary frame rendering
    if prop is None:
        return cls.from_video(src, strict, func_except)

    return prop

from_param_with_fallback classmethod

from_param_with_fallback(value: Any, fallback: None = None) -> Self | None
from_param_with_fallback(value: Any, fallback: T) -> Self | T
from_param_with_fallback(
    value: Any, fallback: T | None = None
) -> Self | T | None

Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted or represents an unspecified enum member.

Parameters:

  • value

    (Any) –

    The input value to convert into an enum member.

  • fallback

    (T | None, default: None ) –

    The value to return if the input cannot be converted. Defaults to None.

Returns:

  • Self | T | None

    The corresponding enum member if conversion succeeds, otherwise the provided fallback value.

Source code in vstools/enums/base.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@classmethod
def from_param_with_fallback[T](cls, value: Any, fallback: T | None = None) -> Self | T | None:
    """
    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted
    or represents an unspecified enum member.

    Args:
        value: The input value to convert into an enum member.
        fallback: The value to return if the input cannot be converted. Defaults to `None`.

    Returns:
        The corresponding enum member if conversion succeeds, otherwise the provided `fallback` value.
    """
    with suppress(NotFoundEnumValueError, CustomValueError):
        # Will raise a NotFoundEnumValueError if the value can't be casted
        casted = cls.from_param(value)

        # If unspecified, fallbacks to `fallback` value
        if casted.is_unspecified():
            raise CustomValueError

        return casted

    return fallback

from_res classmethod

from_res(frame: VideoNode | VideoFrame) -> Primaries

Guess the primaries based on the clip's resolution.

Parameters:

  • frame

    (VideoNode | VideoFrame) –

    Input clip or frame.

Returns:

Source code in vstools/enums/color.py
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> Primaries:
    """
    Guess the primaries based on the clip's resolution.

    Args:
        frame: Input clip or frame.

    Returns:
        Primaries object.
    """
    from ..utils import get_var_infos

    fmt, width, height = get_var_infos(frame)

    if fmt.color_family == vs.RGB:
        return Primaries.BT709

    if (width, height) <= (1024, 576):
        return Primaries.ST170_M if height <= 486 else Primaries.BT470_BG

    return Primaries.BT709

from_video classmethod

from_video(
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func: FuncExcept | None = None,
) -> Primaries

Try to obtain the primaries of a clip from the frame props or fallback to clip's resolution if the prop is undefined, strict=False and src is a clip.

Parameters:

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the frame props. Will ALWAYS error with Primaries.UNKNOWN.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Raises:

Source code in vstools/enums/color.py
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> Primaries:
    """
    Try to obtain the primaries of a clip from the frame props or fallback to clip's resolution
    if the prop is undefined, strict=False and src is a clip.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the frame props. Will ALWAYS error with Primaries.UNKNOWN.
        func: Function returned for custom error handling.

    Returns:
        Primaries object.

    Raises:
        UndefinedPrimariesError: If the primaries are undefined or can not be determined from the frameprops.
    """
    return _base_from_video(cls, src, UndefinedPrimariesError, strict, func)

is_unspecified

is_unspecified() -> bool

Check if the primaries are Primaries.UNSPECIFIED.

Source code in vstools/enums/color.py
595
596
597
598
599
def is_unspecified(self) -> bool:
    """
    Check if the primaries are Primaries.UNSPECIFIED.
    """
    return self is Primaries.UNSPECIFIED

pretty_string

pretty_string() -> str

Get a pretty, displayable string of the enum member.

Source code in vstools/enums/base.py
45
46
47
48
49
50
@cachedproperty
def pretty_string(self) -> str:
    """
    Get a pretty, displayable string of the enum member.
    """
    return self._pretty_string

prop_key classmethod

prop_key() -> str

The key used in props to store the enum.

Source code in vstools/enums/base.py
59
60
61
62
63
64
65
@classproperty
@classmethod
def prop_key(cls) -> str:
    """
    The key used in props to store the enum.
    """
    return f"_{cls.__name__}"

string

string() -> str

Get the string representation used in resize plugin/encoders.

Source code in vstools/enums/base.py
52
53
54
55
56
57
@cachedproperty
def string(self) -> str:
    """
    Get the string representation used in resize plugin/encoders.
    """
    return self._string

Transfer

Transfer(_: Any, string: str | None = None, pretty_string: str | None = None)

Bases: PropEnum

Transfer characteristics (ITU-T H.265 Table E.4).

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the VideoNode.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param_or_video

    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

  • from_param_with_fallback

    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted

  • from_res

    Guess the transfer based on the clip's resolution.

  • from_video

    Try to obtain the transfer of a clip from the frame props or fallback to clip's resolution

  • is_unspecified

    Check if the transfer is Transfer.UNSPECIFIED.

  • pretty_string

    Get a pretty, displayable string of the enum member.

  • prop_key

    The key used in props to store the enum.

  • string

    Get the string representation used in resize plugin/encoders.

Attributes:

Source code in vstools/enums/base.py
34
35
36
def __init__(self, _: Any, string: str | None = None, pretty_string: str | None = None) -> None:
    self._string = fallback(string, self._name_.lower())
    self._pretty_string = fallback(pretty_string, capwords(self._string.replace("_", " ")))

ARIB_B67 class-attribute instance-attribute

ARIB_B67 = (18, 'std-b67', 'ARIB std-b67 (HLG)')

Association of Radio Industries and Businesses (ARIB) STD-B67

Rec. ITU-R BT.2100-2 hybrid loggamma (HLG) system

BT2020_10 class-attribute instance-attribute

BT2020_10 = (14, '2020_10', 'BT.2020 10 bits')

(Functionally the same as Transfer.BT709, Transfer.BT601, and Transfer.BT2020_12)

Rec. ITU-R BT.2020-2

BT2020_12 class-attribute instance-attribute

BT2020_12 = (15, '2020_12', 'BT.2020 12 bits')

(Functionally the same as Transfer.BT709, Transfer.BT601, and Transfer.BT2020_10)

Rec. ITU-R BT.2020-2

BT470_BG class-attribute instance-attribute

BT470_BG = (5, '470bg', 'BT.470bg')

Rec. ITU-R BT.470-6 System B, G (historical) Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM

BT470_M class-attribute instance-attribute

BT470_M = (4, '470m', 'BT.470m')

Rec. ITU-R BT.470-6 System M (historical) NTSC Recommendation for transmission standards for colour television (1953) FCC, Title 47 Code of Federal Regulations (2003) 73.682 (a) (20)

BT601 class-attribute instance-attribute

BT601 = (6, '601', 'BT.601')

(Functionally the same as Transfer.BT709, Transfer.BT2020_10, and Transfer.BT2020_12) Rec. ITU-R BT.601-7 525 or 625 Rec. ITU-R BT.1358-1 525 or 625 (historical) Rec. ITU-R BT.1700-0 NTSC SMPTE ST 170 (2004)

BT709 class-attribute instance-attribute

BT709 = (1, '709', 'BT.709')

(Functionally the same as Transfer.BT601, Transfer.BT2020_10, and Transfer.BT2020_12) Rec. ITU-R BT.709-6 Rec. ITU-R BT.1361-0 conventional Colour gamut system (historical)

IEC_61966_2_1 class-attribute instance-attribute

IEC_61966_2_1 = (13, 'srgb', 'sRGB')

IEC 61966-2-1 sRGB when matrix is equal to Matrix.RGB

IEC 61966-2-1 sYCC when matrix is equal to Matrix.BT470_BG

IEC_61966_2_4 class-attribute instance-attribute

IEC_61966_2_4 = (11, 'xvycc', 'xvYCC')

IEC 61966-2-4.

LINEAR class-attribute instance-attribute

LINEAR = (8, 'linear', 'Linear')

Linear transfer characteristics.

LOG_100 class-attribute instance-attribute

LOG_100 = (9, 'log100', 'Log 1:100 contrast')

Logarithmic transfer characteristic (100:1 range).

LOG_316 class-attribute instance-attribute

LOG_316 = (10, 'log316', 'Log 1:316 contrast')

Logarithmic transfer characteristic (100 * sqrt(10):1 range).

ST2084 class-attribute instance-attribute

ST2084 = (16, 'st2084', 'SMPTE ST 2084 (PQ)')

SMPTE ST 2084 (2014) for 10, 12, 14, and 16-bit systems

Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system

ST240_M class-attribute instance-attribute

ST240_M = (7, '240m', 'SMPTE ST 240m')

SMPTE ST 240 (1999, historical).

ST428 class-attribute instance-attribute

ST428 = (17, 'st428', 'SMPTE ST 428-1')

SMPTE ST 428-1

UNSPECIFIED class-attribute instance-attribute

UNSPECIFIED = (2, 'unspec')

Unspecified.

Image characteristics are unknown or are determined by the application.

apply

apply(clip: VideoNode) -> VideoNode

Applies the property to the VideoNode.

Source code in vstools/enums/base.py
67
68
69
70
71
def apply(self, clip: vs.VideoNode) -> vs.VideoNode:
    """
    Applies the property to the VideoNode.
    """
    return clip.std.SetFrameProp(self.prop_key, self.value)

ensure_presence classmethod

ensure_presence(
    clip: VideoNode, value: Any, func: FuncExcept | None = None
) -> VideoNode

Ensure the presence of the property in the VideoNode.

Source code in vstools/enums/base.py
153
154
155
156
157
158
159
160
@classmethod
def ensure_presence(cls, clip: vs.VideoNode, value: Any, func: FuncExcept | None = None) -> vs.VideoNode:
    """
    Ensure the presence of the property in the VideoNode.
    """
    enum_value = cls.from_param_or_video(value, clip, True, func)

    return clip.std.SetFrameProp(enum_value.prop_key, enum_value.value)

ensure_presences staticmethod

ensure_presences(
    clip: VideoNode,
    prop_enums: Iterable[type[PropEnum] | PropEnum],
    func: FuncExcept | None = None,
) -> VideoNode

Ensure the presence of multiple PropEnums at once.

Source code in vstools/enums/base.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@staticmethod
def ensure_presences(
    clip: vs.VideoNode, prop_enums: Iterable[type[PropEnum] | PropEnum], func: FuncExcept | None = None
) -> vs.VideoNode:
    """
    Ensure the presence of multiple PropEnums at once.
    """
    return clip.std.SetFrameProps(
        **{
            value.prop_key: value.value
            for value in (
                prop_enum if isinstance(prop_enum, PropEnum) else prop_enum.from_video(clip, True, func)
                for prop_enum in prop_enums
            )
        },
    )

from_param_or_video classmethod

from_param_or_video(
    value: Any,
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self

Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

If strict=False, gather the heuristics using the clip's size or format.

Parameters:

  • value

    (Any) –

    Value to cast.

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Clip to get prop from.

  • strict

    (bool, default: False ) –

    Be strict about the frame properties. Default: False.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Source code in vstools/enums/base.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@classmethod
def from_param_or_video(
    cls,
    value: Any,
    src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

    If `strict=False`, gather the heuristics using the clip's size or format.

    Args:
        value: Value to cast.
        src: Clip to get prop from.
        strict: Be strict about the frame properties. Default: False.
        func_except: Function returned for custom error handling.
    """
    prop = cls.from_param_with_fallback(value, None)

    # Delay the `from_video` call here to avoid unnecessary frame rendering
    if prop is None:
        return cls.from_video(src, strict, func_except)

    return prop

from_param_with_fallback classmethod

from_param_with_fallback(value: Any, fallback: None = None) -> Self | None
from_param_with_fallback(value: Any, fallback: T) -> Self | T
from_param_with_fallback(
    value: Any, fallback: T | None = None
) -> Self | T | None

Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted or represents an unspecified enum member.

Parameters:

  • value

    (Any) –

    The input value to convert into an enum member.

  • fallback

    (T | None, default: None ) –

    The value to return if the input cannot be converted. Defaults to None.

Returns:

  • Self | T | None

    The corresponding enum member if conversion succeeds, otherwise the provided fallback value.

Source code in vstools/enums/base.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@classmethod
def from_param_with_fallback[T](cls, value: Any, fallback: T | None = None) -> Self | T | None:
    """
    Attempts to obtain an enum member from a parameter value, returning a fallback if the value cannot be converted
    or represents an unspecified enum member.

    Args:
        value: The input value to convert into an enum member.
        fallback: The value to return if the input cannot be converted. Defaults to `None`.

    Returns:
        The corresponding enum member if conversion succeeds, otherwise the provided `fallback` value.
    """
    with suppress(NotFoundEnumValueError, CustomValueError):
        # Will raise a NotFoundEnumValueError if the value can't be casted
        casted = cls.from_param(value)

        # If unspecified, fallbacks to `fallback` value
        if casted.is_unspecified():
            raise CustomValueError

        return casted

    return fallback

from_res classmethod

from_res(frame: VideoNode | VideoFrame) -> Transfer

Guess the transfer based on the clip's resolution.

Parameters:

  • frame

    (VideoNode | VideoFrame) –

    Input clip or frame.

Returns:

Source code in vstools/enums/color.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> Transfer:
    """
    Guess the transfer based on the clip's resolution.

    Args:
        frame: Input clip or frame.

    Returns:
        Transfer object.
    """
    from ..utils import get_var_infos

    fmt, width, height = get_var_infos(frame)

    if fmt.color_family == vs.RGB:
        return Transfer.IEC_61966_2_1

    return Transfer.BT601 if (width, height) <= (1024, 576) else Transfer.BT709

from_video classmethod

from_video(
    src: VideoNode | VideoFrame | Mapping[str, Any],
    strict: bool = False,
    func: FuncExcept | None = None,
) -> Transfer

Try to obtain the transfer of a clip from the frame props or fallback to clip's resolution if the prop is undefined, strict=False and src is a clip.

Parameters:

  • src

    (VideoNode | VideoFrame | Mapping[str, Any]) –

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the properties. The result may NOT be Transfer.UNKNOWN.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Raises:

Source code in vstools/enums/color.py
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> Transfer:
    """
    Try to obtain the transfer of a clip from the frame props or fallback to clip's resolution
    if the prop is undefined, strict=False and src is a clip.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the properties. The result may NOT be Transfer.UNKNOWN.
        func: Function returned for custom error handling.

    Returns:
        Transfer object.

    Raises:
        UndefinedTransferError: If the transfer is undefined or can not be determined from the frameprops.
    """
    return _base_from_video(cls, src, UndefinedTransferError, strict, func)

is_unspecified

is_unspecified() -> bool

Check if the transfer is Transfer.UNSPECIFIED.

Source code in vstools/enums/color.py
345
346
347
348
349
def is_unspecified(self) -> bool:
    """
    Check if the transfer is Transfer.UNSPECIFIED.
    """
    return self is Transfer.UNSPECIFIED

pretty_string

pretty_string() -> str

Get a pretty, displayable string of the enum member.

Source code in vstools/enums/base.py
45
46
47
48
49
50
@cachedproperty
def pretty_string(self) -> str:
    """
    Get a pretty, displayable string of the enum member.
    """
    return self._pretty_string

prop_key classmethod

prop_key() -> str

The key used in props to store the enum.

Source code in vstools/enums/base.py
59
60
61
62
63
64
65
@classproperty
@classmethod
def prop_key(cls) -> str:
    """
    The key used in props to store the enum.
    """
    return f"_{cls.__name__}"

string

string() -> str

Get the string representation used in resize plugin/encoders.

Source code in vstools/enums/base.py
52
53
54
55
56
57
@cachedproperty
def string(self) -> str:
    """
    Get the string representation used in resize plugin/encoders.
    """
    return self._string