lvsfunc.misc

Miscellaneous functions and wrappers that don’t really have a place elsewhere.

lvsfunc.misc.edgefixer(clip[, left, right, ...])

Fix the issues with over- and undershoot for ContinuityFixer.

lvsfunc.misc.limit_dark(clip, filtered[, ...])

Replace frames in a clip with a filtered clip when the frame's luminosity exceeds the threshold.

lvsfunc.misc.overlay_sign(clip, overlay[, ...])

Overlay a logo or sign onto another clip.

lvsfunc.misc.shift_tint(clip[, values])

Forcibly adds pixel values to a clip.

lvsfunc.misc.source(path[, ref, film_thr, ...])

Index and load video clips for use in VapourSynth automatically.

lvsfunc.misc.unsharpen(clip[, strength, ...])

Diff'd unsharpening function.

lvsfunc.misc.wipe_row(clip[, ref, pos, ...])

Wipe a row or column with a blank clip.

lvsfunc.misc.edgefixer(clip, left=None, right=None, top=None, bottom=None, radius=None, full_range=False)

Fix the issues with over- and undershoot for ContinuityFixer.

This also adds what are in my opinion “more sane” ways of handling the parameters and given values.

…If possible, you should be using bbmod instead, though.

Alias for this function is lvsfunc.ef.

Warning

This function may be rewritten in the future, and functionality may change!

Dependencies:

Parameters
  • clip (VideoNode) – Clip to process.

  • left (Union[int, List[int], None]) – Number of pixels to fix on the left (Default: None).

  • right (Union[int, List[int], None]) – Number of pixels to fix on the right (Default: None).

  • top (Union[int, List[int], None]) – Number of pixels to fix on the top (Default: None).

  • bottom (Union[int, List[int], None]) – Number of pixels to fix on the bottom (Default: None).

  • radius (Optional[List[int]]) – Radius for edgefixing (Default: None).

  • full_range (bool) – Does not run the expression over the clip to fix over/undershoot (Default: False).

Return type

VideoNode

Returns

Clip with fixed edges.

lvsfunc.misc.limit_dark(clip, filtered, threshold=0.25, threshold_range=None)

Replace frames in a clip with a filtered clip when the frame’s luminosity exceeds the threshold.

This way you can run lighter (or heavier) filtering on scenes that are almost entirely dark.

There is one caveat, however: You can get scenes where every other frame is filtered rather than the entire scene. Please do take care to avoid that if possible.

Parameters
  • clip (VideoNode) – Clip to process.

  • filtered (VideoNode) – Filtered clip.

  • threshold (float) – Threshold for frame averages to be filtered (Default: 0.25).

  • threshold_range (Optional[int]) – Threshold for a range of frame averages to be filtered (Default: None).

Return type

VideoNode

Returns

Conditionally filtered clip.

Raises

ValueErrorthreshold_range is a higher value than threshold.

lvsfunc.misc.overlay_sign(clip, overlay, frame_ranges=None, fade_length=0, matrix=None)

Overlay a logo or sign onto another clip.

This is a rewrite of fvsfunc.InsertSign.

This wrapper also allows you to set fades to fade a logo in and out.

Dependencies:

Parameters
  • clip (vs.VideoNode) – Clip to process.

  • overlay (vs.VideoNode | str) – Sign or logo to overlay. Must be the png loaded in through core.vapoursnth.imwri.Read() or a path string to the image file, and MUST be the same dimensions as the clip to process.

  • frame_ranges (Range | List[Range] | None) – Frame ranges or starting frame to apply the overlay to. See lvsfunc.types.Range for more info. If None, overlays the entire clip. If a Range is passed, the overlaid clip will only show up inside that range. If only a single integer is given, it will start on that frame and stay until the end of the clip. Note that this function only accepts a single Range! You can’t pass a list of them!

  • fade_length (int) – Length to fade the clips into each other. The fade will start and end on the frames given in frame_ranges. If set to 0, it won’t fade and the sign will simply pop in.

  • matrix (Matrix | int | None) – Enum for the matrix of the Clip to process. See lvsfunc.types.Matrix for more info. If not specified, gets matrix from the “_Matrix” prop of the clip unless it’s an RGB clip, in which case it stays as None.

Return type

vs.VideoNode

Returns

Clip with a logo or sign overlaid on top for the given frame ranges, either with or without a fade.

Raises
  • ModuleNotFoundError – Dependencies are missing.

  • ValueErroroverlay is not a VideoNode or a path.

  • ValueError – The overlay clip is not of the same dimensions as the input clip.

  • InvalidMatrixErrorMatrix is an invalid value.

  • ValueError – Overlay does not have an alpha channel.

  • TypeError – Overlay clip was not loaded in using vapoursynth.core.imwri.Read().

