Skip to content

misc

Classes:

Functions:

  • change_fps

    Convert the framerate of a clip.

  • match_clip

    Try to match the formats, dimensions, etc. of a reference clip to match the original clip.

  • pick_func_stype

    Pick the function matching the sample type of the clip's format.

  • set_output

    Set output node with optional index and name, and if available, use vspreview set_output.

SceneAverageStats

SceneAverageStats(
    clip: VideoNode,
    keyframes: Keyframes | str,
    prop: str = "SceneStats",
    plane: int = 0,
    cache_size: int = 5,
)

Bases: SceneBasedDynamicCache

Classes:

Methods:

Attributes:

Source code
685
686
687
688
689
690
691
692
693
694
695
696
def __init__(
    self,
    clip: vs.VideoNode,
    keyframes: Keyframes | str,
    prop: str = "SceneStats",
    plane: int = 0,
    cache_size: int = 5,
) -> None:
    super().__init__(clip, keyframes, cache_size)

    self.prop_keys = tuple(f"{prop}{x}" for x in self._props_keys)
    self.scene_avgs = self.__class__.cache(self.clip, self.keyframes, plane)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

keyframes instance-attribute

keyframes = from_param(clip, keyframes)

prop_keys instance-attribute

prop_keys = tuple(f'{prop}{x}' for x in _props_keys)

scene_avgs instance-attribute

scene_avgs = cache(clip, keyframes, plane)

cache

cache(clip: VideoNode, keyframes: Keyframes, plane: int)

Bases: dict[int, tuple[float, float, float]]

Attributes:

Source code
664
665
666
def __init__(self, clip: vs.VideoNode, keyframes: Keyframes, plane: int) -> None:
    self.props = clip.std.PlaneStats(plane=plane)
    self.keyframes = keyframes

keyframes instance-attribute

keyframes = keyframes

props instance-attribute

props = PlaneStats(plane=plane)

from_clip classmethod

from_clip(
    clip: VideoNode, keyframes: Keyframes | str, *args: Any, **kwargs: Any
) -> VideoNode
Source code
126
127
128
@classmethod
def from_clip(cls, clip: vs.VideoNode, keyframes: Keyframes | str, *args: Any, **kwargs: Any) -> vs.VideoNode:
    return cls(clip, keyframes, *args, **kwargs).get_eval()

get_clip

get_clip(key: int) -> VideoNode
Source code
698
699
def get_clip(self, key: int) -> vs.VideoNode:
    return self.clip.std.SetFrameProps(**dict(zip(self.prop_keys, self.scene_avgs[key])))

get_eval

get_eval() -> VideoNode
Source code
123
124
def get_eval(self) -> vs.VideoNode:
    return self.clip.std.FrameEval(lambda n: self[self.keyframes.scenes.indices[n]])

padder

Pad out the pixels on the sides by the given amount of pixels.

Methods:

  • COLOR

    Pad a clip with a constant color.

  • MIRROR

    Pad a clip with reflect mode. This will reflect the clip on each side.

  • REPEAT

    Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

  • mod_padding
  • mod_padding_crop

Attributes:

ctx class-attribute instance-attribute

ctx = padder_ctx

COLOR classmethod

COLOR(
    clip: VideoNode,
    left: int = 0,
    right: int = 0,
    top: int = 0,
    bottom: int = 0,
    color: (
        int
        | float
        | bool
        | None
        | MissingT
        | Sequence[int | float | bool | None | MissingT]
    ) = (False, MISSING),
) -> ConstantFormatVideoNode

Pad a clip with a constant color.

Visual example:

