lvsfunc.kernels

Kernels are a collection of wrappers pertaining to (de)scaling, format conversion, and other related operations, all while providing a consistent and clean interface. This allows for easy expansion and ease of use for any other maintainers who wishes to use them in their own functions.

You can create presets for common scaling algorithms or settings, while ensuring the interface will always remain the same, even across different plugins with their own settings and expected behavior.

For example, if you want to downscale a video clip to 1280x720 using Bicubic (b=0, c=1), you can call the preset, lvsfunc.kernels.SharpBicubic, like so:

lvf.kernels.SharpBicubic().scale(clip, width=1280, height=720)

Of course, there is also a generic Bicubic class should you want to assign the values manually.

lvf.kernels.Bicubic(b=0, c=1).scale(clip, width=1280, height=720)

This allows for easy customizability, and every kernel can be given unique parameters if required.

lvf.kernels.Bicubic(b=0, c=0.5)
lvf.kernels.Lanczos(taps=3)
lvf.kernels.Impulse(impulse, oversample=8, taps=1)

Using this interface allows for consistency, which makes supporting a wide array of kernels in your own function very simple.

Supporting Kernels in Your Own Function

lvsfunc.kernels.get_kernel(name)

Get a kernel by name.

lvsfunc.kernels.get_all_kernels()

Get all kernels as a list.

Kernels are very flexible, so if you want to use them as-is, they’re simple enough to add. However, you should also consider newer users and their inexperience with Kernels, but potential exposure to abusing strings for “presets”.

With that in mind, we believe the most optimal method to implement kernels is by allowing your function to accept both a Kernel object and a string. This allows users who want to make full use of kernels to do so while not making it any harder for newer users to rely on strings.

Below is some example code for implementing kernel support into a simple descaling function:

from lvsfunc.kernels import Kernel, get_kernel

def descale(clip: vs.VideoNode,
            width: int = 1280, height: int = 720,
            kernel: Kernel | str = 'bicubic') -> vs.VideoNode:
    """A simple descaling function"""

    if isinstance(kernel, str):
        kernel = get_kernel(kernel)()

    descaled_clip = kernel.descale(clip, width, height)
    return descaled_clip

Which in turn allows users to call the function in multiple ways:

import lvsfunc as lvf

example1 = descale(clip, 1280, 720, lvf.kernels.Bicubic())
example2 = descale(clip, 1280, 720, 'bicubic')

Easy as pie!

Functions

class lvsfunc.kernels.get_kernel(name)

Get a kernel by name.

Parameters

name (str) – Kernel name.

Return type

Type[Kernel]

Returns

Kernel class.

class lvsfunc.kernels.get_all_kernels

Get all kernels as a list.

Return type

List[Type[Kernel]]

Methods

Every Kernel class comes with a set of methods:

class lvsfunc.kernels.Example.scale(self, clip, width, height, shift=(0, 0))

Perform a regular scaling operation

Parameters
  • clip (VideoNode) – Input clip

  • width (int) – Output width

  • height (int) – Output height

  • shift (Tuple[float, float]) – Shift clip during the operation. Expects a tuple of (src_top, src_left).

Return type

VideoNode

class lvsfunc.kernels.Example.descale(self, clip, width, height, shift=(0, 0))

Perform a regular descaling operation

Parameters
  • clip (VideoNode) – Input clip

  • width (int) – Output width

  • height (int) – Output height

  • shift (Tuple[float, float]) – Shift clip during the operation. Expects a tuple of (src_top, src_left).

Return type

VideoNode

class lvsfunc.kernels.Example.shift(self, clip, shift=(0, 0))

Perform a regular shifting operation

Parameters
  • clip (VideoNode) – Input clip

  • shift (Tuple[float, float]) – Shift clip during the operation. Expects a tuple of (src_top, src_left).

Return type

VideoNode

class lvsfunc.kernels.Example.resample(self, clip, format, matrix=None, matrix_in=None)

Perform a regular resampling operation

Parameters
  • clip (vs.VideoNode) – Input clip

  • format (vs.PresetFormat | vs.VideoFormat) – Output format

  • matrix (vs.MatrixCoefficients | Matrix | None) – Output matrix. If None, will take the matrix from the input clip’s frameprops.

  • matrix_in (vs.MatrixCoefficients | Matrix | None) – Input matrix. If None, will take the matrix from the input clip’s frameprops.

