Skip to content

freqs

Classes:

MeanMode

Bases: CustomIntEnum

Methods:

Attributes:

ARITHMETIC class-attribute instance-attribute

ARITHMETIC = 1

CUBIC class-attribute instance-attribute

CUBIC = 3

GEOMETRIC class-attribute instance-attribute

GEOMETRIC = 0

HARMONIC class-attribute instance-attribute

HARMONIC = -1

LEHMER class-attribute instance-attribute

LEHMER = 10

MAXIMUM class-attribute instance-attribute

MAXIMUM = 4

MAXIMUM_ABS class-attribute instance-attribute

MAXIMUM_ABS = 21

MEDIAN class-attribute instance-attribute

MEDIAN = 30

MINIMUM class-attribute instance-attribute

MINIMUM = -2

MINIMUM_ABS class-attribute instance-attribute

MINIMUM_ABS = 20

RMS class-attribute instance-attribute

RMS = 2

__call__

__call__(
    *_clips: VideoNode | Iterable[VideoNode],
    planes: PlanesT = None,
    func: FuncExceptT | None = None
) -> ConstantFormatVideoNode
Source code
 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
 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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def __call__(
    self, *_clips: vs.VideoNode | Iterable[vs.VideoNode], planes: PlanesT = None, func: FuncExceptT | None = None
) -> ConstantFormatVideoNode:
    func = func or self.__class__

    clips = flatten_vnodes(_clips)

    assert check_variable_format(clips, func)

    n_clips = len(clips)
    n_op = n_clips - 1

    if n_clips < 2:
        return next(iter(clips))

    if self == MeanMode.MINIMUM:
        return ExprOp.MIN(clips, planes=planes, func=func)

    if self == MeanMode.MAXIMUM:
        return ExprOp.MAX(clips, planes=planes, func=func)

    if self == MeanMode.GEOMETRIC:
        return combine(clips, ExprOp.MUL, None, None, [1 / n_clips, ExprOp.POW], planes=planes, func=func)

    if self == MeanMode.LEHMER:
        counts = range(n_clips)
        clip_vars = ExprVars(n_clips)

        expr = StrList([[f'{clip} neutral - D{i}!' for i, clip in zip(counts, clip_vars)]])

        for y in range(2):
            expr.extend([
                [f'D{i}@ {3 - y} pow' for i in counts],
                ExprOp.ADD * n_op, f'P{y + 1}!'
            ])

        expr.append('P2@ 0 = 0 P1@ P2@ / ? neutral +')

        return norm_expr(clips, expr, planes=planes, func=func)

    if self in {MeanMode.RMS, MeanMode.ARITHMETIC, MeanMode.CUBIC, MeanMode.HARMONIC}:
        return combine(
            clips, ExprOp.ADD, f'{self.value} {ExprOp.POW}', None, [
                n_clips, ExprOp.DIV, 1 / self, ExprOp.POW
            ], planes=planes, func=func
        )

    if self in {MeanMode.MINIMUM_ABS, MeanMode.MAXIMUM_ABS}:
        operator = ExprOp.MIN if self is MeanMode.MINIMUM_ABS else ExprOp.MAX

        expr_string = ''
        for src in ExprVars(n_clips):
            expr_string += f'{src} neutral - abs {src.upper()}D! '

        for i, src, srcn in zip(count(), ExprVars(n_clips), ExprVars(1, n_clips)):
            expr_string += f'{src.upper()}D@ {srcn.upper()}D@ {operator} {src} '

            if i == n_clips - 2:
                expr_string += f'{srcn} '

        expr_string += '? ' * n_op

        return norm_expr(clips, expr_string, planes=planes, func=func)

    if self == MeanMode.MEDIAN:
        all_clips = str(ExprVars(1, n_clips))

        n_ops = n_clips - 2

        yzmin, yzmax = [
            all_clips + f' {op}' * n_ops for op in (ExprOp.MIN, ExprOp.MAX)
        ]

        return norm_expr(
            clips, f'{yzmin} YZMIN! {yzmax} YZMAX! x YZMIN@ min x = YZMIN@ x YZMAX@ max x = YZMAX@ x ? ?',
            planes, func=func
        )

    raise CustomNotImplementedError