Skip to content

freqs

Classes:

  • MeanMode

    Enum of different mean for combining clips.

MeanMode

Bases: CustomEnum

Enum of different mean for combining clips.

Methods:

  • __call__

    Applies the selected mean to one or more video clips.

Attributes:

  • ARITHMETIC

    Arithmetic mean.

  • CONTRAHARMONIC

    Contraharmonic mean, implemented as a Lehmer mean withs p=2

  • GEOMETRIC

    Geometric mean, implemented as a Lehmer mean with p=0.5.

  • HARMONIC

    Harmonic mean, implemented as a Lehmer mean with p=0.

  • LEHMER

    Lehmer mean, configurable with parameter p.

  • MAXIMUM

    Maximum value across all clips

  • MEDIAN

    Median value across all clips

  • MINIMUM

    Minimum value across all clips

ARITHMETIC class-attribute instance-attribute

ARITHMETIC = 1

Arithmetic mean.

CONTRAHARMONIC class-attribute instance-attribute

CONTRAHARMONIC = 2

Contraharmonic mean, implemented as a Lehmer mean withs p=2

GEOMETRIC class-attribute instance-attribute

GEOMETRIC = 0.5

Geometric mean, implemented as a Lehmer mean with p=0.5.

HARMONIC class-attribute instance-attribute

HARMONIC = 0

Harmonic mean, implemented as a Lehmer mean with p=0.

LEHMER class-attribute instance-attribute

LEHMER = 3

Lehmer mean, configurable with parameter p.

Note: An odd number for p is preferred as it will avoid negative inputs.

MAXIMUM class-attribute instance-attribute

MAXIMUM = auto()

Maximum value across all clips

MEDIAN class-attribute instance-attribute

MEDIAN = auto()

Median value across all clips

MINIMUM class-attribute instance-attribute

MINIMUM = auto()

Minimum value across all clips

__call__

__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    p: float = 3,
    planes: Planes = None,
    func: FuncExcept | None = None
) -> ConstantFormatVideoNode
__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    planes: Planes = None,
    func: FuncExcept | None = None
) -> ConstantFormatVideoNode
__call__(
    *_clips: VideoNodeIterableT[VideoNode],
    planes: Planes = None,
    func: FuncExcept | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode

Applies the selected mean to one or more video clips.

Parameters:

  • *_clips

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

    Input clips to combine.

  • planes

    (Planes, default: None ) –

    Which planes to process.

func: An optional function to use for error handling. **kwargs: Additional keyword arguments for certain modes.

       - p (float): Exponent for `LEHMER` mode. Defaults to 3.

Returns:

  • ConstantFormatVideoNode

    A new clip containing the combined frames.

Source code in vsrgtools/freqs.py
 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def __call__(
    self,
    *_clips: VideoNodeIterableT[vs.VideoNode],
    planes: Planes = None,
    func: FuncExcept | None = None,
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Applies the selected mean to one or more video clips.

    Args:
        *_clips: Input clips to combine.
        planes: Which planes to process.
       func: An optional function to use for error handling.
        **kwargs: Additional keyword arguments for certain modes.

               - p (float): Exponent for `LEHMER` mode. Defaults to 3.

    Returns:
        A new clip containing the combined frames.
    """

    func = func or self.__class__

    clips = flatten_vnodes(_clips)

    assert check_variable_format(clips, func)

    n_clips = len(clips)
    all_clips = ExprVars(n_clips)

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

    match self:
        case MeanMode.LEHMER:
            p = kwargs.get("p", self.value)
            counts = range(n_clips)

            expr = StrList([[f"{clip} neutral - D{i}!" for i, clip in zip(counts, all_clips)]])
            for x in range(2):
                expr.extend([[f"D{i}@ {p - x} pow" for i in counts], ExprOp.ADD * (n_clips - 1), f"P{x}!"])

            return norm_expr(clips, f"{expr} P1@ 0 = 0 P0@ P1@ / ? neutral +", planes, func=func)

        case MeanMode.HARMONIC | MeanMode.GEOMETRIC | MeanMode.CONTRAHARMONIC:
            return MeanMode.LEHMER(clips, p=self.value, planes=planes, func=func)

        case MeanMode.ARITHMETIC:
            return ExprOp.ADD(clips, expr_suffix=f"{n_clips} /", planes=planes, func=func)

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

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

        case MeanMode.MEDIAN:
            n_op = (n_clips - 1) // 2

            mean = "" if n_clips % 2 else "+ 2 /"

            return norm_expr(
                clips, f"{all_clips} sort{n_clips} drop{n_op} {mean} swap{n_op} drop{n_op}", planes, func=func
            )