Skip to content

generic

Type Aliases:

Classes:

  • ChromaLocation

    Chroma sample position in YUV formats.

  • Field

    Indicates which field (top or bottom) was used to generate the current frame.

  • FieldBased

    Whether the frame is composed of two independent fields (interlaced) and their order if so.

Attributes:

ChromaLocationT module-attribute

ChromaLocationT = ChromaLocationLike

Deprecated alias of ChromaLocationLike

FieldBasedT module-attribute

FieldBasedT = FieldBasedLike

Deprecated alias of FieldBasedT = FieldBasedLike

ChromaLocationLike

ChromaLocationLike = int | ChromaLocation | ChromaLocation

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

FieldBasedLike

FieldBasedLike = int | FieldBased | FieldBased

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

FieldLike

FieldLike = int | Field

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

ChromaLocation

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

Bases: PropEnum

Chroma sample position in YUV formats.

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 chroma location based on the clip's resolution.

  • from_video

    Obtain the chroma location of a clip from the frame properties.

  • get_offsets

    Get (left,top) shift for chroma relative to luma.

  • 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:

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("_", " ")))

BOTTOM class-attribute instance-attribute

BOTTOM = 5

BOTTOM_LEFT class-attribute instance-attribute

BOTTOM_LEFT = 4

CENTER class-attribute instance-attribute

CENTER = 1

LEFT class-attribute instance-attribute

LEFT = 0

TOP class-attribute instance-attribute

TOP = 3

TOP_LEFT class-attribute instance-attribute

TOP_LEFT = 2

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) -> ChromaLocation

Guess the chroma location based on the clip's resolution.

Parameters:

  • frame

    (VideoNode | VideoFrame) –

    Input clip or frame.

Returns:

Source code in vstools/enums/generic.py
62
63
64
65
66
67
68
69
70
71
72
73
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> ChromaLocation:
    """
    Guess the chroma location based on the clip's resolution.

    Args:
        frame: Input clip or frame.

    Returns:
        ChromaLocation object.
    """
    return ChromaLocation.LEFT

from_video classmethod

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

Obtain the chroma location of a clip from the frame properties.

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 an unknown value.

Returns:

Raises:

Source code in vstools/enums/generic.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> ChromaLocation:
    """
    Obtain the chroma location of a clip from the frame properties.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the properties. The result may NOT be an unknown value.

    Returns:
        ChromaLocation object.

    Raises:
        UndefinedChromaLocationError: If chroma location is undefined or chroma location can not be determined
            from the frame properties.
    """
    return _base_from_video(cls, src, UndefinedChromaLocationError, strict, func)

get_offsets

Get (left,top) shift for chroma relative to luma.

This is only useful if you MUST use a pre-specified chroma location and shift the chroma yourself.

Source code in vstools/enums/generic.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_offsets(self, src: SupportsInt | VideoFormatLike | HoldsVideoFormat) -> tuple[float, float]:
    """
    Get (left,top) shift for chroma relative to luma.

    This is only useful if you MUST use a pre-specified chroma location and shift the chroma yourself.
    """
    from ..utils import get_video_format

    fmt = get_video_format(src)

    off_left = off_top = 0.0

    if self in [ChromaLocation.LEFT, ChromaLocation.TOP_LEFT, ChromaLocation.BOTTOM_LEFT]:
        off_left = 0.5 - 2 ** (fmt.subsampling_w - 1)

    if self in [ChromaLocation.TOP, ChromaLocation.TOP_LEFT]:
        off_top = 0.5 - 2 ** (fmt.subsampling_h - 1)
    elif self in [ChromaLocation.BOTTOM, ChromaLocation.BOTTOM_LEFT]:
        off_top = 2 ** (fmt.subsampling_h - 1) - 0.5

    return off_left, off_top

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

Field

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

Bases: PropEnum

Indicates which field (top or bottom) was used to generate the current frame.

This property is typically set when the frame is produced by a function such as .std.SeparateFields.

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

    Get an enum member from the video resolution with heuristics.

  • from_video

    Obtain the Field of a clip from the frame properties.

  • 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:

  • BOTTOM

    Frame generated from the bottom field.

  • TOP

    Frame generated from the top field.

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("_", " ")))

BOTTOM class-attribute instance-attribute

BOTTOM = 0

Frame generated from the bottom field.

TOP class-attribute instance-attribute

TOP = 1

Frame generated from the top field.

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) -> NoReturn

Get an enum member from the video resolution with heuristics.

Source code in vstools/enums/generic.py
239
240
241
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> NoReturn:
    raise CustomNotImplementedError

from_video classmethod

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

Obtain the Field of a clip from the frame properties.

Parameters:

  • src

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

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the properties. Will ALWAYS error if the Field is missing.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Field

    Field object.

Raises:

  • UndefinedFieldError

    if the Field is undefined or can not be determined from the frame properties.

