Skip to content

base

This module defines the base abstract interfaces for general scaling operations.

Classes:

  • Descaler

    Abstract descaling interface.

  • Kernel

    Abstract kernel interface combining scaling, descaling, resampling, and shifting functionality.

  • Resampler

    Abstract resampling interface.

  • Scaler

    Abstract scaling interface.

Attributes:

  • DescalerLike

    Type alias for anything that can resolve to a Descaler.

  • KernelLike

    Type alias for anything that can resolve to a Kernel.

  • ResamplerLike

    Type alias for anything that can resolve to a Resampler.

  • ScalerLike

    Type alias for anything that can resolve to a Scaler.

DescalerLike module-attribute

DescalerLike = Union[str, type[Descaler], Descaler]

Type alias for anything that can resolve to a Descaler.

This includes: - A string identifier. - A class type subclassing Descaler. - An instance of a Descaler.

KernelLike module-attribute

KernelLike = Union[str, type[Kernel], Kernel]

Type alias for anything that can resolve to a Kernel.

This includes: - A string identifier. - A class type subclassing Kernel. - An instance of a Kernel.

ResamplerLike module-attribute

ResamplerLike = Union[str, type[Resampler], Resampler]

Type alias for anything that can resolve to a Resampler.

This includes: - A string identifier. - A class type subclassing Resampler. - An instance of a Resampler.

ScalerLike module-attribute

ScalerLike = Union[str, type[Scaler], Scaler]

Type alias for anything that can resolve to a Scaler.

This includes: - A string identifier. - A class type subclassing Scaler. - An instance of a Scaler.

abstract_kernels module-attribute

abstract_kernels: list[BaseScalerMeta] = []

List of fully abstract kernel classes.

Used internally to track kernel base classes that should not be used directly.

partial_abstract_kernels module-attribute

partial_abstract_kernels: list[BaseScalerMeta] = []

List of partially abstract kernel classes.

These may implement some but not all kernel functionality.

BaseScaler

BaseScaler(**kwargs: Any)

Bases: vs_object, ABC

Base abstract scaling interface for VapourSynth scalers.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the _implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the _implemented_funcs, the one passed to func takes precedence.

Parameters:

  • kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Classes:

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • pretty_string

    Cached property returning a user-friendly string representation.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

Source code
281
282
283
284
285
286
287
288
289
290
291
292
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to the `_implemented_funcs` methods
    but only if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the `_implemented_funcs`,
    the one passed to `func` takes precedence.

    :param kwargs:  Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

cached_property

cached_property(func: Callable[Concatenate[_BaseScalerT, P], T_co])

Bases: cached_property[T_co]

Read only version of functools.cached_property.

Source code
265
def __init__(self, func: Callable[Concatenate[_BaseScalerT, P], T_co]) -> None: ...

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • type[Self]

    Resolved scaler type.

Source code
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Returns:

  • int

    Kernel radius.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Source code
347
348
349
350
351
352
353
354
355
@cached_property
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    :raises CustomNotImplementedError:  If no kernel radius is defined.
    :return:                            Kernel radius.
    """
    ...

pretty_string

pretty_string() -> str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

Source code
368
369
370
371
372
373
374
375
@cached_property
def pretty_string(self) -> str:
    """
    Cached property returning a user-friendly string representation.

    :return: Pretty-printed string with arguments.
    """
    return self._pretty_string()

BaseScalerMeta

Bases: ABCMeta

Metaclass for scaler classes.

This metaclass can be used to enforce abstraction rules by specifying abstract or partial_abstract as keyword arguments in the class definition.

  • If abstract=True: The class is marked as fully abstract and added to the abstract_kernels registry. It should not be instantiated.
  • If partial_abstract=True: The class is considered partially abstract, meaning it may lack certain implementations (e.g., kernel radius) but is still allowed to be instantiated. It is added to partial_abstract_kernels.

Descaler

Descaler(**kwargs: Any)

Bases: BaseScaler

Abstract descaling interface.

Subclasses must define the descale_function used to perform the descaling.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the _implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the _implemented_funcs, the one passed to func takes precedence.

Parameters:

  • kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Classes:

Methods:

  • descale

    Descale a clip to the given resolution.

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_descale_args

    Construct the argument dictionary used for descaling.

  • get_rescale_args

    Construct the argument dictionary used for upscaling.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • pretty_string

    Cached property returning a user-friendly string representation.

  • rescale

    Rescale a clip to the given resolution from a previously descaled clip.

Attributes:

  • descale_function (Callable[..., ConstantFormatVideoNode]) –

    Descale function called internally when performing descaling operations.

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • rescale_function (Callable[..., ConstantFormatVideoNode]) –

    Rescale function called internally when performing upscaling operations.

Source code
281
282
283
284
285
286
287
288
289
290
291
292
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to the `_implemented_funcs` methods
    but only if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the `_implemented_funcs`,
    the one passed to `func` takes precedence.

    :param kwargs:  Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

descale_function instance-attribute

descale_function: Callable[..., ConstantFormatVideoNode]

Descale function called internally when performing descaling operations.

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

rescale_function instance-attribute

rescale_function: Callable[..., ConstantFormatVideoNode]

Rescale function called internally when performing upscaling operations.

cached_property

cached_property(func: Callable[Concatenate[_BaseScalerT, P], T_co])

Bases: cached_property[T_co]

Read only version of functools.cached_property.

Source code
265
def __init__(self, func: Callable[Concatenate[_BaseScalerT, P], T_co]) -> None: ...

descale

descale(
    clip: VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode

Descale a clip to the given resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target descaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target descaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • ConstantFormatVideoNode

    The descaled clip.

Source code
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
def descale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Descale a clip to the given resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:    The source clip.
    :param width:   Target descaled width (defaults to clip width if None).
    :param height:  Target descaled height (defaults to clip height if None).
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :return:        The descaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.descale_function(
        clip, **_norm_props_enums(self.get_descale_args(clip, shift, width, height, **kwargs))
    )

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • type[Self]

    Resolved scaler type.

Source code
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for descaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width for descaling.

  • height

    (int | None, default: None ) –

    Target height for descaling.

  • kwargs

    (Any, default: {} ) –

    Extra keyword arguments to merge.

Returns:

  • dict[str, Any]

    Combined keyword argument dictionary.

Source code
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
def get_descale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for descaling.

    :param clip:    The source clip.
    :param shift:   Subpixel shift (top, left).
    :param width:   Target width for descaling.
    :param height:  Target height for descaling.
    :param kwargs:  Extra keyword arguments to merge.
    :return:        Combined keyword argument dictionary.
    """
    return dict(width=width, height=height, src_top=shift[0], src_left=shift[1]) | self.kwargs | kwargs