Return type

VideoNode

All Available Kernels

Note

There are still a lot of unsupported kernels! If you know of any we’re missing, please contact us!
class lvsfunc.kernels.BSpline(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=1, c=0

class lvsfunc.kernels.Bessel(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Bessel kernel.

class lvsfunc.kernels.Bicubic(b=0, c=0.5, **kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in bicubic resizer. b=0, c=0.5

Dependencies:

  • VapourSynth-descale

Parameters
  • b (float) – B-param for bicubic kernel

  • c (float) – C-param for bicubic kernel

class lvsfunc.kernels.BicubicDidee(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Kernel inspired by a Didée post.

Bicubic b=-0.5, c=0.25

This is useful for downscaling content, but might not help much with upscaling.

class lvsfunc.kernels.BicubicDogWay(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Kernel inspired by DogWay.

Bicubic b=-0.6, c=0.4

This is useful for downscaling content with ringing.

class lvsfunc.kernels.BicubicSharp(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0, c=1

class lvsfunc.kernels.Bilinear(**kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in bilinear resizer.

class lvsfunc.kernels.BlackHarris(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Black-Harris kernel.

class lvsfunc.kernels.BlackMan(taps=4, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s blackman resizer.

class lvsfunc.kernels.BlackManMinLobe(taps=4, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s blackmanminlobe resizer.

class lvsfunc.kernels.BlackNuttall(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

BlackNuttall kernel.

class lvsfunc.kernels.Bohman(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Bohman kernel.

class lvsfunc.kernels.Box(taps=4, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s box resizer.

class lvsfunc.kernels.Catrom(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0, c=0.5

class lvsfunc.kernels.Cosine(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Cosine kernel.

class lvsfunc.kernels.FlatTop(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

FlatTop kernel.

class lvsfunc.kernels.FmtConv(taps=4, **kwargs)

Bases: lvsfunc.kernels.Kernel

Abstract fmtconv’s resizer.

Dependencies:

  • fmtconv

class lvsfunc.kernels.Gaussian(curve=30, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s gaussian resizer.

class lvsfunc.kernels.Ginseng(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Ginseng kernel.

class lvsfunc.kernels.Hamming(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Hamming kernel.

class lvsfunc.kernels.Hann(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Hann kernel.

class lvsfunc.kernels.Hermite(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0, c=0

class lvsfunc.kernels.Impulse(impulse, oversample=8, taps=1, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s impulse resizer.

class lvsfunc.kernels.Kaiser(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Kaiser kernel.

class lvsfunc.kernels.Lanczos(taps=3, **kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in lanczos resizer.

Dependencies:

  • VapourSynth-descale

Parameters

taps (int) – taps param for lanczos kernel

class lvsfunc.kernels.MinSide(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

MinSide kernel.

class lvsfunc.kernels.Mitchell(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=1/3, c=1/3

class lvsfunc.kernels.NearestNeighbour(**kwargs)

Bases: lvsfunc.kernels.Gaussian

Nearest Neighbour kernel.

class lvsfunc.kernels.Parzen(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Parzen kernel.

class lvsfunc.kernels.Point(**kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in point resizer.

class lvsfunc.kernels.Quadratic(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Quadratic kernel.

class lvsfunc.kernels.Robidoux(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0.37822, c=0.31089

class lvsfunc.kernels.RobidouxSharp(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0.26201, c=0.36899

class lvsfunc.kernels.RobidouxSoft(**kwargs)

Bases: lvsfunc.kernels.Bicubic

Bicubic b=0.67962, c=0.16019

class lvsfunc.kernels.Sinc(taps=4, **kwargs)

Bases: lvsfunc.kernels.FmtConv

fmtconv’s sinc resizer.

class lvsfunc.kernels.Spline16(**kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in spline16 resizer.

Dependencies:

  • VapourSynth-descale

class lvsfunc.kernels.Spline36(**kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in spline36 resizer.

Dependencies:

  • VapourSynth-descale

class lvsfunc.kernels.Spline64(**kwargs)

Bases: lvsfunc.kernels.Kernel

Built-in spline64 resizer.

Dependencies:

  • VapourSynth-descale

class lvsfunc.kernels.Welch(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Welch kernel.

class lvsfunc.kernels.Wiener(oversample, **kwargs)

Bases: lvsfunc.kernels.Impulse

Wiener kernel.