```
>>> |ABCDE
>>> padder.COLOR(left=3, color=Z)
>>> ZZZ|ABCDE
```

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • left

    (int, default: 0 ) –

    Padding added to the left side of the clip.

  • right

    (int, default: 0 ) –

    Padding added to the right side of the clip.

  • top

    (int, default: 0 ) –

    Padding added to the top side of the clip.

  • bottom

    (int, default: 0 ) –

    Padding added to the bottom side of the clip.

  • color

    (int | float | bool | None | MissingT | Sequence[int | float | bool | None | MissingT], default: (False, MISSING) ) –

    Constant color that should be added on the sides:

    • number: This will be treated as such and not converted or clamped.
    • False: Lowest value for this clip format and color range.
    • True: Highest value for this clip format and color range.
    • None: Neutral value for this clip format.
    • MISSING: Automatically set to False if RGB, else None.

Returns:

  • ConstantFormatVideoNode

    Padded clip with colored borders.

Source code
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
@classmethod
def COLOR(  # noqa: N802
    cls,
    clip: vs.VideoNode,
    left: int = 0,
    right: int = 0,
    top: int = 0,
    bottom: int = 0,
    color: int | float | bool | None | MissingT | Sequence[int | float | bool | None | MissingT] = (False, MISSING),
) -> ConstantFormatVideoNode:
    """
    Pad a clip with a constant color.

    Visual example:

        ```
        >>> |ABCDE
        >>> padder.COLOR(left=3, color=Z)
        >>> ZZZ|ABCDE
        ```

    Args:
        clip: Input clip.
        left: Padding added to the left side of the clip.
        right: Padding added to the right side of the clip.
        top: Padding added to the top side of the clip.
        bottom: Padding added to the bottom side of the clip.
        color: Constant color that should be added on the sides:

               * number: This will be treated as such and not converted or clamped.
               * False: Lowest value for this clip format and color range.
               * True: Highest value for this clip format and color range.
               * None: Neutral value for this clip format.
               * MISSING: Automatically set to False if RGB, else None.

    Returns:
        Padded clip with colored borders.
    """

    from ..functions import normalize_seq
    from ..utils import core, get_lowest_values, get_neutral_values, get_peak_values

    assert check_variable_format(clip, "padder")

    cls._base(clip, left, right, top, bottom)

    def _norm(colr: int | float | bool | None | MissingT) -> Sequence[int | float]:
        if colr is MISSING:
            colr = False if clip.format.color_family is vs.RGB else None

        if colr is False:
            return get_lowest_values(clip, clip)

        if colr is True:
            return get_peak_values(clip, clip)

        if colr is None:
            return get_neutral_values(clip)

        return normalize_seq(colr, clip.format.num_planes)

    if not isinstance(color, Sequence):
        norm_colors = _norm(color)
    else:
        norm_colors = [_norm(c)[i] for i, c in enumerate(normalize_seq(color, clip.format.num_planes))]

    return core.std.AddBorders(clip, left, right, top, bottom, norm_colors)

MIRROR classmethod

MIRROR(
    clip: VideoNodeT,
    left: int = 0,
    right: int = 0,
    top: int = 0,
    bottom: int = 0,
) -> VideoNodeT

Pad a clip with reflect mode. This will reflect the clip on each side.

Visual example:

```
>>> |ABCDE
>>> padder.MIRROR(left=3)
>>> CBA|ABCDE
```

Parameters:

  • clip

    (VideoNodeT) –

    Input clip.

  • left

    (int, default: 0 ) –

    Padding added to the left side of the clip.

  • right

    (int, default: 0 ) –

    Padding added to the right side of the clip.

  • top

    (int, default: 0 ) –

    Padding added to the top side of the clip.

  • bottom

    (int, default: 0 ) –

    Padding added to the bottom side of the clip.

Returns:

  • VideoNodeT

    Padded clip with reflected borders.

