Skip to content

normalize

Functions:

flatten

flatten(items: Iterable[Iterable[T]]) -> Iterator[T]
flatten(items: Iterable[Any]) -> Iterator[Any]
flatten(items: Any) -> Iterator[Any]
flatten(items: Any) -> Iterator[Any]

Flatten an array of values, clips and frames included.

Source code
82
83
84
85
86
87
88
def flatten(items: Any) -> Iterator[Any]:
    """Flatten an array of values, clips and frames included."""

    if isinstance(items, (vs.RawNode, vs.RawFrame)):
        yield items
    else:
        yield from jetp_flatten(items)

flatten_vnodes

flatten_vnodes(
    *clips: VideoNodeIterableT[VideoNodeT], split_planes: Literal[False] = ...
) -> Sequence[VideoNodeT]
flatten_vnodes(
    *clips: VideoNodeIterableT[VideoNodeT], split_planes: Literal[True] = ...
) -> Sequence[ConstantFormatVideoNode]
flatten_vnodes(
    *clips: VideoNodeIterableT[VideoNodeT], split_planes: bool = ...
) -> Sequence[VideoNodeT]
flatten_vnodes(
    *clips: VideoNodeIterableT[VideoNodeT], split_planes: bool = False
) -> Sequence[VideoNode]

Flatten an array of VideoNodes.

Parameters:

  • clips

    (VideoNodeIterableT[VideoNodeT], default: () ) –

    An array of clips to flatten into a list.

  • split_planes

    (bool, default: False ) –

    Optionally split the VideoNodes into their individual planes as well. Default: False.

Returns:

  • Sequence[VideoNode]

    Flattened list of VideoNodes.

Source code
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def flatten_vnodes(
    *clips: VideoNodeIterableT[VideoNodeT], split_planes: bool = False
) -> Sequence[vs.VideoNode]:
    """
    Flatten an array of VideoNodes.

    :param clips:           An array of clips to flatten into a list.
    :param split_planes:    Optionally split the VideoNodes into their individual planes as well.
                            Default: False.

    :return:                Flattened list of VideoNodes.
    """

    from .utils import split

    nodes = list[VideoNodeT](flatten(clips))

    if not split_planes:
        return nodes

    return sum(map(split, nodes), list[ConstantFormatVideoNode]())

invert_ranges

invert_ranges(
    clipa: VideoNode,
    clipb: VideoNode | None,
    ranges: FrameRangeN | FrameRangesN,
) -> list[tuple[int, int]]

Invert FrameRanges.

Example:

.. code-block:: python

>>> franges = [(100, 200), 600, (1200, 2400)]
>>> invert_ranges(core.std.BlankClip(length=10000), core.std.BlankClip(length=10000), franges)
[(0, 99), (201, 599), (601, 1199), (2401, 9999)]

Parameters:

  • clipa

    (VideoNode) –

    Original clip.

  • clipb

    (VideoNode | None) –

    Replacement clip.

  • ranges

    (FrameRangeN | FrameRangesN) –

    Ranges to replace clipa (original clip) with clipb (replacement clip). These ranges will be inverted. For more info, see replace_ranges.

Returns:

Source code
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def invert_ranges(
    clipa: vs.VideoNode, clipb: vs.VideoNode | None, ranges: FrameRangeN | FrameRangesN
) -> list[tuple[int, int]]:
    """
    Invert FrameRanges.

    Example:

    .. code-block:: python

        >>> franges = [(100, 200), 600, (1200, 2400)]
        >>> invert_ranges(core.std.BlankClip(length=10000), core.std.BlankClip(length=10000), franges)
        [(0, 99), (201, 599), (601, 1199), (2401, 9999)]

    :param clipa:          Original clip.
    :param clipb:          Replacement clip.
    :param ranges:         Ranges to replace clipa (original clip) with clipb (replacement clip).
                           These ranges will be inverted. For more info, see `replace_ranges`.

    :return:                A list of inverted frame ranges.
    """

    return jetp_invert_ranges(ranges, clipa.num_frames, None if clipb is None else clipb.num_frames)

normalize_planes

normalize_planes(clip: VideoNode, planes: PlanesT = None) -> list[int]

Normalize a sequence of planes.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • planes

    (PlanesT, default: None ) –

    Array of planes. If None, returns all planes of the input clip's format. Default: None.

Returns:

  • list[int]

    Sorted list of planes.

Source code
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def normalize_planes(clip: vs.VideoNode, planes: PlanesT = None) -> list[int]:
    """
    Normalize a sequence of planes.

    :param clip:        Input clip.
    :param planes:      Array of planes. If None, returns all planes of the input clip's format.
                        Default: None.

    :return:            Sorted list of planes.
    """

    assert clip.format

    if planes is None or planes == 4:
        planes = list(range(clip.format.num_planes))
    else:
        planes = to_arr(planes)

    return list(sorted(set(planes).intersection(range(clip.format.num_planes))))

normalize_ranges

normalize_ranges(
    clip: VideoNode, ranges: FrameRangeN | FrameRangesN
) -> list[tuple[int, int]]

Normalize ranges to a list of positive ranges.

Frame ranges can include None and negative values. None will be converted to either 0 if it's the first value in a FrameRange, or the clip's length if it's the second item. Negative values will be subtracted from the clip's length.

Examples:

.. code-block:: python

>>> clip.num_frames
1000
>>> normalize_ranges(clip, (None, None))
[(0, 999)]
>>> normalize_ranges(clip, (24, -24))
[(24, 975)]
>>> normalize_ranges(clip, [(24, 100), (80, 150)])
[(24, 150)]

Parameters:

Returns:

Source code
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def normalize_ranges(clip: vs.VideoNode, ranges: FrameRangeN | FrameRangesN) -> list[tuple[int, int]]:
    """
    Normalize ranges to a list of positive ranges.

    Frame ranges can include `None` and negative values.
    None will be converted to either 0 if it's the first value in a FrameRange,
    or the clip's length if it's the second item.
    Negative values will be subtracted from the clip's length.

    Examples:

    .. code-block:: python

        >>> clip.num_frames
        1000
        >>> normalize_ranges(clip, (None, None))
        [(0, 999)]
        >>> normalize_ranges(clip, (24, -24))
        [(24, 975)]
        >>> normalize_ranges(clip, [(24, 100), (80, 150)])
        [(24, 150)]


    :param clip:        Input clip.
    :param ranges:      Frame range or list of frame ranges.

    :return:            List of positive frame ranges.
    """

    return jetp_normalize_ranges(ranges, clip.num_frames)

normalize_seq

normalize_seq(val: T | Sequence[T], length: int = 3) -> list[T]
normalize_seq(val: Any, length: int = 3) -> list[Any]
normalize_seq(val: T | Sequence[T], length: int = 3) -> list[T]

Normalize a sequence to the given length.

Source code
40
41
42
43
def normalize_seq(val: T | Sequence[T], length: int = 3) -> list[T]:
    """Normalize a sequence to the given length."""

    return jetp_normalize_seq(val, length)