get_rescale_args

get_rescale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for upscaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width for upscaling.

  • height

    (int | None, default: None ) –

    Target height for upscaling.

  • kwargs

    (Any, default: {} ) –

    Extra keyword arguments to merge.

Returns:

  • dict[str, Any]

    Combined keyword argument dictionary.

Source code
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
def get_rescale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for upscaling.

    :param clip:    The source clip.
    :param shift:   Subpixel shift (top, left).
    :param width:   Target width for upscaling.
    :param height:  Target height for upscaling.
    :param kwargs:  Extra keyword arguments to merge.
    :return:        Combined keyword argument dictionary.
    """
    return dict(width=width, height=height, src_top=shift[0], src_left=shift[1]) | self.kwargs | kwargs

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Returns:

  • int

    Kernel radius.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Source code
347
348
349
350
351
352
353
354
355
@cached_property
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    :raises CustomNotImplementedError:  If no kernel radius is defined.
    :return:                            Kernel radius.
    """
    ...

pretty_string

pretty_string() -> str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

Source code
368
369
370
371
372
373
374
375
@cached_property
def pretty_string(self) -> str:
    """
    Cached property returning a user-friendly string representation.

    :return: Pretty-printed string with arguments.
    """
    return self._pretty_string()

rescale

rescale(
    clip: VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode

Rescale a clip to the given resolution from a previously descaled clip.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target scaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target scaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • ConstantFormatVideoNode

    The scaled clip.

Source code
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
def rescale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Rescale a clip to the given resolution from a previously descaled clip.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:    The source clip.
    :param width:   Target scaled width (defaults to clip width if None).
    :param height:  Target scaled height (defaults to clip height if None).
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :return:        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.rescale_function(
        clip, **_norm_props_enums(self.get_rescale_args(clip, shift, width, height, **kwargs))
    )

Kernel

Kernel(**kwargs: Any)

Bases: Scaler, Descaler, Resampler

Abstract kernel interface combining scaling, descaling, resampling, and shifting functionality.

Subclasses are expected to implement the actual transformation logic by overriding the methods or providing the respective *_function callables (scale_function, descale_function, resample_function).

This class is abstract and should not be used directly.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the _implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the _implemented_funcs, the one passed to func takes precedence.

Parameters:

  • kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Classes:

Methods:

  • descale

    Descale a clip to the given resolution.

  • ensure_obj

    Ensure that the given kernel input is returned as a kernel instance.

  • from_param

    Resolve and return a kernel class from a string name, class type, or instance.

  • get_descale_args

    Generate and normalize argument dictionary for a descale operation.

  • get_params_args

    Generate a base set of parameters to pass for scaling, descaling, or resampling.

  • get_resample_args

    Generate and normalize argument dictionary for a resample operation.

  • get_rescale_args

    Generate and normalize argument dictionary for a rescale operation.

  • get_scale_args

    Generate and normalize argument dictionary for a scale operation.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • multi

    Deprecated alias for supersample.

  • pretty_string

    Cached property returning a user-friendly string representation.

  • resample

    Resample a video clip to the given format.

  • rescale

    Rescale a clip to the given resolution from a previously descaled clip.

  • scale

    Scale a clip to a specified resolution.

  • shift

    Apply a subpixel shift to the clip using the kernel's scaling logic.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

  • descale_function (Callable[..., ConstantFormatVideoNode]) –

    Descale function called internally when performing descaling operations.

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • resample_function (Callable[..., ConstantFormatVideoNode]) –

    Resample function called internally when performing resampling operations.

  • rescale_function (Callable[..., ConstantFormatVideoNode]) –

    Rescale function called internally when performing upscaling operations.

  • scale_function (Callable[..., VideoNode]) –

    Scale function called internally when performing scaling operations.

Source code
281
282
283
284
285
286
287
288
289
290
291
292
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to the `_implemented_funcs` methods
    but only if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the `_implemented_funcs`,
    the one passed to `func` takes precedence.

    :param kwargs:  Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

descale_function instance-attribute

descale_function: Callable[..., ConstantFormatVideoNode]

Descale function called internally when performing descaling operations.

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

resample_function instance-attribute

resample_function: Callable[..., ConstantFormatVideoNode]

Resample function called internally when performing resampling operations.

rescale_function instance-attribute

rescale_function: Callable[..., ConstantFormatVideoNode]

Rescale function called internally when performing upscaling operations.

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when performing scaling operations.

cached_property

cached_property(func: Callable[Concatenate[_BaseScalerT, P], T_co])

Bases: cached_property[T_co]

Read only version of functools.cached_property.

Source code
265
def __init__(self, func: Callable[Concatenate[_BaseScalerT, P], T_co]) -> None: ...

descale

descale(
    clip: VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode

Descale a clip to the given resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target descaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target descaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • ConstantFormatVideoNode

    The descaled clip.

Source code
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
def descale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Descale a clip to the given resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:    The source clip.
    :param width:   Target descaled width (defaults to clip width if None).
    :param height:  Target descaled height (defaults to clip height if None).
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :return:        The descaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.descale_function(
        clip, **_norm_props_enums(self.get_descale_args(clip, shift, width, height, **kwargs))
    )

ensure_obj classmethod

ensure_obj(
    kernel: KernelLike | None = None, /, func_except: FuncExceptT | None = None
) -> Self

Ensure that the given kernel input is returned as a kernel instance.

Parameters:

  • kernel

    (KernelLike | None, default: None ) –

    Kernel name, class, or instance. Defaults to current class if None.

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    The resolved and instantiated kernel.

Source code
804
805
806
807
808
809
810
811
812
813
814
@classmethod
def ensure_obj(cls, kernel: KernelLike | None = None, /, func_except: FuncExceptT | None = None) -> Self:
    """
    Ensure that the given kernel input is returned as a kernel instance.

    :param kernel:              Kernel name, class, or instance. Defaults to current class if None.
    :param func_except:         Function returned for custom error handling.

    :return:                    The resolved and instantiated kernel.
    """
    return _base_ensure_obj(cls, kernel, func_except)

from_param classmethod

from_param(
    kernel: KernelLike | None = None, /, func_except: FuncExceptT | None = None
) -> type[Self]

Resolve and return a kernel class from a string name, class type, or instance.

Parameters:

  • kernel

    (KernelLike | None, default: None ) –

    Kernel identifier as a string, class type, or instance. If None, defaults to the current class.

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • type[Self]

    The resolved kernel class.

Raises:

  • UnknownKernelError

    If the kernel could not be identified.

Source code
791
792
793
794
795
796
797
798
799
800
801
802
@classmethod
def from_param(cls, kernel: KernelLike | None = None, /, func_except: FuncExceptT | None = None) -> type[Self]:
    """
    Resolve and return a kernel class from a string name, class type, or instance.

    :param kernel:              Kernel identifier as a string, class type, or instance. If None, defaults to the current class.
    :param func_except:         Function returned for custom error handling.

    :return:                    The resolved kernel class.
    :raises UnknownKernelError: If the kernel could not be identified.
    """
    return _base_from_param(cls, kernel, cls._err_class, func_except)

get_descale_args

get_descale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a descale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the descale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the descale function.

Source code
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
def get_descale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a descale operation.

    :param clip:    The source clip.
    :param shift:   Vertical and horizontal shift to apply.
    :param width:   Target width.
    :param height:  Target height.
    :param kwargs:  Additional arguments to pass to the descale function.

    :return:        Dictionary of keyword arguments for the descale function.
    """
    return dict(src_top=shift[0], src_left=shift[1]) | self.get_params_args(True, clip, width, height, **kwargs)

get_params_args

get_params_args(
    is_descale: bool,
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate a base set of parameters to pass for scaling, descaling, or resampling.

Parameters:

  • is_descale

    (bool) –

    Whether this is for a descale operation.

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • kwargs

    (Any, default: {} ) –

    Additional keyword arguments to include.

Returns:

  • dict[str, Any]

    Dictionary of combined parameters.

Source code
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
def get_params_args(
    self, is_descale: bool, clip: vs.VideoNode, width: int | None = None, height: int | None = None, **kwargs: Any
) -> dict[str, Any]:
    """
    Generate a base set of parameters to pass for scaling, descaling, or resampling.

    :param is_descale:  Whether this is for a descale operation.
    :param clip:        The source clip.
    :param width:       Target width.
    :param height:      Target height.
    :param kwargs:      Additional keyword arguments to include.

    :return:            Dictionary of combined parameters.
    """
    return dict(width=width, height=height) | self.kwargs | kwargs

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a resample operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (int | VideoFormatT | HoldsVideoFormatT) –

    The target video format, which can either be: - an integer format ID, - a vs.PresetVideoFormat or vs.VideoFormat, - or a source from which a valid VideoFormat can be extracted.

  • matrix

    (MatrixT | None) –

    Target color matrix.

  • matrix_in

    (MatrixT | None) –

    Source color matrix.

  • kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the resample function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the resample function.

Source code
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
def get_resample_args(
    self,
    clip: vs.VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a resample operation.

    :param clip:        The source clip.
    :param format:      The target video format, which can either be:
                            - an integer format ID,
                            - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
                            - or a source from which a valid `VideoFormat` can be extracted.
    :param matrix:      Target color matrix.
    :param matrix_in:   Source color matrix.
    :param kwargs:      Additional arguments to pass to the resample function.

    :return:            Dictionary of keyword arguments for the resample function.
    """
    return dict(
        format=get_video_format(format).id, matrix=Matrix.from_param(matrix), matrix_in=Matrix.from_param(matrix_in)
    ) | self.get_params_args(False, clip, **kwargs)

get_rescale_args

get_rescale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a rescale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the rescale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the rescale function.

Source code
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
def get_rescale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a rescale operation.

    :param clip:    The source clip.
    :param shift:   Vertical and horizontal shift to apply.
    :param width:   Target width.
    :param height:  Target height.
    :param kwargs:  Additional arguments to pass to the rescale function.

    :return:        Dictionary of keyword arguments for the rescale function.
    """
    return dict(src_top=shift[0], src_left=shift[1]) | self.get_params_args(True, clip, width, height, **kwargs)

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate and normalize argument dictionary for a scale operation.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Vertical and horizontal shift to apply.

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • kwargs

    (Any, default: {} ) –

    Additional arguments to pass to the scale function.

Returns:

  • dict[str, Any]

    Dictionary of keyword arguments for the scale function.

Source code
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
def get_scale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate and normalize argument dictionary for a scale operation.

    :param clip:    The source clip.
    :param shift:   Vertical and horizontal shift to apply.
    :param width:   Target width.
    :param height:  Target height.
    :param kwargs:  Additional arguments to pass to the scale function.

    :return:        Dictionary of keyword arguments for the scale function.
    """
    return dict(src_top=shift[0], src_left=shift[1]) | self.get_params_args(False, clip, width, height, **kwargs)

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Returns:

  • int

    Kernel radius.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Source code
347
348
349
350
351
352
353
354
355
@cached_property
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    :raises CustomNotImplementedError:  If no kernel radius is defined.
    :return:                            Kernel radius.
    """
    ...

multi

multi(
    clip: VideoNodeT,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNodeT

Deprecated alias for supersample.

Parameters:

  • clip

    (VideoNodeT) –

    The source clip.

  • multi

    (float, default: 2.0 ) –

    Supersampling factor.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

Source code
451
452
453
454
455
456
457
458
459
460
461
462
463
464
@deprecated('The "multi" method is deprecated. Use "supersample" instead.', category=DeprecationWarning)
def multi(
    self, clip: VideoNodeT, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNodeT:
    """
    Deprecated alias for `supersample`.

    :param clip:    The source clip.
    :param multi:   Supersampling factor.
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :param kwargs:  Additional arguments forwarded to the scale function.
    :return:        The supersampled clip.
    """
    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

Source code
368
369
370
371
372
373
374
375
@cached_property
def pretty_string(self) -> str:
    """
    Cached property returning a user-friendly string representation.

    :return: Pretty-printed string with arguments.
    """
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode

Resample a video clip to the given format.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (int | VideoFormatT | HoldsVideoFormatT) –

    The target video format, which can either be: - an integer format ID, - a vs.PresetVideoFormat or vs.VideoFormat, - or a source from which a valid VideoFormat can be extracted.

  • matrix

    (MatrixT | None, default: None ) –

    An optional color transformation matrix to apply.

  • matrix_in

    (MatrixT | None, default: None ) –

    An optional input matrix for color transformations.

  • kwargs

    (Any, default: {} ) –

    Additional keyword arguments passed to the resample_function.

Returns:

  • ConstantFormatVideoNode

    The resampled clip.

Source code
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
def resample(
    self,
    clip: vs.VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Resample a video clip to the given format.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:        The source clip.
    :param format:      The target video format, which can either be:
                            - an integer format ID,
                            - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
                            - or a source from which a valid `VideoFormat` can be extracted.
    :param matrix:      An optional color transformation matrix to apply.
    :param matrix_in:   An optional input matrix for color transformations.
    :param kwargs:      Additional keyword arguments passed to the `resample_function`.
    :return:            The resampled clip.
    """
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

rescale

rescale(
    clip: VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> ConstantFormatVideoNode

Rescale a clip to the given resolution from a previously descaled clip.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None) –

    Target scaled width (defaults to clip width if None).

  • height

    (int | None) –

    Target scaled height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

Returns:

  • ConstantFormatVideoNode

    The scaled clip.

Source code
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
def rescale(
    self,
    clip: vs.VideoNode,
    width: int | None,
    height: int | None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Rescale a clip to the given resolution from a previously descaled clip.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:    The source clip.
    :param width:   Target scaled width (defaults to clip width if None).
    :param height:  Target scaled height (defaults to clip height if None).
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :return:        The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.rescale_function(
        clip, **_norm_props_enums(self.get_rescale_args(clip, shift, width, height, **kwargs))
    )

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode | ConstantFormatVideoNode

Scale a clip to a specified resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width (defaults to clip width if None).

  • height

    (int | None, default: None ) –

    Target height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

  • VideoNode | ConstantFormatVideoNode

    The scaled clip.

Source code
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode | ConstantFormatVideoNode:
    """
    Scale a clip to a specified resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:        The source clip.
    :param width:       Target width (defaults to clip width if None).
    :param height:      Target height (defaults to clip height if None).
    :param shift:       Subpixel shift (top, left) applied during scaling.
    :param kwargs:      Additional arguments forwarded to the scale function.
    :return:            The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.scale_function(clip, **_norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs)))

shift

shift(
    clip: VideoNode, shift: tuple[TopShift, LeftShift], /, **kwargs: Any
) -> ConstantFormatVideoNode
shift(
    clip: VideoNode,
    shift_top: float | list[float],
    shift_left: float | list[float],
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode
shift(
    clip: VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float],
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode

Apply a subpixel shift to the clip using the kernel's scaling logic.

If a single float or tuple is provided, it is used uniformly. If a list is given, the shift is applied per plane.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shifts_or_top

    (float | tuple[float, float] | list[float]) –

    Either a single vertical shift, a (top, left) tuple, or a list of vertical shifts.

  • shift_left

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

    Horizontal shift or list of horizontal shifts. Ignored if shifts_or_top is a tuple.

  • kwargs

    (Any, default: {} ) –

    Additional arguments passed to the internal scale call.

Returns:

  • ConstantFormatVideoNode

    A new clip with the applied shift.

Raises:

  • VariableFormatError

    If the input clip has variable format.

  • CustomValueError

    If the input clip is GRAY but lists of shift has been passed.

Source code
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
def shift(
    self,
    clip: vs.VideoNode,
    shifts_or_top: float | tuple[float, float] | list[float],
    shift_left: float | list[float] | None = None,
    /,
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Apply a subpixel shift to the clip using the kernel's scaling logic.

    If a single float or tuple is provided, it is used uniformly.
    If a list is given, the shift is applied per plane.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:                    The source clip.
    :param shifts_or_top:           Either a single vertical shift, a (top, left) tuple, or a list of vertical shifts.
    :param shift_left:              Horizontal shift or list of horizontal shifts. Ignored if `shifts_or_top` is a tuple.
    :param kwargs:                  Additional arguments passed to the internal `scale` call.

    :return:                        A new clip with the applied shift.
    :raises VariableFormatError:    If the input clip has variable format.
    :raises CustomValueError:       If the input clip is GRAY but lists of shift has been passed.
    """
    assert check_variable_format(clip, self.shift)

    n_planes = clip.format.num_planes

    def _shift(src: vs.VideoNode, shift: tuple[TopShift, LeftShift] = (0, 0)) -> ConstantFormatVideoNode:
        return self.scale(src, shift=shift, **kwargs)  # type: ignore[return-value]

    if isinstance(shifts_or_top, tuple):
        return _shift(clip, shifts_or_top)

    if isinstance(shifts_or_top, (int, float)) and isinstance(shift_left, (int, float, NoneType)):
        return _shift(clip, (shifts_or_top, shift_left or 0))

    if shift_left is None:
        shift_left = 0.0

    shifts_top = normalize_seq(shifts_or_top, n_planes)
    shifts_left = normalize_seq(shift_left, n_planes)

    if n_planes == 1:
        if len(set(shifts_top)) > 1 or len(set(shifts_left)) > 1:
            raise CustomValueError(
                "Inconsistent shift values detected for a single plane. "
                "All shift values must be identical when passing a GRAY clip.",
                self.shift,
                (shifts_top, shifts_left),
            )

        return _shift(clip, (shifts_top[0], shifts_left[0]))

    shifted_planes = [
        plane if top == left == 0 else _shift(plane, (top, left))
        for plane, top, left in zip(split(clip), shifts_top, shifts_left)
    ]

    return core.std.ShufflePlanes(shifted_planes, [0, 0, 0], clip.format.color_family)

supersample

supersample(
    clip: VideoNodeT,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNodeT

Supersample a clip by a given scaling factor.

Parameters:

  • clip

    (VideoNodeT) –

    The source clip.

  • rfactor

    (float, default: 2.0 ) –

    Scaling factor for supersampling.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

Raises:

  • CustomValueError

    If resulting resolution is non-positive.

Source code
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
def supersample(
    self, clip: VideoNodeT, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNodeT:
    """
    Supersample a clip by a given scaling factor.

    :param clip:                The source clip.
    :param rfactor:             Scaling factor for supersampling.
    :param shift:               Subpixel shift (top, left) applied during scaling.
    :param kwargs:              Additional arguments forwarded to the scale function.
    :raises CustomValueError:   If resulting resolution is non-positive.
    :return:                    The supersampled clip.
    """
    assert check_variable_resolution(clip, self.supersample)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!',
            self.supersample,
            rfactor,
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)  # type: ignore[return-value]

Resampler

Resampler(**kwargs: Any)

Bases: BaseScaler

Abstract resampling interface.

Subclasses must define the resample_function used to perform the resampling.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the _implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the _implemented_funcs, the one passed to func takes precedence.

Parameters:

  • kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Classes:

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_resample_args

    Construct the argument dictionary used for resampling.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • pretty_string

    Cached property returning a user-friendly string representation.

  • resample

    Resample a video clip to the given format.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • resample_function (Callable[..., ConstantFormatVideoNode]) –

    Resample function called internally when performing resampling operations.

Source code
281
282
283
284
285
286
287
288
289
290
291
292
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to the `_implemented_funcs` methods
    but only if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the `_implemented_funcs`,
    the one passed to `func` takes precedence.

    :param kwargs:  Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

resample_function instance-attribute

resample_function: Callable[..., ConstantFormatVideoNode]

Resample function called internally when performing resampling operations.

cached_property

cached_property(func: Callable[Concatenate[_BaseScalerT, P], T_co])

Bases: cached_property[T_co]

Read only version of functools.cached_property.

Source code
265
def __init__(self, func: Callable[Concatenate[_BaseScalerT, P], T_co]) -> None: ...

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • type[Self]

    Resolved scaler type.

Source code
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_resample_args

get_resample_args(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    **kwargs: Any
) -> dict[str, Any]

Construct the argument dictionary used for resampling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (int | VideoFormatT | HoldsVideoFormatT) –

    The target video format, which can either be: - an integer format ID, - a vs.PresetVideoFormat or vs.VideoFormat, - or a source from which a valid VideoFormat can be extracted.

  • matrix

    (MatrixT | None) –

    The matrix for color transformation.

  • matrix_in

    (MatrixT | None) –

    The input matrix for color transformation.

  • kwargs

    (Any, default: {} ) –

    Additional keyword arguments for resampling.

Returns:

  • dict[str, Any]

    A dictionary containing the resampling arguments.

Source code
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
def get_resample_args(
    self,
    clip: vs.VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None,
    matrix_in: MatrixT | None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Construct the argument dictionary used for resampling.

    :param clip:        The source clip.
    :param format:      The target video format, which can either be:
                            - an integer format ID,
                            - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
                            - or a source from which a valid `VideoFormat` can be extracted.
    :param matrix:      The matrix for color transformation.
    :param matrix_in:   The input matrix for color transformation.
    :param kwargs:      Additional keyword arguments for resampling.
    :return:            A dictionary containing the resampling arguments.
    """
    return (
        dict(
            format=get_video_format(format).id,
            matrix=Matrix.from_param(matrix),
            matrix_in=Matrix.from_param(matrix_in),
        )
        | self.kwargs
        | kwargs
    )

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Returns:

  • int

    Kernel radius.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Source code
347
348
349
350
351
352
353
354
355
@cached_property
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    :raises CustomNotImplementedError:  If no kernel radius is defined.
    :return:                            Kernel radius.
    """
    ...

pretty_string

pretty_string() -> str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

Source code
368
369
370
371
372
373
374
375
@cached_property
def pretty_string(self) -> str:
    """
    Cached property returning a user-friendly string representation.

    :return: Pretty-printed string with arguments.
    """
    return self._pretty_string()

resample

resample(
    clip: VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any
) -> ConstantFormatVideoNode

Resample a video clip to the given format.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • format

    (int | VideoFormatT | HoldsVideoFormatT) –

    The target video format, which can either be: - an integer format ID, - a vs.PresetVideoFormat or vs.VideoFormat, - or a source from which a valid VideoFormat can be extracted.

  • matrix

    (MatrixT | None, default: None ) –

    An optional color transformation matrix to apply.

  • matrix_in

    (MatrixT | None, default: None ) –

    An optional input matrix for color transformations.

  • kwargs

    (Any, default: {} ) –

    Additional keyword arguments passed to the resample_function.

Returns:

  • ConstantFormatVideoNode

    The resampled clip.

Source code
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
def resample(
    self,
    clip: vs.VideoNode,
    format: int | VideoFormatT | HoldsVideoFormatT,
    matrix: MatrixT | None = None,
    matrix_in: MatrixT | None = None,
    **kwargs: Any,
) -> ConstantFormatVideoNode:
    """
    Resample a video clip to the given format.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:        The source clip.
    :param format:      The target video format, which can either be:
                            - an integer format ID,
                            - a `vs.PresetVideoFormat` or `vs.VideoFormat`,
                            - or a source from which a valid `VideoFormat` can be extracted.
    :param matrix:      An optional color transformation matrix to apply.
    :param matrix_in:   An optional input matrix for color transformations.
    :param kwargs:      Additional keyword arguments passed to the `resample_function`.
    :return:            The resampled clip.
    """
    return self.resample_function(
        clip, **_norm_props_enums(self.get_resample_args(clip, format, matrix, matrix_in, **kwargs))
    )

Scaler

Scaler(**kwargs: Any)

Bases: BaseScaler

Abstract scaling interface.

Subclasses should define a scale_function to perform the actual scaling logic.

Initialize the scaler with optional keyword arguments.

These keyword arguments are automatically forwarded to the _implemented_funcs methods but only if the method explicitly accepts them as named parameters. If the same keyword is passed to both __init__ and one of the _implemented_funcs, the one passed to func takes precedence.

Parameters:

  • kwargs

    (Any, default: {} ) –

    Keyword arguments that configure the internal scaling behavior.

Classes:

Methods:

  • ensure_obj

    Ensure that the input is a scaler instance, resolving it if necessary.

  • from_param

    Resolve and return a scaler type from a given input (string, type, or instance).

  • get_scale_args

    Generate the keyword arguments used for scaling.

  • kernel_radius

    Return the effective kernel radius for the scaler.

  • multi

    Deprecated alias for supersample.

  • pretty_string

    Cached property returning a user-friendly string representation.

  • scale

    Scale a clip to a specified resolution.

  • supersample

    Supersample a clip by a given scaling factor.

Attributes:

  • kwargs (dict[str, Any]) –

    Arguments passed to the implemented funcs or internal scale function.

  • scale_function (Callable[..., VideoNode]) –

    Scale function called internally when performing scaling operations.

Source code
281
282
283
284
285
286
287
288
289
290
291
292
def __init__(self, **kwargs: Any) -> None:
    """
    Initialize the scaler with optional keyword arguments.

    These keyword arguments are automatically forwarded to the `_implemented_funcs` methods
    but only if the method explicitly accepts them as named parameters.
    If the same keyword is passed to both `__init__` and one of the `_implemented_funcs`,
    the one passed to `func` takes precedence.

    :param kwargs:  Keyword arguments that configure the internal scaling behavior.
    """
    self.kwargs = kwargs

kwargs instance-attribute

kwargs: dict[str, Any] = kwargs

Arguments passed to the implemented funcs or internal scale function.

scale_function instance-attribute

scale_function: Callable[..., VideoNode]

Scale function called internally when performing scaling operations.

cached_property

cached_property(func: Callable[Concatenate[_BaseScalerT, P], T_co])

Bases: cached_property[T_co]

Read only version of functools.cached_property.

Source code
265
def __init__(self, func: Callable[Concatenate[_BaseScalerT, P], T_co]) -> None: ...

ensure_obj classmethod

ensure_obj(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self

Ensure that the input is a scaler instance, resolving it if necessary.

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Scaler instance.

Source code
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@classmethod
def ensure_obj(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> Self:
    """
    Ensure that the input is a scaler instance, resolving it if necessary.

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Scaler instance.
    """
    return _base_ensure_obj(cls, scaler, func_except)

from_param classmethod

from_param(
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]

Resolve and return a scaler type from a given input (string, type, or instance).

Parameters:

  • scaler

    (str | type[Self] | Self | None, default: None ) –

    Scaler identifier (string, class, or instance).

  • func_except

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • type[Self]

    Resolved scaler type.

Source code
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@classmethod
def from_param(
    cls,
    scaler: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExceptT | None = None,
) -> type[Self]:
    """
    Resolve and return a scaler type from a given input (string, type, or instance).

    :param scaler:          Scaler identifier (string, class, or instance).
    :param func_except:     Function returned for custom error handling.
    :return:                Resolved scaler type.
    """
    return _base_from_param(cls, scaler, cls._err_class, func_except)

get_scale_args

get_scale_args(
    clip: VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any
) -> dict[str, Any]

Generate the keyword arguments used for scaling.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left).

  • width

    (int | None, default: None ) –

    Target width.

  • height

    (int | None, default: None ) –

    Target height.

  • kwargs

    (Any, default: {} ) –

    Extra parameters to merge.

Returns:

  • dict[str, Any]

    Final dictionary of keyword arguments for the scale function.

Source code
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
def get_scale_args(
    self,
    clip: vs.VideoNode,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    width: int | None = None,
    height: int | None = None,
    **kwargs: Any,
) -> dict[str, Any]:
    """
    Generate the keyword arguments used for scaling.

    :param clip:    The source clip.
    :param shift:   Subpixel shift (top, left).
    :param width:   Target width.
    :param height:  Target height.
    :param kwargs:  Extra parameters to merge.
    :return:        Final dictionary of keyword arguments for the scale function.
    """
    return dict(width=width, height=height, src_top=shift[0], src_left=shift[1]) | self.kwargs | kwargs

kernel_radius

kernel_radius() -> int

Return the effective kernel radius for the scaler.

Returns:

  • int

    Kernel radius.

Raises:

  • CustomNotImplementedError

    If no kernel radius is defined.

Source code
347
348
349
350
351
352
353
354
355
@cached_property
def kernel_radius(self) -> int:
    """
    Return the effective kernel radius for the scaler.

    :raises CustomNotImplementedError:  If no kernel radius is defined.
    :return:                            Kernel radius.
    """
    ...

multi

multi(
    clip: VideoNodeT,
    multi: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNodeT

Deprecated alias for supersample.

Parameters:

  • clip

    (VideoNodeT) –

    The source clip.

  • multi

    (float, default: 2.0 ) –

    Supersampling factor.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

Source code
451
452
453
454
455
456
457
458
459
460
461
462
463
464
@deprecated('The "multi" method is deprecated. Use "supersample" instead.', category=DeprecationWarning)
def multi(
    self, clip: VideoNodeT, multi: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNodeT:
    """
    Deprecated alias for `supersample`.

    :param clip:    The source clip.
    :param multi:   Supersampling factor.
    :param shift:   Subpixel shift (top, left) applied during scaling.
    :param kwargs:  Additional arguments forwarded to the scale function.
    :return:        The supersampled clip.
    """
    return self.supersample(clip, multi, shift, **kwargs)

pretty_string

pretty_string() -> str

Cached property returning a user-friendly string representation.

Returns:

  • str

    Pretty-printed string with arguments.

Source code
368
369
370
371
372
373
374
375
@cached_property
def pretty_string(self) -> str:
    """
    Cached property returning a user-friendly string representation.

    :return: Pretty-printed string with arguments.
    """
    return self._pretty_string()

scale

scale(
    clip: VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNode | ConstantFormatVideoNode

Scale a clip to a specified resolution.

Keyword arguments passed during initialization are automatically injected here, unless explicitly overridden by the arguments provided at call time. Only arguments that match named parameters in this method are injected.

Parameters:

  • clip

    (VideoNode) –

    The source clip.

  • width

    (int | None, default: None ) –

    Target width (defaults to clip width if None).

  • height

    (int | None, default: None ) –

    Target height (defaults to clip height if None).

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

  • VideoNode | ConstantFormatVideoNode

    The scaled clip.

Source code
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
def scale(
    self,
    clip: vs.VideoNode,
    width: int | None = None,
    height: int | None = None,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any,
) -> vs.VideoNode | ConstantFormatVideoNode:
    """
    Scale a clip to a specified resolution.

    Keyword arguments passed during initialization are automatically injected here,
    unless explicitly overridden by the arguments provided at call time.
    Only arguments that match named parameters in this method are injected.

    :param clip:        The source clip.
    :param width:       Target width (defaults to clip width if None).
    :param height:      Target height (defaults to clip height if None).
    :param shift:       Subpixel shift (top, left) applied during scaling.
    :param kwargs:      Additional arguments forwarded to the scale function.
    :return:            The scaled clip.
    """
    width, height = self._wh_norm(clip, width, height)
    check_correct_subsampling(clip, width, height)

    return self.scale_function(clip, **_norm_props_enums(self.get_scale_args(clip, shift, width, height, **kwargs)))

supersample

supersample(
    clip: VideoNodeT,
    rfactor: float = 2.0,
    shift: tuple[TopShift, LeftShift] = (0, 0),
    **kwargs: Any
) -> VideoNodeT

Supersample a clip by a given scaling factor.

Parameters:

  • clip

    (VideoNodeT) –

    The source clip.

  • rfactor

    (float, default: 2.0 ) –

    Scaling factor for supersampling.

  • shift

    (tuple[TopShift, LeftShift], default: (0, 0) ) –

    Subpixel shift (top, left) applied during scaling.

  • kwargs

    (Any, default: {} ) –

    Additional arguments forwarded to the scale function.

Returns:

Raises:

  • CustomValueError

    If resulting resolution is non-positive.

Source code
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
def supersample(
    self, clip: VideoNodeT, rfactor: float = 2.0, shift: tuple[TopShift, LeftShift] = (0, 0), **kwargs: Any
) -> VideoNodeT:
    """
    Supersample a clip by a given scaling factor.

    :param clip:                The source clip.
    :param rfactor:             Scaling factor for supersampling.
    :param shift:               Subpixel shift (top, left) applied during scaling.
    :param kwargs:              Additional arguments forwarded to the scale function.
    :raises CustomValueError:   If resulting resolution is non-positive.
    :return:                    The supersampled clip.
    """
    assert check_variable_resolution(clip, self.supersample)

    dst_width, dst_height = ceil(clip.width * rfactor), ceil(clip.height * rfactor)

    if max(dst_width, dst_height) <= 0.0:
        raise CustomValueError(
            'Multiplying the resolution by "rfactor" must result in a positive resolution!',
            self.supersample,
            rfactor,
        )

    return self.scale(clip, dst_width, dst_height, shift, **kwargs)  # type: ignore[return-value]