Source code
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
@classmethod
def MIRROR(cls, clip: VideoNodeT, left: int = 0, right: int = 0, top: int = 0, bottom: int = 0) -> VideoNodeT:  # noqa: N802
    """
    Pad a clip with reflect mode. This will reflect the clip on each side.

    Visual example:

        ```
        >>> |ABCDE
        >>> padder.MIRROR(left=3)
        >>> CBA|ABCDE
        ```

    Args:
        clip: Input clip.
        left: Padding added to the left side of the clip.
        right: Padding added to the right side of the clip.
        top: Padding added to the top side of the clip.
        bottom: Padding added to the bottom side of the clip.

    Returns:
        Padded clip with reflected borders.
    """

    from ..utils import core

    width, height, *_ = cls._base(clip, left, right, top, bottom)

    padded = core.resize.Point(
        core.std.CopyFrameProps(clip, clip.std.BlankClip()),
        width,
        height,
        src_top=-top,
        src_left=-left,
        src_width=width,
        src_height=height,
    )
    return core.std.CopyFrameProps(padded, clip)

REPEAT classmethod

REPEAT(
    clip: VideoNode,
    left: int = 0,
    right: int = 0,
    top: int = 0,
    bottom: int = 0,
) -> ConstantFormatVideoNode

Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

Visual example:

```
>>> |ABCDE
>>> padder.REPEAT(left=3)
>>> AAA|ABCDE
```

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • left

    (int, default: 0 ) –

    Padding added to the left side of the clip.

  • right

    (int, default: 0 ) –

    Padding added to the right side of the clip.

  • top

    (int, default: 0 ) –

    Padding added to the top side of the clip.

  • bottom

    (int, default: 0 ) –

    Padding added to the bottom side of the clip.

Returns:

  • ConstantFormatVideoNode

    Padded clip with repeated borders.

