Utility Functions

rvsfunc.utils.batch_index

Index sources in batch, provide a list of files to index.

rvsfunc.utils.copy_credits

Copy credits from source to the nc using a mask.

rvsfunc.utils.frame_to_array

Simple wrapper to turn a video frame into an numpy array.

rvsfunc.utils.is_topleft

Simple function that checks if chroma is top-left aligned or not.

rvsfunc.utils.pad_to

Pad a clip with the specified color to the specified dimensions.

rvsfunc.utils.replace

A simple and probably underoptimized RFS implementation, because why not.

rvsfunc.utils.replace_ranges

Replace frames in bulk, mostly useful for scenefiltering.

Easy livin’ functions, utilities that don’t match a category.

The functions in this module are mostly things that don’t fit in with the other categories but aren’t really worth making a new module over. This module will end up mostly containing things like batch utilities and project setup stuff. This should spawn some ease of use functions that I think are missing from the well known collections like vsutil.

rvsfunc.utils.VS_API_BELOW_4: bool = False

A boolean constant that provides some info on the VapourSynth API version.

This is to be used for situations where compatibility with version 3 is desired and there could be different calls to be made. frame_to_array() makes for a good example of when to use this.

rvsfunc.utils.batch_index(paths, source_filter, show_list=False, **src_args)

Index sources in batch, provide a list of files to index.

Simple lazy function. Takes a path or a list of paths, indexes them and then frees the memory before returning on success. If you happen to get any errors or exceptions, this will just raise the same thing again.

Parameters:
  • paths (Union[List[str], str]) – A single path as a string or a List of paths.

  • source_filter (Callable[..., VideoNode]) – The source filter or indexer method to call. If it doesn’t write, make sure to get the list of indexes using show_list.

  • show_list (bool) – If this is set to True, this function returns the results of source_filter(path) for every path in paths. Might be useful for batches as well as it would just return every vs.VideoNode returned by the calls to source_filter.

  • src_args (Dict[str, Any]) – Any additional keyword args will be forwarded to to the source filter as provided.

Return type:

List[VideoNode]

rvsfunc.utils.copy_credits(source, nc, mask=None)

Copy credits from source to the nc using a mask.

This function internally calls masking.detail_mask() which is meant for descales. As such, it assumes the NC doesn’t have major differences with the source as they are provided. Assumes both inputs have the same length.

Parameters:
  • source (VideoNode) – The clip to take the credits from.

  • nc (VideoNode) – The NC to copy the credits into.

  • mask (Optional[VideoNode]) – Optional, an external mask to use.

Return type:

VideoNode

rvsfunc.utils.frame_to_array(f)

Simple wrapper to turn a video frame into an numpy array.

Return type:

ndarray

rvsfunc.utils.is_topleft(clip)

Simple function that checks if chroma is top-left aligned or not.

In any other case it’s fairly safe to assume the chroma is aligned to the center-left as was the default before 4K UHD BDs and Bt.2020 were a thing. This is basically a more complex check for BT.2020 material.

Return type:

bool

rvsfunc.utils.pad_to(clip, width=1920, height=1080, color=None, *, range_in=vsutil.Range.LIMITED, range_out=None, chroma=False)

Pad a clip with the specified color to the specified dimensions.

Parameters:
  • clip (VideoNode) – The clip to pad

  • width (int) – The width to pad to, defaults to 1920

  • height (int) – The height to pad to, defaults to 1080

  • color (Union[Sequence[int], int, None]) – A Sequence describing the color to use for padding, in 8-bit values (a triplet of 0-255 values) or a single int for single-plane formats. Defaults to YUV black

  • range_in (Range) – The range for the video, either limited or full, defined in vsutil.Range and defaults to Range.LIMITED for integer format clips.

  • range_out (Optional[Range]) – Optional output range, defaults to range_in if not given.

  • chroma (bool) – Only used with single plane clips, force processing as chroma to ensure values stay within the valid ranges.

Return type:

VideoNode

rvsfunc.utils.replace(clip_a, clip_b, range, mismatch=False)

A simple and probably underoptimized RFS implementation, because why not.

Parameters:
  • clip_a (VideoNode) – The clip to replace frames in.

  • clip_b (VideoNode) – The clip to replace frames from clip_a with.

  • range (Sequence[int]) – A sequence containing exactly 2 ints. Any more will be ignored without warning. User error is not my problem.

  • mismatch (bool) – A bool whether or not to allow splicing variable resolutions or formats together.

Return type:

VideoNode

rvsfunc.utils.replace_ranges(clip_a, clip_b, ranges, mismatch=False)

Replace frames in bulk, mostly useful for scenefiltering.

Parameters:
  • clip_a (VideoNode) – The clip to replace frames in.

  • clip_b (VideoNode) – The clip to replace frames from clip_a with.

  • ranges (Union[Sequence[Sequence[int]], Sequence[int]]) – Either a Sequence of int, or a Sequence of Sequence of int. Ranges to replace.

  • mismatch (bool) – Whether or not to allow mismatched formats and resolutions.

Return type:

VideoNode