Source code in vstools/enums/generic.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> Field:
    """
    Obtain the Field of a clip from the frame properties.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the properties. Will ALWAYS error if the Field is missing.
        func: Function returned for custom error handling.

    Returns:
        Field object.

    Raises:
        UndefinedFieldError: if the Field is undefined or can not be determined from the frame properties.
    """
    return _base_from_video(cls, src, UndefinedFieldError, strict, func)

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

FieldBased

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

Bases: PropEnum

Whether the frame is composed of two independent fields (interlaced) and their order if so.

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the clip.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param

    Determine the type of field through a parameter.

  • 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 Field order from the frame resolution.

  • from_video

    Obtain the Field order of a clip from the frame properties.

  • is_inter

    Check whether the value belongs to an interlaced value.

  • is_tff

    Check whether the value is Top-Field-First.

  • is_unspecified

    Whether the value is unspecified.

  • prop_key

    The key used in props to store the enum.

  • string

    Get the string representation used in resize plugin/encoders.

Attributes:

  • BFF

    The frame is interlaced and the field order is bottom field first.

  • PROGRESSIVE

    The frame is progressive.

  • TFF

    The frame is interlaced and the field order is top field first.

  • field (Field) –

    Check what field the enum signifies.

  • inverted_field (FieldBased) –

    Get the inverted field order.

  • pretty_string (str) –

    Get a pretty, displayable string of the enum member.

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("_", " ")))

BFF class-attribute instance-attribute

BFF = 1

The frame is interlaced and the field order is bottom field first.

PROGRESSIVE class-attribute instance-attribute

PROGRESSIVE = 0

The frame is progressive.

TFF class-attribute instance-attribute

TFF = 2

The frame is interlaced and the field order is top field first.

field property

field: Field

Check what field the enum signifies.

Raises:

inverted_field property

inverted_field: FieldBased

Get the inverted field order.

Raises:

pretty_string property

pretty_string: str

Get a pretty, displayable string of the enum member.

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 clip.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • value

    (Any) –

    Value or FieldBased object. If it's bool, it specifies whether it's TFF or BFF.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • VideoNode

    Clip with the FieldBased set.

Source code in vstools/enums/generic.py
210
211
212
213
214
215
216
217
218
219
220
221
222
223
@classmethod
def ensure_presence(cls, clip: vs.VideoNode, value: Any, func: FuncExcept | None = None) -> vs.VideoNode:
    """
    Ensure the presence of the property in the clip.

    Args:
        clip: Input clip.
        value: Value or FieldBased object. If it's bool, it specifies whether it's TFF or BFF.
        func: Function returned for custom error handling.

    Returns:
        Clip with the FieldBased set.
    """
    return clip.std.SetFieldBased(cls.from_param_or_video(value, clip, True, func))

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 classmethod

from_param(value: Any, func_except: FuncExcept | None = None) -> FieldBased

Determine the type of field through a parameter.

Parameters:

  • value

    (Any) –

    Value or FieldBased object. If it's bool, it specifies whether it's TFF or BFF.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vstools/enums/generic.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@classmethod
def from_param(cls, value: Any, func_except: FuncExcept | None = None) -> FieldBased:
    """
    Determine the type of field through a parameter.

    Args:
        value: Value or FieldBased object. If it's bool, it specifies whether it's TFF or BFF.
        func_except: Function returned for custom error handling.

    Returns:
        FieldBased object.
    """
    if isinstance(value, bool):
        return cls(1 + value)

    return super().from_param(value, func_except)

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) -> FieldBased

Guess the Field order from the frame resolution.

Source code in vstools/enums/generic.py
182
183
184
185
186
187
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> FieldBased:
    """
    Guess the Field order from the frame resolution.
    """
    return cls.PROGRESSIVE

from_video classmethod

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

Obtain the Field order of a clip from the frame properties.

Parameters:

  • src

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

    Input clip, frame, or props.

  • strict

    (bool, default: False ) –

    Be strict about the properties. Will ALWAYS error if the FieldBased is missing.

  • func

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Raises:

Source code in vstools/enums/generic.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | Mapping[str, Any], strict: bool = False, func: FuncExcept | None = None
) -> FieldBased:
    """
    Obtain the Field order of a clip from the frame properties.

    Args:
        src: Input clip, frame, or props.
        strict: Be strict about the properties. Will ALWAYS error if the FieldBased is missing.
        func: Function returned for custom error handling.

    Returns:
        FieldBased object.

    Raises:
        UndefinedFieldBasedError: If the Field order is undefined or can not be determined
            from the frame properties.
    """
    return _base_from_video(cls, src, UndefinedFieldBasedError, strict, func)

is_inter

is_inter() -> bool

Check whether the value belongs to an interlaced value.

Source code in vstools/enums/generic.py
153
154
155
156
157
def is_inter(self) -> bool:
    """
    Check whether the value belongs to an interlaced value.
    """
    return self != FieldBased.PROGRESSIVE

is_tff

is_tff() -> bool

Check whether the value is Top-Field-First.

Source code in vstools/enums/generic.py
159
160
161
162
163
def is_tff(self) -> bool:
    """
    Check whether the value is Top-Field-First.
    """
    return self is self.TFF

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

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