Skip to content

check

Functions:

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:

Source code
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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.

    Args:
        clip: Clip to check.
        width: Output width.
        height: Output height.
        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 and (
        (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={"width": width, "height": height},
        )

check_progressive

check_progressive(clip: VideoNodeT, func: FuncExceptT) -> TypeGuard[VideoNodeT]

Check if the clip is progressive and return an error if it's not.

Parameters:

  • clip

    (VideoNodeT) –

    Clip to check.

  • func

    (FuncExceptT) –

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

Raises:

Source code
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def check_progressive(clip: VideoNodeT, func: FuncExceptT) -> TypeGuard[VideoNodeT]:
    """
    Check if the clip is progressive and return an error if it's not.

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

    Raises:
        UnsupportedFieldBasedError: The clip is interlaced.
    """

    if FieldBased.from_video(clip, func=func).is_inter:
        raise UnsupportedFieldBasedError("Only progressive video is supported!", func)

    return True

check_ref_clip

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

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.

Raises:

Returns:

  • ConstantFormatVideoNode

    Ref clip.

Source code
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def check_ref_clip(
    src: vs.VideoNode, ref: vs.VideoNode | None, func: FuncExceptT | None = None
) -> ConstantFormatVideoNode:
    """
    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.

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

    Raises:
        VariableFormatError: The format of either clip is variable.
        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.

    Returns:
        Ref clip.
    """
    func = func or check_ref_clip

    assert check_variable(src, func)

    if ref is None:
        return src

    assert check_variable(ref, func)

    FormatsRefClipMismatchError.check(func, src, ref)
    ResolutionsRefClipMismatchError.check(func, src, ref)

    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:

Source code
106
107
108
109
110
111
112
113
114
115
116
117
118
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.
        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_variable_format(
    clip: Sequence[VideoNode], func: FuncExceptT
) -> TypeGuard[Sequence[ConstantFormatVideoNode]]
check_variable_format(
    clip: VideoNode | Sequence[VideoNode], func: FuncExceptT
) -> (
    TypeGuard[ConstantFormatVideoNode]
    | TypeGuard[Sequence[ConstantFormatVideoNode]]
)

Check for variable format and return an error if found.

Raises:

Source code
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def check_variable_format(
    clip: vs.VideoNode | Sequence[vs.VideoNode], func: FuncExceptT
) -> TypeGuard[ConstantFormatVideoNode] | TypeGuard[Sequence[ConstantFormatVideoNode]]:
    """
    Check for variable format and return an error if found.

    Raises:
        VariableFormatError: The clip is of a variable format.
    """
    clip = [clip] if isinstance(clip, vs.VideoNode) else clip

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

    return True

check_variable_resolution

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

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

Raises:

Source code
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def check_variable_resolution(clip: VideoNodeT, func: FuncExceptT) -> TypeGuard[VideoNodeT]:
    """
    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