lvsfunc.misc.shift_tint(clip, values=16)

Forcibly adds pixel values to a clip.

Can be used to fix green tints in Crunchyroll sources, for example. Only use this if you know what you’re doing!

This function accepts a single integer or a list of integers. Values passed should mimic those of an 8bit clip. If your clip is not 8bit, they will be scaled accordingly.

If you only pass 1 value, it will copied to every plane. If you pass 2, the 2nd one will be copied over to the 3rd. Don’t pass more than three.

Parameters
  • clip (VideoNode) – Clip to process.

  • values (Union[int, Sequence[int]]) – Value added to every pixel, scales accordingly to your clip’s depth (Default: 16).

Return type

VideoNode

Returns

Clip with pixel values added.

Raises
  • ValueError – Too many values are supplied.

  • ValueError – Any value in values are above 255.

lvsfunc.misc.source(path, ref=None, film_thr=99.0, force_lsmas=False, tail_lines=4, kernel=vskernels.Bicubic, **index_args)

Index and load video clips for use in VapourSynth automatically.

Note

For this function to work properly, you NEED to have DGIndex(NV) in your PATH!
DGIndexNV will be faster, but it only works with an NVidia GPU.

This function will try to index the given video file using DGIndex(NV). If it can’t, it will fall back on L-SMASH. L-SMASH can also be forced using force_lsmas. It also automatically determines if an image has been imported.

This function will automatically check whether your clip is mostly FILM. If FILM is above film_thr and the order is above 0, it will automatically set fieldop=1 and _FieldBased=0. This can be disabled by passing fieldop=0 to the function yourself.

You can pass a ref clip to further adjust the clip. This affects the dimensions, framerates, matrix/transfer/primaries, and in the case of an image, the length of the clip.

Alias for this function is lvsfunc.src.

Dependencies:

Thanks RivenSkaye!

Parameters
  • file – File to index and load in.

  • ref (vs.VideoNode | None) – Use another clip as reference for the clip’s format, resolution, framerate, and matrix/transfer/primaries (Default: None).

  • film_thr (float) – FILM percentage the dgi must exceed for fieldop=1 to be set automatically. If set above 100.0, it’s silently lowered to 100.0 (Default: 99.0).

  • force_lsmas (bool) – Force files to be imported with L-SMASH (Default: False).

  • kernel (Kernel | str) – py:class:vskernels.Kernel object used for converting the clip to match ref. This can also be the string name of the kernel (Default: py:class:vskernels.Bicubic(b=0, c=1/2)).

  • tail_lines (int) – Lines to check on the tail of the dgi file. Increase this value if FILM and ORDER do exist in your dgi file but it’s having trouble finding them. Set to 2 for a very minor speed-up, as that’s usually enough to find them (Default: 4).

  • kwargs – Optional arguments passed to the indexing filter.

Return type

vs.VideoNode

Returns

VapourSynth clip representing the input file.

Raises

ValueError – Something other than a path is passed to path.

lvsfunc.misc.unsharpen(clip, strength=1.0, sigma=1.5, prefilter=True, prefilter_sigma=0.75)

Diff’d unsharpening function.

Performs one-dimensional sharpening as such: “Original + (Original - blurred) * Strength” It then merges back noise and detail that was prefiltered away,

Negative values will blur instead. This can be useful for trying to undo sharpening.

This function is not recommended for normal use, but may be useful as prefiltering for detail- or edgemasks.

Parameters
  • clip (VideoNode) – Clip to process.

  • strength (float) – Amount to multiply blurred clip with original clip by. Negative values will blur the clip instead.

  • sigma (float) – Sigma for the gaussian blur.

  • prefilter (bool) – Pre-denoising to prevent the unsharpening from picking up random noise.

  • prefilter_sigma (float) – Strength for the pre-denoising.

  • show_mask – Show halo mask.

Return type

VideoNode

Returns

Unsharpened clip.

lvsfunc.misc.wipe_row(clip, ref=None, pos=(1, 1), size=None, show_mask=False)

Wipe a row or column with a blank clip.

You can also give it a different clip to replace a row with.

Parameters
  • clip (vs.VideoNode) – Clip to process.

  • secondary – Clip to replace wiped rows with (Default: None).

  • width – Width of row (Default: 1).

  • height – Height of row (Default: 1).

  • offset_x – X-offset of row (Default: 0).

  • offset_y – Y-offset of row (Default: 0).

Return type

vs.VideoNode

Returns

Clip with given rows or columns wiped.