Skip to content

check

check_correct_subsampling

check_correct_subsampling(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    func: FuncExceptT | None = None,
) -> None

Check if the subsampling is correct and return an error if it's not.

Parameters:

  • clip

    (VideoNode) –

    Clip to check.

  • width

    (int | None, default: None ) –

    Output width.

  • height

    (int | None, default: None ) –

    Output height.

  • func

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling. This should only be set by VS package developers.

Raises:

  • InvalidSubsamplingError

    The clip has invalid subsampling.

Source code
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def check_correct_subsampling(
    clip: vs.VideoNode, width: int | None = None, height: int | None = None, func: FuncExceptT | None = None
) -> None:
    """
    Check if the subsampling is correct and return an error if it's not.

    :param clip:                        Clip to check.
    :param width:                       Output width.
    :param height:                      Output height.
    :param func:                        Function returned for custom error handling.
                                        This should only be set by VS package developers.

    :raises InvalidSubsamplingError:    The clip has invalid subsampling.
    """
    from ..exceptions import InvalidSubsamplingError

    if clip.format:
        if (
            (width is not None and width % (1 << clip.format.subsampling_w))
            or (height is not None and height % (1 << clip.format.subsampling_h))
        ):
            raise InvalidSubsamplingError(
                func or check_correct_subsampling, clip,
                'The {subsampling} subsampling is not supported for this resolution!',
                reason=dict(width=width, height=height)
            )

check_ref_clip

check_ref_clip(
    src: VideoNode, ref: VideoNode | None, func: FuncExceptT | None = None
) -> VideoNode

Function for ensuring the ref clip's format matches that of the input clip.

If no ref clip can be found, this function will simply do nothing.

Parameters:

  • src

    (VideoNode) –

    Input clip.

  • ref

    (VideoNode | None) –

    Reference clip. Default: None.

Returns:

  • VideoNode

    Ref clip.

Raises:

  • VariableResolutionError

    The resolution of either clip is variable.

  • FormatsRefClipMismatchError

    The formats of the two clips do not match.

  • ResolutionsRefClipMismatchError

    The resolutions of the two clips do not match.

Source code
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def check_ref_clip(src: vs.VideoNode, ref: vs.VideoNode | None, func: FuncExceptT | None = None) -> vs.VideoNode:
    """
    Function for ensuring the ref clip's format matches that of the input clip.

    If no ref clip can be found, this function will simply do nothing.

    :param src:     Input clip.
    :param ref:     Reference clip.
                    Default: None.

    :raises VariableFormatError                 The format of either clip is variable.
    :raises VariableResolutionError:            The resolution of either clip is variable.
    :raises FormatsRefClipMismatchError:        The formats of the two clips do not match.
    :raises ResolutionsRefClipMismatchError:    The resolutions of the two clips do not match.

    :return:        Ref clip.
    """

    from .funcs import fallback

    if ref is None:
        return src

    func = fallback(func, check_ref_clip)

    assert check_variable(src, func)  # type: ignore
    assert check_variable(ref, func)  # type: ignore

    FormatsRefClipMismatchError.check(func, src, ref)  # type: ignore
    ResolutionsRefClipMismatchError.check(func, src, ref)  # type: ignore

    return ref

check_variable

check_variable(
    clip: VideoNode, func: FuncExceptT
) -> TypeGuard[ConstantFormatVideoNode]

Check for variable format and a variable resolution and return an error if found.

Raises:

  • VariableFormatError

    The clip is of a variable format.

  • VariableResolutionError

    The clip has a variable resolution.

Source code
167
168
169
170
171
172
173
174
175
176
177
178
def check_variable(clip: vs.VideoNode, func: FuncExceptT) -> TypeGuard[ConstantFormatVideoNode]:
    """
    Check for variable format and a variable resolution and return an error if found.

    :raises VariableFormatError:        The clip is of a variable format.
    :raises VariableResolutionError:    The clip has a variable resolution.
    """

    check_variable_format(clip, func)
    check_variable_resolution(clip, func)

    return True

check_variable_format

check_variable_format(
    clip: VideoNode, func: FuncExceptT
) -> TypeGuard[ConstantFormatVideoNode]

Check for variable format and return an error if found.

Raises:

  • VariableFormatError

    The clip is of a variable format.

Source code
141
142
143
144
145
146
147
148
149
150
151
def check_variable_format(clip: vs.VideoNode, func: FuncExceptT) -> TypeGuard[ConstantFormatVideoNode]:
    """
    Check for variable format and return an error if found.

    :raises VariableFormatError:    The clip is of a variable format.
    """

    if clip.format is None:
        raise VariableFormatError(func)

    return True

check_variable_resolution

check_variable_resolution(
    clip: VideoNode, func: FuncExceptT
) -> TypeGuard[VideoNode]

Check for variable width or height and return an error if found.

Raises:

  • VariableResolutionError

    The clip has a variable resolution.

Source code
154
155
156
157
158
159
160
161
162
163
164
def check_variable_resolution(clip: vs.VideoNode, func: FuncExceptT) -> TypeGuard[vs.VideoNode]:
    """
    Check for variable width or height and return an error if found.

    :raises VariableResolutionError:    The clip has a variable resolution.
    """

    if 0 in (clip.width, clip.height):
        raise VariableResolutionError(func)

    return True

disallow_variable_format

disallow_variable_format(*, only_first: bool = False) -> Callable[[F], F]
disallow_variable_format(function: F | None = None) -> F
disallow_variable_format(
    function: F | None = None, /, *, only_first: bool = False
) -> Callable[[F], F] | F

Decorator for disallowing clips with variable formats.

Parameters:

  • only_first

    (bool, default: False ) –

    Only verify the format of the first argument. Default: False.

Raises:

  • VariableFormatError

    A clip with a variable format is found.

Source code
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def disallow_variable_format(function: F | None = None, /, *, only_first: bool = False) -> Callable[[F], F] | F:
    """
    Decorator for disallowing clips with variable formats.

    :param only_first:              Only verify the format of the first argument.
                                    Default: False.

    :raises VariableFormatError:    A clip with a variable format is found.
    """

    if function is None:
        return cast(Callable[[F], F], partial(disallow_variable_format, only_first=only_first))

    return _check_variable(
        function, 'format', VariableFormatError, only_first, lambda x: x.format is None
    )

disallow_variable_resolution

disallow_variable_resolution(*, only_first: bool = False) -> Callable[[F], F]
disallow_variable_resolution(func: F | None = None) -> F
disallow_variable_resolution(
    function: F | None = None, /, *, only_first: bool = False
) -> Callable[[F], F] | F

Decorator for disallowing clips with variable resolutions.

Parameters:

  • only_first

    (bool, default: False ) –

    Only verify the resolution of the first argument. Default: False.

Raises:

  • VariableResolutionError

    A clip with a variable resolution is found.

Source code
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def disallow_variable_resolution(function: F | None = None, /, *, only_first: bool = False) -> Callable[[F], F] | F:
    """
    Decorator for disallowing clips with variable resolutions.

    :param only_first:                  Only verify the resolution of the first argument.
                                        Default: False.

    :raises VariableResolutionError:    A clip with a variable resolution is found.
    """

    if function is None:
        return cast(Callable[[F], F], partial(disallow_variable_resolution, only_first=only_first))

    return _check_variable(
        function, 'resolution', VariableResolutionError, only_first, lambda x: not all({x.width, x.height})
    )