Skip to content

utils

Utilities for field-based processing and telecine pattern generation.

Functions:

  • get_field_difference

    Compute the difference between top and bottom fields in a clip.

  • reinterlace

    Reinterlace a progressive clip by separating and weaving fields.

  • reweave

    Interleave two clips and weave them into full frames.

  • telecine_patterns

    Generate all possible telecine patterns by interleaving frames from two clips.

  • weave

    Recombine fields into frames using DoubleWeave.

get_field_difference

get_field_difference(
    clip: VideoNode,
    tff: FieldBasedLike | bool | None = None,
    func: FuncExcept | None = None,
) -> ConstantFormatVideoNode

Compute the difference between top and bottom fields in a clip.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • tff

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

    Field order (top-field-first). If None, inferred from the clip. Defaults to None.

  • func

    (FuncExcept | None, default: None ) –

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

Returns:

  • ConstantFormatVideoNode

    A clip with a per-frame property "FieldDifference" indicating the absolute difference between fields.

Source code in vsdeinterlace/utils.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_field_difference(
    clip: vs.VideoNode, tff: FieldBasedLike | bool | None = None, func: FuncExcept | None = None
) -> ConstantFormatVideoNode:
    """
    Compute the difference between top and bottom fields in a clip.

    Args:
        clip: Input clip.
        tff: Field order (top-field-first). If None, inferred from the clip. Defaults to None.
        func: Function returned for custom error handling. This should only be set by VS package developers.

    Returns:
        A clip with a per-frame property "FieldDifference" indicating the absolute difference between fields.
    """
    func = func or get_field_difference

    assert check_variable(clip, func)

    tff = FieldBased.from_param_or_video(tff, clip, True, func).is_tff

    stats = clip.std.SeparateFields(tff).std.PlaneStats()

    return core.akarin.PropExpr(
        [clip, stats[::2], stats[1::2]], lambda: {"FieldDifference": "y.PlaneStatsAverage z.PlaneStatsAverage - abs"}
    )

reinterlace

reinterlace(
    clip: VideoNode,
    tff: FieldBasedLike | bool | None = None,
    func: FuncExcept | None = None,
) -> ConstantFormatVideoNode

Reinterlace a progressive clip by separating and weaving fields.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • tff

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

    Field order (top-field-first). If None, inferred from the clip. Defaults to None.

  • func

    (FuncExcept | None, default: None ) –

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

Returns:

  • ConstantFormatVideoNode

    A reinterlaced clip with fields woven back into interlaced frames.

Source code in vsdeinterlace/utils.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def reinterlace(
    clip: vs.VideoNode, tff: FieldBasedLike | bool | None = None, func: FuncExcept | None = None
) -> ConstantFormatVideoNode:
    """
    Reinterlace a progressive clip by separating and weaving fields.

    Args:
        clip: Input clip.
        tff: Field order (top-field-first). If None, inferred from the clip. Defaults to None.
        func: Function returned for custom error handling. This should only be set by VS package developers.

    Returns:
        A reinterlaced clip with fields woven back into interlaced frames.
    """
    func = func or reinterlace

    assert check_variable(clip, func)

    tff = FieldBased.from_param_or_video(tff, clip, True, func).is_tff

    return weave(clip.std.SeparateFields(tff).std.SelectEvery(4, (0, 3)), tff, func)

reweave

reweave(
    clipa: VideoNode,
    clipb: VideoNode,
    tff: FieldBasedLike | bool | None = None,
    func: FuncExcept | None = None,
) -> ConstantFormatVideoNode

Interleave two clips and weave them into full frames.

Parameters:

  • clipa

    (VideoNode) –

    First input clip.

  • clipb

    (VideoNode) –

    Second input clip.

  • tff

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

    Field order (top-field-first). If None, inferred from the clip. Defaults to None.

  • func

    (FuncExcept | None, default: None ) –

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

Returns:

  • ConstantFormatVideoNode

    A reweaved clip with fields combined into frames.

Source code in vsdeinterlace/utils.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def reweave(
    clipa: vs.VideoNode, clipb: vs.VideoNode, tff: FieldBasedLike | bool | None = None, func: FuncExcept | None = None
) -> ConstantFormatVideoNode:
    """
    Interleave two clips and weave them into full frames.

    Args:
        clipa: First input clip.
        clipb: Second input clip.
        tff: Field order (top-field-first). If None, inferred from the clip. Defaults to None.
        func: Function returned for custom error handling. This should only be set by VS package developers.

    Returns:
        A reweaved clip with fields combined into frames.
    """
    func = func or reweave
    assert check_variable(clipa, func)
    assert check_variable(clipb, func)

    return weave(core.std.Interleave([clipa, clipb]), tff, func)

telecine_patterns

telecine_patterns(
    clipa: VideoNode,
    clipb: VideoNode,
    length: int = 5,
    func: FuncExcept | None = None,
) -> list[ConstantFormatVideoNode]

Generate all possible telecine patterns by interleaving frames from two clips.

Parameters:

  • clipa

    (VideoNode) –

    First input clip.

  • clipb

    (VideoNode) –

    Second input clip.

  • length

    (int, default: 5 ) –

    Cycle length used for frame selection. Defaults to 5.

  • func

    (FuncExcept | None, default: None ) –

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

Returns:

  • list[ConstantFormatVideoNode]

    A list of interleaved clips, each representing a unique telecine pattern.

Source code in vsdeinterlace/utils.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def telecine_patterns(
    clipa: vs.VideoNode, clipb: vs.VideoNode, length: int = 5, func: FuncExcept | None = None
) -> list[ConstantFormatVideoNode]:
    """
    Generate all possible telecine patterns by interleaving frames from two clips.

    Args:
        clipa: First input clip.
        clipb: Second input clip.
        length: Cycle length used for frame selection. Defaults to 5.
        func: Function returned for custom error handling. This should only be set by VS package developers.

    Returns:
        A list of interleaved clips, each representing a unique telecine pattern.
    """
    func = func or telecine_patterns

    assert check_variable(clipa, func)
    assert check_variable(clipb, func)

    a_select = [clipa.std.SelectEvery(length, i) for i in range(length)]
    b_select = [clipb.std.SelectEvery(length, i) for i in range(length)]

    return [core.std.Interleave([(b_select if i == j else a_select)[j] for j in range(length)]) for i in range(length)]

weave

weave(
    clip: VideoNode,
    tff: FieldBasedLike | bool | None = None,
    func: FuncExcept | None = None,
) -> ConstantFormatVideoNode

Recombine fields into frames using DoubleWeave.

Parameters:

  • clip

    (VideoNode) –

    Input clip.

  • tff

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

    Field order (top-field-first). If None, inferred from the clip. Defaults to None.

  • func

    (FuncExcept | None, default: None ) –

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

Returns:

  • ConstantFormatVideoNode

    A clip with fields woven back into full frames.

Source code in vsdeinterlace/utils.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def weave(
    clip: vs.VideoNode, tff: FieldBasedLike | bool | None = None, func: FuncExcept | None = None
) -> ConstantFormatVideoNode:
    """
    Recombine fields into frames using DoubleWeave.

    Args:
        clip: Input clip.
        tff: Field order (top-field-first). If None, inferred from the clip. Defaults to None.
        func: Function returned for custom error handling. This should only be set by VS package developers.

    Returns:
        A clip with fields woven back into full frames.
    """
    func = func or weave

    assert check_variable(clip, func)

    tff = FieldBased.from_param_or_video(tff, clip, True, func).is_tff

    return clip.std.DoubleWeave(tff)[::2]