Skip to content

vodesfunc.rescale_ext.scenes

apply_ranges

apply_ranges(targets: Sequence[RescaleTarget], filename: str | PathLike[str]) -> vs.VideoNode

Apply saved descale ranges to prepared targets in candidate order.

Generate the range file with get_descale_ranges and prepare each selected RescaleBuilder (for final()) or vsscale.Rescale target. The RB_Target frame prop is the 1-based target index, or 0 for unassigned source frames.

Example usage:

    targets = [
        RescaleBuilder(src).descale_raw(Bicubic(0, 1), 960, 540, src_width=960, src_left=-0.0625, src_top=-0.0625, src_height=540),
        RescaleBuilder(src).descale(Lanczos(3), 960, 540),
    ]
    targets = [t.double().linemask().errormask().downscale() for t in targets]

    get_descale_ranges(targets, avg_error_thr=0.04, ind_error_thr=0.06, filename="example.toml")
    clip = apply_ranges(targets, filename="example.toml")

Parameters:

Name Type Description Default
targets Sequence[RescaleTarget]

List of RescaleBuilder or vsscale.Rescale targets to be used and picked from.

required
filename str | PathLike[str]

TOML file containing the results of a previous get_descale_ranges run.

required

Returns:

Type Description
VideoNode

Final output of the picked target or the unfiltered input clip when none matched.

Source code in vodesfunc/rescale_ext/scenes.py
def apply_ranges(
    targets: Sequence[RescaleTarget],
    filename: str | PathLike[str],
) -> vs.VideoNode:
    """Apply saved descale ranges to prepared targets in candidate order.

    Generate the range file with `get_descale_ranges` and prepare each selected `RescaleBuilder` (for `final()`) or `vsscale.Rescale` target.
    The `RB_Target` frame prop is the 1-based target index, or 0 for unassigned source frames.

    Example usage:
    ```py
        targets = [
            RescaleBuilder(src).descale_raw(Bicubic(0, 1), 960, 540, src_width=960, src_left=-0.0625, src_top=-0.0625, src_height=540),
            RescaleBuilder(src).descale(Lanczos(3), 960, 540),
        ]
        targets = [t.double().linemask().errormask().downscale() for t in targets]

        get_descale_ranges(targets, avg_error_thr=0.04, ind_error_thr=0.06, filename="example.toml")
        clip = apply_ranges(targets, filename="example.toml")
    ```

    :param targets:     List of `RescaleBuilder` or `vsscale.Rescale` targets to be used and picked from.
    :param filename:    TOML file containing the results of a previous `get_descale_ranges` run.

    :return:            Final output of the picked target or the unfiltered input clip when none matched.
    """
    source = _get_source(targets[0])
    result = source.std.SetFrameProps(RB_Target=0)
    scene_ranges = _load_ranges(Path(filename), source, len(targets), apply_ranges)
    for index, (target, ranges) in enumerate(zip(targets, scene_ranges, strict=True), start=1):
        if ranges:
            clip = _get_final(target, source).std.SetFrameProps(RB_Target=index)
            result = replace_ranges(result, clip, ranges, exclusive=False)
    return result