lvsfunc.util

Helper functions for module functions and wrapper. Some of these may also be useful for regular scripting or other modules.

lvsfunc.util.colored_clips(amount[, ...])

Return a list of BlankClips with unique colors in sequential or random order.

lvsfunc.util.frames_since_bookmark(clip, ...)

Display frames since last bookmark to create easily reusable scenefiltering.

lvsfunc.util.load_bookmarks(bookmark_path)

Load VSEdit bookmarks.

lvsfunc.util.truncate_string(str_in, max_length)

Truncate a string if it surpasses a certain length.

lvsfunc.util.colored_clips(amount, max_hue=300, rand=True, seed=None, **kwargs)

Return a list of BlankClips with unique colors in sequential or random order.

The colors will be evenly spaced by hue in the HSL colorspace.

Useful maybe for comparison functions or just for getting multiple uniquely colored BlankClips for testing purposes.

Will always return a pure red clip in the list as this is the RGB equivalent of the lowest HSL hue possible (0).

Written by Dave.

Parameters
  • amount (int) – Number of VideoNodes to return.

  • max_hue (int) – Maximum hue (0 < hue <= 360) in degrees to generate colors from (uses the HSL color model). Setting this higher than 315 will result in the clip colors looping back towards red and is not recommended for visually distinct colors. If the amount of clips is higher than the max_hue expect there to be identical or visually similar colored clips returned (Default: 300)

  • rand (bool) – Randomizes order of the returned list (Default: True).

  • seed (Union[bytearray, bytes, float, str, None]) – Bytes-like object passed to random.seed which allows for consistent randomized order. of the resulting clips (Default: None)

  • kwargs (Any) – Arguments passed to vapoursynth.core.std.BlankClip() (Default: keep=1).

Return type

list[VideoNode]

Returns

List of uniquely colored clips in sequential or random order.

Raises
  • ValueErroramount is less than 2.

  • ValueErrormax_hue is not between 0–360.

lvsfunc.util.convert_rfs(rfs_string)

A utility function to convert ReplaceFramesSimple-styled ranges to replace_ranges-styled ranges.

This function accepts the RFS ranges as a string only. This is in line with how RFS handles them. The string will be validated before it’s passed on. As with all framerange-related functions, the more ranges you have, the slower the function will become.

This function works with both ‘[x y]’ and ‘x’ styles of frame numbering. If no frames could be found, it will simply return an empty list.

Parameters

rfs_string (str) – A string representing frame ranges, as you would for ReplaceFramesSimple.

Return type

FrameRangesN

Returns

A FrameRangesN list containing frame ranges as accepted by replace_ranges. If no frames are found, it will simply return an empty list.

Raises

ValueError – Invalid input string is passed.

lvsfunc.util.frames_since_bookmark(clip, bookmarks)

Display frames since last bookmark to create easily reusable scenefiltering.

Can be used in tandem with lvsfunc.misc.load_bookmarks() to import VSEdit bookmarks.

Parameters
  • clip (VideoNode) – Clip to process.

  • bookmarks (list[int]) – A list of bookmarks.

Return type

VideoNode

Returns

Clip with bookmarked frames.

lvsfunc.util.load_bookmarks(bookmark_path)

Load VSEdit bookmarks.

load_bookmarks(os.path.basename(__file__)+”.bookmarks”) will load the VSEdit bookmarks for the current Vapoursynth script.

Parameters

bookmark_path (str) – Path to bookmarks file.

Return type

list[int]

Returns

A list of bookmarked frames.

lvsfunc.util.match_clip(clip, ref, dimensions=True, vformat=True, matrices=True, length=False, kernel=vskernels.Catrom)

Try matching the given clip’s format with the reference clip’s.

Parameters
  • clip (VideoNode) – Clip to process.

  • ref (VideoNode) – Reference clip.

  • dimensions (bool) – Match video dimensions (Default: True).

  • vformat (bool) – Match video formats (Default: True).

  • matrices (bool) – Match matrix/transfer/primaries (Default: True).

  • length (bool) – Match clip length (Default: False).

  • kernel (KernelT) – py:class:vskernels.Kernel object used for the format conversion. This can also be the string name of the kernel (Default: py:class:vskernels.Catrom).

Return type

VideoNode

Returns

Clip that matches the ref clip in format.

lvsfunc.util.truncate_string(str_in, max_length, suffix='...')

Truncate a string if it surpasses a certain length.

Return type

str