Skip to content

misc

FFLOAT module-attribute

FFLOAT = TypeVar('FFLOAT', bound=Callable[..., VideoNode])

FINT module-attribute

FINT = TypeVar('FINT', bound=Callable[..., VideoNode])

padder module-attribute

padder = _padder()

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

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

    :return:            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
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
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.

    :param clip:            Original clip.
    :param ref:             Reference clip.
    :param 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.
    :param vformat:         Whether to change the reference clip's format to match the original clip's.
                            Default: True.
    :param matrices:        Whether to adjust the Matrix, Transfer, and Primaries of the reference clip
                            to match the original clip. Default: True.
    :param length:          Whether to adjust the length of the reference clip to match the original clip.
    """
    from ..enums import Matrix, Primaries, Transfer
    from ..functions import check_variable

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

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

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

    if matrices:
        with ref.get_frame(0) as ref_frame:
            clip = clip.std.SetFrameProps(
                _Matrix=Matrix(ref_frame), _Transfer=Transfer(ref_frame), _Primaries=Primaries(ref_frame)
            )

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

pick_func_stype

pick_func_stype(
    clip: VideoNode, func_int: FINT, func_float: FFLOAT
) -> FINT | FFLOAT

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

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • func_int

    (FINT) –

    Function to run on integer clips.

  • func_float

    (FFLOAT) –

    Function to run on float clips.

Returns:

  • FINT | FFLOAT

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

Source code
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def pick_func_stype(clip: vs.VideoNode, func_int: FINT, func_float: FFLOAT) -> FINT | FFLOAT:
    """
    Pick the function matching the sample type of the clip's format.

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

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

    assert clip.format

    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[VideoNode | Iterable[VideoNode | Iterable[VideoNode]]],
    index: int | Sequence[int] = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[VideoNode | Iterable[VideoNode | Iterable[VideoNode]]],
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[VideoNode | Iterable[VideoNode | Iterable[VideoNode]]],
    index: int | Sequence[int] = ...,
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[AudioNode | Iterable[AudioNode | Iterable[AudioNode]]],
    index: int | Sequence[int] = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[AudioNode | Iterable[AudioNode | Iterable[AudioNode]]],
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: Iterable[AudioNode | Iterable[AudioNode | Iterable[AudioNode]]],
    index: int | Sequence[int] = ...,
    name: str | bool | None = ...,
    /,
    **kwargs: Any,
) -> None
set_output(
    node: RawNode | 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 name, and if available, use vspreview set_output.

Parameters:

  • node

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

    Output node

  • index

    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

Source code
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
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 name, and if available, use vspreview set_output.

    :param node:            Output node
    :param index:           Index number, defaults to current maximum index number + 1 or 0 if no ouput exists yet
    :param name:            Node's name, defaults to variable name
    :param alpha:           Alpha planes node, defaults to None
    """
    from ..functions import flatten, to_arr

    if isinstance(index_or_name, (str, bool)):
        index = None
        # Backward compatible with older api
        if isinstance(name, vs.VideoNode):
            alpha = name  # type: ignore[unreachable]
        name = index_or_name
    else:
        index = index_or_name

    ouputs = vs.get_outputs()
    nodes = list(flatten(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)