Source code
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
@classmethod
def REPEAT(  # noqa: N802
    cls, clip: vs.VideoNode, left: int = 0, right: int = 0, top: int = 0, bottom: int = 0
) -> ConstantFormatVideoNode:
    """
    Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

    Visual example:

        ```
        >>> |ABCDE
        >>> padder.REPEAT(left=3)
        >>> AAA|ABCDE
        ```

    Args:
        clip: Input clip.
        left: Padding added to the left side of the clip.
        right: Padding added to the right side of the clip.
        top: Padding added to the top side of the clip.
        bottom: Padding added to the bottom side of the clip.

    Returns:
        Padded clip with repeated borders.
    """

    *_, fmt, w_sub, h_sub = cls._base(clip, left, right, top, bottom)

    padded = clip.std.AddBorders(left, right, top, bottom)

    right, bottom = clip.width + left, clip.height + top

    pads = [
        (left, right, top, bottom),
        (left // w_sub, right // w_sub, top // h_sub, bottom // h_sub),
    ][: fmt.num_planes]

    return padded.akarin.Expr(
        [
            """
            X {left} < L! Y {top} < T! X {right} > R! Y {bottom} > B!

            T@ B@ or L@ R@ or and
                L@
                    T@ {left} {top}  x[] {left} {bottom} x[] ?
                    T@ {right} {top} x[] {right} {bottom} x[] ?
                ?
                L@
                    {left} Y x[]
                    R@
                        {right} Y x[]
                        T@
                            X {top} x[]
                            B@
                                X {bottom} x[]
                                x
                            ?
                        ?
                    ?
                ?
            ?
        """.format(left=l_, right=r_ - 1, top=t_, bottom=b_ - 1)
            for l_, r_, t_, b_ in pads
        ]
    )

mod_padding classmethod

mod_padding(
    sizes: tuple[int, int] | VideoNode,
    mod: int = 16,
    min: int = 4,
    align: Align = MIDDLE_CENTER,
) -> tuple[int, int, int, int]
Source code
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
@classmethod
def mod_padding(
    cls, sizes: tuple[int, int] | vs.VideoNode, mod: int = 16, min: int = 4, align: Align = Align.MIDDLE_CENTER
) -> tuple[int, int, int, int]:
    sizes, _ = cls._get_sizes_crop_scale(sizes, 1)
    ph, pv = (mod - (((x + min * 2) - 1) % mod + 1) for x in sizes)
    left, top = floor(ph / 2), floor(pv / 2)
    left, right, top, bottom = tuple(x + min for x in (left, ph - left, top, pv - top))

    if align & BaseAlign.TOP:
        bottom += top
        top = 0
    elif align & BaseAlign.BOTTOM:
        top += bottom
        bottom = 0

    if align & BaseAlign.LEFT:
        right += left
        left = 0
    elif align & BaseAlign.RIGHT:
        left += right
        right = 0

    return left, right, top, bottom

mod_padding_crop classmethod

mod_padding_crop(
    sizes: tuple[int, int] | VideoNode,
    mod: int = 16,
    min: int = 4,
    crop_scale: float | tuple[float, float] = 2,
    align: Align = MIDDLE_CENTER,
) -> tuple[tuple[int, int, int, int], tuple[int, int, int, int]]
Source code
441
442
443
444
445
446
447
448
449
450
451
452
@classmethod
def mod_padding_crop(
    cls,
    sizes: tuple[int, int] | vs.VideoNode,
    mod: int = 16,
    min: int = 4,
    crop_scale: float | tuple[float, float] = 2,
    align: Align = Align.MIDDLE_CENTER,
) -> tuple[tuple[int, int, int, int], tuple[int, int, int, int]]:
    sizes, crop_scale = cls._get_sizes_crop_scale(sizes, crop_scale)
    padding = cls.mod_padding(sizes, mod, min, align)
    return padding, tuple(x * crop_scale[0 if i < 2 else 1] for x, i in enumerate(padding))  # type: ignore

padder_ctx

padder_ctx(mod: int = 8, min: int = 0, align: Align = MIDDLE_CENTER)

Bases: AbstractContextManager['padder_ctx']

Context manager for the padder class.

Parameters:

  • mod

    (int, default: 8 ) –

    The modulus used for calculations or constraints. Defaults to 8.

  • min

    (int, default: 0 ) –

    The minimum value allowed or used as a base threshold. Defaults to 0.

  • align

    (Align, default: MIDDLE_CENTER ) –

    The alignment configuration. Defaults to Align.MIDDLE_CENTER.

Methods:

  • COLOR

    Pad a clip with a constant color.

  • CROP

    Crop a clip with the padding values.

  • MIRROR

    Pad a clip with reflect mode. This will reflect the clip on each side.

  • REPEAT

    Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

Attributes:

Source code
104
105
106
107
108
109
110
111
112
113
114
def __init__(self, mod: int = 8, min: int = 0, align: Align = Align.MIDDLE_CENTER) -> None:
    """
    Args:
        mod: The modulus used for calculations or constraints. Defaults to 8.
        min: The minimum value allowed or used as a base threshold. Defaults to 0.
        align: The alignment configuration. Defaults to Align.MIDDLE_CENTER.
    """
    self.mod = mod
    self.min = min
    self.align = align
    self.pad_ops = list[tuple[tuple[int, int, int, int], tuple[int, int]]]()

align instance-attribute

align = align

min instance-attribute

min = min

mod instance-attribute

mod = mod

pad_ops instance-attribute

pad_ops = list[tuple[tuple[int, int, int, int], tuple[int, int]]]()

COLOR

COLOR(
    clip: VideoNode,
    color: int | float | bool | None | Sequence[int | float | bool | None] = (
        False,
        None,
    ),
) -> ConstantFormatVideoNode

Pad a clip with a constant color.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • color

    (int | float | bool | None | Sequence[int | float | bool | None], default: (False, None) ) –

    Constant color that should be added on the sides: * number: This will be treated as such and not converted or clamped. * False: Lowest value for this clip format and color range. * True: Highest value for this clip format and color range. * None: Neutral value for this clip format. * MISSING: Automatically set to False if RGB, else None.

Returns:

  • ConstantFormatVideoNode

    Padded clip with colored borders.

Source code
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def COLOR(  # noqa: N802
    self, clip: vs.VideoNode, color: int | float | bool | None | Sequence[int | float | bool | None] = (False, None)
) -> ConstantFormatVideoNode:
    """
    Pad a clip with a constant color.

    Args:
        clip: Input clip.
        color: Constant color that should be added on the sides: * number: This will be treated as such and not
            converted or clamped. * False: Lowest value for this clip format and color range. * True: Highest value
            for this clip format and color range. * None: Neutral value for this clip format. * MISSING:
            Automatically set to False if RGB, else None.

    Returns:
        Padded clip with colored borders.
    """
    padding = padder.mod_padding(clip, self.mod, self.min, self.align)
    out = padder.COLOR(clip, *padding, color)
    self.pad_ops.append((padding, (out.width, out.height)))
    return out

CROP

CROP(
    clip: VideoNode, crop_scale: float | tuple[float, float] | None = None
) -> ConstantFormatVideoNode

Crop a clip with the padding values.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • crop_scale

    (float | tuple[float, float] | None, default: None ) –

    Optional scale factor for the padding values. If None, no scaling is applied.

Returns:

  • ConstantFormatVideoNode

    Cropped clip.

Source code
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def CROP(  # noqa: N802
    self, clip: vs.VideoNode, crop_scale: float | tuple[float, float] | None = None
) -> ConstantFormatVideoNode:
    """
    Crop a clip with the padding values.

    Args:
        clip: Input clip.
        crop_scale: Optional scale factor for the padding values. If None, no scaling is applied.

    Returns:
        Cropped clip.
    """
    (padding, sizes) = self.pad_ops.pop(0)

    if crop_scale is None:
        crop_scale = (clip.width / sizes[0], clip.height / sizes[1])

    crop_pad = padder._crop_padding(padder._get_sizes_crop_scale(clip, crop_scale)[1])

    return clip.std.Crop(*(x * y for x, y in zip(padding, crop_pad)))

MIRROR

Pad a clip with reflect mode. This will reflect the clip on each side.

Parameters:

Returns:

  • VideoNodeT

    Padded clip with reflected borders.

Source code
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def MIRROR(self, clip: VideoNodeT) -> VideoNodeT:  # noqa: N802
    """
    Pad a clip with reflect mode. This will reflect the clip on each side.

    Args:
        clip: Input clip.

    Returns:
        Padded clip with reflected borders.
    """
    padding = padder.mod_padding(clip, self.mod, self.min, self.align)
    out = padder.MIRROR(clip, *padding)
    self.pad_ops.append((padding, (out.width, out.height)))
    return out

REPEAT

REPEAT(clip: VideoNode) -> ConstantFormatVideoNode

Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

Returns:

  • ConstantFormatVideoNode

    Padded clip with repeated borders.

Source code
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def REPEAT(self, clip: vs.VideoNode) -> ConstantFormatVideoNode:  # noqa: N802
    """
    Pad a clip with repeat mode. This will simply repeat the last row/column till the end.

    Args:
        clip: Input clip.

    Returns:
        Padded clip with repeated borders.
    """
    padding = padder.mod_padding(clip, self.mod, self.min, self.align)
    out = padder.REPEAT(clip, *padding)
    self.pad_ops.append((padding, (out.width, out.height)))
    return out

change_fps

change_fps(clip: VideoNode, fps: Fraction) -> VideoNode

Convert the framerate of a clip.

This is different from AssumeFPS as this will actively adjust the framerate of a clip, rather than simply set the framerate properties.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • fps

    (Fraction) –

    Framerate to convert the clip to. Must be a Fraction.

Returns:

  • VideoNode

    Clip with the framerate converted and frames adjusted as necessary.

Source code
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def change_fps(clip: vs.VideoNode, fps: Fraction) -> vs.VideoNode:
    """
    Convert the framerate of a clip.

    This is different from AssumeFPS as this will actively adjust
    the framerate of a clip, rather than simply set the framerate properties.

    Args:
        clip: Input clip.
        fps: Framerate to convert the clip to. Must be a Fraction.

    Returns:
        Clip with the framerate converted and frames adjusted as necessary.
    """

    src_num, src_den = clip.fps_num, clip.fps_den

    dest_num, dest_den = fps.as_integer_ratio()

    if (dest_num, dest_den) == (src_num, src_den):
        return clip

    factor = (dest_num / dest_den) * (src_den / src_num)

    new_fps_clip = clip.std.BlankClip(length=floor(clip.num_frames * factor), fpsnum=dest_num, fpsden=dest_den)

    return new_fps_clip.std.FrameEval(lambda n: clip[round(n / factor)])

match_clip

match_clip(
    clip: VideoNode,
    ref: VideoNode,
    dimensions: bool = True,
    vformat: bool = True,
    matrices: bool = True,
    length: bool = False,
) -> VideoNode

Try to match the formats, dimensions, etc. of a reference clip to match the original clip.

Parameters:

  • clip

    (VideoNode) –

    Original clip.

  • ref

    (VideoNode) –

    Reference clip.

  • dimensions

    (bool, default: True ) –

    Whether to adjust the dimensions of the reference clip to match the original clip. If True, uses resize.Bicubic to resize the image. Default: True.

  • vformat

    (bool, default: True ) –

    Whether to change the reference clip's format to match the original clip's. Default: True.

  • matrices

    (bool, default: True ) –

    Whether to adjust the Matrix, Transfer, and Primaries of the reference clip to match the original clip. Default: True.

  • length

    (bool, default: False ) –

    Whether to adjust the length of the reference clip to match the original clip.

Source code
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def match_clip(
    clip: vs.VideoNode,
    ref: vs.VideoNode,
    dimensions: bool = True,
    vformat: bool = True,
    matrices: bool = True,
    length: bool = False,
) -> vs.VideoNode:
    """
    Try to match the formats, dimensions, etc. of a reference clip to match the original clip.

    Args:
        clip: Original clip.
        ref: Reference clip.
        dimensions: Whether to adjust the dimensions of the reference clip to match the original clip. If True, uses
            resize.Bicubic to resize the image. Default: True.
        vformat: Whether to change the reference clip's format to match the original clip's. Default: True.
        matrices: Whether to adjust the Matrix, Transfer, and Primaries of the reference clip to match the original
            clip. Default: True.
        length: Whether to adjust the length of the reference clip to match the original clip.
    """
    from ..enums import Matrix
    from ..functions import check_variable

    assert check_variable(clip, match_clip)
    assert check_variable(ref, match_clip)

    if length:
        if clip.num_frames < ref.num_frames:
            clip = vs.core.std.Splice([clip, clip[-1] * (ref.num_frames - clip.num_frames)])
        else:
            clip = clip[: ref.num_frames]

    clip = clip.resize.Bicubic(ref.width, ref.height) if dimensions else clip

    if vformat:
        clip = clip.resize.Bicubic(format=ref.format.id, matrix=Matrix.from_video(ref))

    if matrices:
        clip = clip.std.SetFrameProps(
            **get_props(ref, ["_Matrix", "_Transfer", "_Primaries"], int, default=2, func=match_clip)
        )

    return clip.std.AssumeFPS(fpsnum=ref.fps.numerator, fpsden=ref.fps.denominator)

pick_func_stype

pick_func_stype(
    clip: VideoNode,
    func_int: Callable[P, VideoNodeT],
    func_float: Callable[P, VideoNodeT],
) -> Callable[P, VideoNodeT]

Pick the function matching the sample type of the clip's format.

Parameters:

Returns:

Source code
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
def pick_func_stype(
    clip: vs.VideoNode, func_int: Callable[P, VideoNodeT], func_float: Callable[P, VideoNodeT]
) -> Callable[P, VideoNodeT]:
    """
    Pick the function matching the sample type of the clip's format.

    Args:
        clip: Input clip.
        func_int: Function to run on integer clips.
        func_float: Function to run on float clips.

    Returns:
        Function matching the sample type of your clip's format.
    """

    assert check_variable_format(clip, pick_func_stype)

    return func_float if clip.format.sample_type == vs.FLOAT else func_int

set_output

set_output(
    node: VideoNode,
    index: int = ...,
    /,
    *,
    alpha: VideoNode | None = ...,
    **kwargs: Any,
) -> None
set_output(
    node: VideoNode,
    name: str | bool | None = ...,
    /,
    *,
    alpha: VideoNode | None = ...,
    **kwargs: Any,
) -> None
set_output(
    node: VideoNode,
    index: int = ...,
    name: str | bool | None = ...,
    /,
    alpha: VideoNode | None = ...,
    **kwargs: Any,
) -> None
set_output(node: AudioNode, index: int = ..., /, **kwargs: Any) -> None
set_output(
    node: AudioNode, name: str | bool | None = ..., /, **kwargs: Any
) -> None
set_output(
    node: AudioNode,
    index: int = ...,
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[RawNode | Iterable[RawNode | Iterable[RawNode]]],
    index: int | Sequence[int] = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[RawNode | Iterable[RawNode | Iterable[RawNode]]],
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[RawNode | Iterable[RawNode | Iterable[RawNode]]],
    index: int | Sequence[int] = ...,
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: RawNode | Iterable[RawNode | Iterable[RawNode | Iterable[RawNode]]],
    index_or_name: int | Sequence[int] | str | bool | None = None,
    name: str | bool | None = None,
    /,
    alpha: VideoNode | None = None,
    **kwargs: Any,
) -> None

Set output node with optional index and name, and if available, use vspreview set_output.

Parameters:

  • node

    (RawNode | Iterable[RawNode | Iterable[RawNode | Iterable[RawNode]]]) –

    Output node.

  • index_or_name

    (int | Sequence[int] | str | bool | None, default: None ) –

    Index number, defaults to current maximum index number + 1 or 0 if no ouput exists yet.

  • name

    (str | bool | None, default: None ) –

    Node's name, defaults to variable name

  • alpha

    (VideoNode | None, default: None ) –

    Alpha planes node, defaults to None.

  • **kwargs

    (Any, default: {} ) –

    Additional arguments to be passed to vspreview.set_output.

Source code
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
def set_output(
    node: vs.RawNode | Iterable[vs.RawNode | Iterable[vs.RawNode | Iterable[vs.RawNode]]],
    index_or_name: int | Sequence[int] | str | bool | None = None,
    name: str | bool | None = None,
    /,
    alpha: vs.VideoNode | None = None,
    **kwargs: Any,
) -> None:
    """
    Set output node with optional index and name, and if available, use vspreview set_output.

    Args:
        node: Output node.
        index_or_name: Index number, defaults to current maximum index number + 1 or 0 if no ouput exists yet.
        name: Node's name, defaults to variable name
        alpha: Alpha planes node, defaults to None.
        **kwargs: Additional arguments to be passed to `vspreview.set_output`.
    """
    from ..functions import flatten, to_arr

    if isinstance(index_or_name, (str, bool)):
        index = None
        if not TYPE_CHECKING and isinstance(name, vs.VideoNode):
            # Backward compatible with older api
            alpha = name
        name = index_or_name
    else:
        index = index_or_name

    ouputs = vs.get_outputs()
    nodes = list[vs.RawNode](flatten(node)) if isinstance(node, Iterable) else [node]

    index = to_arr(index) if index is not None else [max(ouputs, default=-1) + 1]

    while len(index) < len(nodes):
        index.append(index[-1] + 1)

    try:
        from vspreview import set_output as vsp_set_output

        vsp_set_output(nodes, index, name, alpha=alpha, f_back=2, force_preview=True, **kwargs)
    except ModuleNotFoundError:
        for idx, n in zip(index, nodes):
            n.set_output(idx)