Skip to content

clips

Classes:

Functions:

ProcessVariableClip

ProcessVariableClip(
    clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
)

Bases: DynamicClipsCache[T, VideoNodeT]

A helper class for processing variable format/resolution clip

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of items allowed in the cache. Defaults to 10

Methods:

  • eval_clip
  • from_clip

    Process a variable format/resolution clip.

  • from_func

    Process a variable format/resolution clip with a given function

  • get_clip
  • get_key

    Generate a unique key based on the node or frame

  • normalize

    Normalize the given node to the format/resolution specified by the unique key cast_to

  • process

    Process the given clip.

Attributes:

Source code
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self, clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> None:
    """
    :param clip:            Clip to process
    :param out_dim:         Ouput dimension.
    :param out_fmt:         Output format.
    :param cache_size:      The maximum number of items allowed in the cache. Defaults to 10
    """
    bk_args = KwargsT(length=clip.num_frames, keep=True, varformat=None)

    if out_dim is None:
        out_dim = (clip.width, clip.height)

    if out_fmt is None:
        out_fmt = clip.format or False

    if out_dim is not False and 0 in out_dim:
        out_dim = False

    if out_dim is False:
        bk_args.update(width=8, height=8, varsize=True)
    else:
        bk_args.update(width=out_dim[0], height=out_dim[1])

    if out_fmt is False:
        bk_args.update(format=vs.GRAY8, varformat=True)
    else:
        bk_args.update(format=out_fmt if isinstance(out_fmt, int) else out_fmt.id)

    super().__init__(cache_size)

    self.clip = clip
    self.out = vs.core.std.BlankClip(clip, **bk_args)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

out instance-attribute

out = BlankClip(clip, **bk_args)

eval_clip

eval_clip() -> VideoNodeT
Source code
315
316
317
318
319
320
321
322
def eval_clip(self) -> VideoNodeT:
    if self.out.format and (0 not in (self.out.width, self.out.height)):
        try:
            return self.get_clip(self.get_key(self.clip))
        except Exception:
            ...

    return vs.core.std.FrameEval(self.out, lambda n, f: self[self.get_key(f)], self.clip)

from_clip classmethod

from_clip(clip: VideoNodeT) -> VideoNodeT

Process a variable format/resolution clip.

Parameters:

Returns:

Source code
327
328
329
330
331
332
333
334
335
336
337
338
@classmethod
def from_clip(
    cls,
    clip: VideoNodeT
) -> VideoNodeT:
    """
    Process a variable format/resolution clip.

    :param clip:    Clip to process.
    :return:        Processed clip.
    """
    return cls(clip).eval_clip()

from_func classmethod

from_func(
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
) -> VideoNodeT

Process a variable format/resolution clip with a given function

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process.

  • func

    (Callable[[VideoNodeT], VideoNodeT]) –

    Function that takes and returns a single VideoNode.

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of VideoNode allowed in the cache. Defaults to 10

Returns:

Source code
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@classmethod
def from_func(
    cls,
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> VideoNodeT:
    """
    Process a variable format/resolution clip with a given function

    :param clip:        Clip to process.
    :param func:        Function that takes and returns a single VideoNode.
    :param out_dim:     Ouput dimension.
    :param out_fmt:     Output format.
    :param cache_size:  The maximum number of VideoNode allowed in the cache. Defaults to 10
    :return:            Processed variable clip.
    """
    setattr(cls, "process", lambda self, clip: func(clip))

    return cls(clip, out_dim, out_fmt, cache_size).eval_clip()

get_clip

get_clip(key: T) -> VideoNodeT
Source code
324
325
def get_clip(self, key: T) -> VideoNodeT:
    return self.process(self.normalize(self.clip, key))

get_key abstractmethod

get_key(frame: VideoNode | VideoFrame) -> T

Generate a unique key based on the node or frame This key will be used to temporarily assert a resolution and format for the clip to process.

Parameters:

  • frame

    (VideoNode | VideoFrame) –

    Node or frame from which the unique key is generated.

Returns:

  • T

    Unique identifier.

Source code
363
364
365
366
367
368
369
370
371
@abstractmethod
def get_key(self, frame: vs.VideoNode | vs.VideoFrame) -> T:
    """
    Generate a unique key based on the node or frame
    This key will be used to temporarily assert a resolution and format for the clip to process.

    :param frame:       Node or frame from which the unique key is generated.
    :return:            Unique identifier.
    """

normalize abstractmethod

normalize(clip: VideoNodeT, cast_to: T) -> VideoNodeT

Normalize the given node to the format/resolution specified by the unique key cast_to

Parameters:

  • clip

    (VideoNodeT) –

    Clip to normalize.

  • cast_to

    (T) –

    The target resolution or format to which the clip should be cast or normalized.

Returns:

Source code
373
374
375
376
377
378
379
380
381
@abstractmethod
def normalize(self, clip: VideoNodeT, cast_to: T) -> VideoNodeT:
    """
    Normalize the given node to the format/resolution specified by the unique key `cast_to`

    :param clip:        Clip to normalize.
    :param cast_to:     The target resolution or format to which the clip should be cast or normalized. 
    :return:            Normalized clip.
    """

process

process(clip: VideoNodeT) -> VideoNodeT

Process the given clip.

Parameters:

Returns:

Source code
383
384
385
386
387
388
389
390
def process(self, clip: VideoNodeT) -> VideoNodeT:
    """
    Process the given clip.

    :param clip:        Clip to process
    :return:            Processed clip
    """
    return clip

ProcessVariableFormatClip

ProcessVariableFormatClip(
    clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
)

Bases: ProcessVariableClip[VideoFormat, VideoNode]

A helper class for processing variable format clip

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of items allowed in the cache. Defaults to 10

Methods:

Attributes:

Source code
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self, clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> None:
    """
    :param clip:            Clip to process
    :param out_dim:         Ouput dimension.
    :param out_fmt:         Output format.
    :param cache_size:      The maximum number of items allowed in the cache. Defaults to 10
    """
    bk_args = KwargsT(length=clip.num_frames, keep=True, varformat=None)

    if out_dim is None:
        out_dim = (clip.width, clip.height)

    if out_fmt is None:
        out_fmt = clip.format or False

    if out_dim is not False and 0 in out_dim:
        out_dim = False

    if out_dim is False:
        bk_args.update(width=8, height=8, varsize=True)
    else:
        bk_args.update(width=out_dim[0], height=out_dim[1])

    if out_fmt is False:
        bk_args.update(format=vs.GRAY8, varformat=True)
    else:
        bk_args.update(format=out_fmt if isinstance(out_fmt, int) else out_fmt.id)

    super().__init__(cache_size)

    self.clip = clip
    self.out = vs.core.std.BlankClip(clip, **bk_args)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

out instance-attribute

out = BlankClip(clip, **bk_args)

eval_clip

eval_clip() -> VideoNodeT
Source code
315
316
317
318
319
320
321
322
def eval_clip(self) -> VideoNodeT:
    if self.out.format and (0 not in (self.out.width, self.out.height)):
        try:
            return self.get_clip(self.get_key(self.clip))
        except Exception:
            ...

    return vs.core.std.FrameEval(self.out, lambda n, f: self[self.get_key(f)], self.clip)

from_clip classmethod

from_clip(clip: VideoNodeT) -> VideoNodeT

Process a variable format/resolution clip.

Parameters:

Returns:

Source code
327
328
329
330
331
332
333
334
335
336
337
338
@classmethod
def from_clip(
    cls,
    clip: VideoNodeT
) -> VideoNodeT:
    """
    Process a variable format/resolution clip.

    :param clip:    Clip to process.
    :return:        Processed clip.
    """
    return cls(clip).eval_clip()

from_func classmethod

from_func(
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
) -> VideoNodeT

Process a variable format/resolution clip with a given function

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process.

  • func

    (Callable[[VideoNodeT], VideoNodeT]) –

    Function that takes and returns a single VideoNode.

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of VideoNode allowed in the cache. Defaults to 10

Returns:

Source code
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@classmethod
def from_func(
    cls,
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> VideoNodeT:
    """
    Process a variable format/resolution clip with a given function

    :param clip:        Clip to process.
    :param func:        Function that takes and returns a single VideoNode.
    :param out_dim:     Ouput dimension.
    :param out_fmt:     Output format.
    :param cache_size:  The maximum number of VideoNode allowed in the cache. Defaults to 10
    :return:            Processed variable clip.
    """
    setattr(cls, "process", lambda self, clip: func(clip))

    return cls(clip, out_dim, out_fmt, cache_size).eval_clip()

get_clip

get_clip(key: T) -> VideoNodeT
Source code
324
325
def get_clip(self, key: T) -> VideoNodeT:
    return self.process(self.normalize(self.clip, key))

get_key

get_key(frame: VideoNode | VideoFrame) -> VideoFormat
Source code
407
408
409
def get_key(self, frame: vs.VideoNode | vs.VideoFrame) -> vs.VideoFormat:
    assert frame.format
    return frame.format

normalize

normalize(clip: VideoNode, cast_to: VideoFormat) -> ConstantFormatVideoNode
Source code
411
412
413
def normalize(self, clip: vs.VideoNode, cast_to: vs.VideoFormat) -> ConstantFormatVideoNode:
    normalized = vs.core.resize.Point(vs.core.std.RemoveFrameProps(clip), format=cast_to.id)
    return vs.core.std.CopyFrameProps(normalized, clip)

process

process(clip: VideoNodeT) -> VideoNodeT

Process the given clip.

Parameters:

Returns:

Source code
383
384
385
386
387
388
389
390
def process(self, clip: VideoNodeT) -> VideoNodeT:
    """
    Process the given clip.

    :param clip:        Clip to process
    :return:            Processed clip
    """
    return clip

ProcessVariableResClip

ProcessVariableResClip(
    clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
)

Bases: ProcessVariableClip[tuple[int, int], VideoNodeT]

A helper class for processing variable resolution clip

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of items allowed in the cache. Defaults to 10

Methods:

Attributes:

Source code
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self, clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> None:
    """
    :param clip:            Clip to process
    :param out_dim:         Ouput dimension.
    :param out_fmt:         Output format.
    :param cache_size:      The maximum number of items allowed in the cache. Defaults to 10
    """
    bk_args = KwargsT(length=clip.num_frames, keep=True, varformat=None)

    if out_dim is None:
        out_dim = (clip.width, clip.height)

    if out_fmt is None:
        out_fmt = clip.format or False

    if out_dim is not False and 0 in out_dim:
        out_dim = False

    if out_dim is False:
        bk_args.update(width=8, height=8, varsize=True)
    else:
        bk_args.update(width=out_dim[0], height=out_dim[1])

    if out_fmt is False:
        bk_args.update(format=vs.GRAY8, varformat=True)
    else:
        bk_args.update(format=out_fmt if isinstance(out_fmt, int) else out_fmt.id)

    super().__init__(cache_size)

    self.clip = clip
    self.out = vs.core.std.BlankClip(clip, **bk_args)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

out instance-attribute

out = BlankClip(clip, **bk_args)

eval_clip

eval_clip() -> VideoNodeT
Source code
315
316
317
318
319
320
321
322
def eval_clip(self) -> VideoNodeT:
    if self.out.format and (0 not in (self.out.width, self.out.height)):
        try:
            return self.get_clip(self.get_key(self.clip))
        except Exception:
            ...

    return vs.core.std.FrameEval(self.out, lambda n, f: self[self.get_key(f)], self.clip)

from_clip classmethod

from_clip(clip: VideoNodeT) -> VideoNodeT

Process a variable format/resolution clip.

Parameters:

Returns:

Source code
327
328
329
330
331
332
333
334
335
336
337
338
@classmethod
def from_clip(
    cls,
    clip: VideoNodeT
) -> VideoNodeT:
    """
    Process a variable format/resolution clip.

    :param clip:    Clip to process.
    :return:        Processed clip.
    """
    return cls(clip).eval_clip()

from_func classmethod

from_func(
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
) -> VideoNodeT

Process a variable format/resolution clip with a given function

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process.

  • func

    (Callable[[VideoNodeT], VideoNodeT]) –

    Function that takes and returns a single VideoNode.

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of VideoNode allowed in the cache. Defaults to 10

Returns:

Source code
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@classmethod
def from_func(
    cls,
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> VideoNodeT:
    """
    Process a variable format/resolution clip with a given function

    :param clip:        Clip to process.
    :param func:        Function that takes and returns a single VideoNode.
    :param out_dim:     Ouput dimension.
    :param out_fmt:     Output format.
    :param cache_size:  The maximum number of VideoNode allowed in the cache. Defaults to 10
    :return:            Processed variable clip.
    """
    setattr(cls, "process", lambda self, clip: func(clip))

    return cls(clip, out_dim, out_fmt, cache_size).eval_clip()

get_clip

get_clip(key: T) -> VideoNodeT
Source code
324
325
def get_clip(self, key: T) -> VideoNodeT:
    return self.process(self.normalize(self.clip, key))

get_key

get_key(frame: VideoNode | VideoFrame) -> tuple[int, int]
Source code
396
397
def get_key(self, frame: vs.VideoNode | vs.VideoFrame) -> tuple[int, int]:
    return (frame.width, frame.height)

normalize

normalize(clip: VideoNodeT, cast_to: tuple[int, int]) -> VideoNodeT
Source code
399
400
401
def normalize(self, clip: VideoNodeT, cast_to: tuple[int, int]) -> VideoNodeT:
    normalized = vs.core.resize.Point(vs.core.std.RemoveFrameProps(clip), *cast_to)
    return vs.core.std.CopyFrameProps(normalized, clip)

process

process(clip: VideoNodeT) -> VideoNodeT

Process the given clip.

Parameters:

Returns:

Source code
383
384
385
386
387
388
389
390
def process(self, clip: VideoNodeT) -> VideoNodeT:
    """
    Process the given clip.

    :param clip:        Clip to process
    :return:            Processed clip
    """
    return clip

ProcessVariableResFormatClip

ProcessVariableResFormatClip(
    clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
)

Bases: ProcessVariableClip[tuple[int, int, VideoFormat], VideoNode]

A helper class for processing variable format and resolution clip

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of items allowed in the cache. Defaults to 10

Methods:

Attributes:

Source code
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self, clip: VideoNodeT,
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> None:
    """
    :param clip:            Clip to process
    :param out_dim:         Ouput dimension.
    :param out_fmt:         Output format.
    :param cache_size:      The maximum number of items allowed in the cache. Defaults to 10
    """
    bk_args = KwargsT(length=clip.num_frames, keep=True, varformat=None)

    if out_dim is None:
        out_dim = (clip.width, clip.height)

    if out_fmt is None:
        out_fmt = clip.format or False

    if out_dim is not False and 0 in out_dim:
        out_dim = False

    if out_dim is False:
        bk_args.update(width=8, height=8, varsize=True)
    else:
        bk_args.update(width=out_dim[0], height=out_dim[1])

    if out_fmt is False:
        bk_args.update(format=vs.GRAY8, varformat=True)
    else:
        bk_args.update(format=out_fmt if isinstance(out_fmt, int) else out_fmt.id)

    super().__init__(cache_size)

    self.clip = clip
    self.out = vs.core.std.BlankClip(clip, **bk_args)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

out instance-attribute

out = BlankClip(clip, **bk_args)

eval_clip

eval_clip() -> VideoNodeT
Source code
315
316
317
318
319
320
321
322
def eval_clip(self) -> VideoNodeT:
    if self.out.format and (0 not in (self.out.width, self.out.height)):
        try:
            return self.get_clip(self.get_key(self.clip))
        except Exception:
            ...

    return vs.core.std.FrameEval(self.out, lambda n, f: self[self.get_key(f)], self.clip)

from_clip classmethod

from_clip(clip: VideoNodeT) -> VideoNodeT

Process a variable format/resolution clip.

Parameters:

Returns:

Source code
327
328
329
330
331
332
333
334
335
336
337
338
@classmethod
def from_clip(
    cls,
    clip: VideoNodeT
) -> VideoNodeT:
    """
    Process a variable format/resolution clip.

    :param clip:    Clip to process.
    :return:        Processed clip.
    """
    return cls(clip).eval_clip()

from_func classmethod

from_func(
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | VideoFormat | Literal[False] | None = None,
    cache_size: int = 10,
) -> VideoNodeT

Process a variable format/resolution clip with a given function

Parameters:

  • clip

    (VideoNodeT) –

    Clip to process.

  • func

    (Callable[[VideoNodeT], VideoNodeT]) –

    Function that takes and returns a single VideoNode.

  • out_dim

    (tuple[int, int] | Literal[False] | None, default: None ) –

    Ouput dimension.

  • out_fmt

    (int | VideoFormat | Literal[False] | None, default: None ) –

    Output format.

  • cache_size

    (int, default: 10 ) –

    The maximum number of VideoNode allowed in the cache. Defaults to 10

Returns:

Source code
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
@classmethod
def from_func(
    cls,
    clip: VideoNodeT,
    func: Callable[[VideoNodeT], VideoNodeT],
    out_dim: tuple[int, int] | Literal[False] | None = None,
    out_fmt: int | vs.VideoFormat | Literal[False] | None = None,
    cache_size: int = 10
) -> VideoNodeT:
    """
    Process a variable format/resolution clip with a given function

    :param clip:        Clip to process.
    :param func:        Function that takes and returns a single VideoNode.
    :param out_dim:     Ouput dimension.
    :param out_fmt:     Output format.
    :param cache_size:  The maximum number of VideoNode allowed in the cache. Defaults to 10
    :return:            Processed variable clip.
    """
    setattr(cls, "process", lambda self, clip: func(clip))

    return cls(clip, out_dim, out_fmt, cache_size).eval_clip()

get_clip

get_clip(key: T) -> VideoNodeT
Source code
324
325
def get_clip(self, key: T) -> VideoNodeT:
    return self.process(self.normalize(self.clip, key))

get_key

get_key(frame: VideoNode | VideoFrame) -> tuple[int, int, VideoFormat]
Source code
419
420
421
def get_key(self, frame: vs.VideoNode | vs.VideoFrame) -> tuple[int, int, vs.VideoFormat]:
    assert frame.format
    return (frame.width, frame.height, frame.format)

normalize

normalize(clip: VideoNode, cast_to: tuple[int, int, VideoFormat]) -> VideoNode
Source code
423
424
425
426
427
428
def normalize(self, clip: vs.VideoNode, cast_to: tuple[int, int, vs.VideoFormat]) -> vs.VideoNode:
    w, h, fmt = cast_to

    normalized = vs.core.resize.Point(vs.core.std.RemoveFrameProps(clip), w, h, fmt.id)

    return vs.core.std.CopyFrameProps(normalized, clip)

process

process(clip: VideoNodeT) -> VideoNodeT

Process the given clip.

Parameters:

Returns:

Source code
383
384
385
386
387
388
389
390
def process(self, clip: VideoNodeT) -> VideoNodeT:
    """
    Process the given clip.

    :param clip:        Clip to process
    :return:            Processed clip
    """
    return clip

finalize_clip

finalize_clip(
    clip: VideoNode,
    bits: VideoFormatT | HoldsVideoFormatT | int | None = 10,
    clamp_tv_range: bool | None = None,
    dither_type: DitherType = AUTO,
    *,
    func: FuncExceptT | None = None
) -> ConstantFormatVideoNode

Finalize a clip for output to the encoder.

Parameters:

  • clip

    (VideoNode) –

    Clip to output.

  • bits

    (VideoFormatT | HoldsVideoFormatT | int | None, default: 10 ) –

    Bitdepth to output to.

  • clamp_tv_range

    (bool | None, default: None ) –

    Whether to clamp to tv range. If None, decide based on clip properties.

  • dither_type

    (DitherType, default: AUTO ) –

    Dithering used for the bitdepth conversion.

  • func

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling. This should only be set by VS package developers.

Returns:

  • ConstantFormatVideoNode

    Dithered down and optionally clamped clip.

Source code
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def finalize_clip(
    clip: vs.VideoNode,
    bits: VideoFormatT | HoldsVideoFormatT | int | None = 10,
    clamp_tv_range: bool | None = None,
    dither_type: DitherType = DitherType.AUTO,
    *, func: FuncExceptT | None = None
) -> ConstantFormatVideoNode:
    """
    Finalize a clip for output to the encoder.

    :param clip:            Clip to output.
    :param bits:            Bitdepth to output to.
    :param clamp_tv_range:  Whether to clamp to tv range. If None, decide based on clip properties.
    :param dither_type:     Dithering used for the bitdepth conversion.
    :param func:            Function returned for custom error handling.
                            This should only be set by VS package developers.

    :return:                Dithered down and optionally clamped clip.
    """
    from ..functions import limiter

    assert check_variable_format(clip, func or finalize_clip)

    if bits:
        clip = depth(clip, bits, dither_type=dither_type)

    if clamp_tv_range is None:
        try:
            clamp_tv_range = ColorRange.from_video(clip, strict=True).is_limited
        except Exception:
            clamp_tv_range = True

    if clamp_tv_range:
        clip = limiter(clip, tv_range=clamp_tv_range)

    return clip

finalize_output

finalize_output(
    function: Callable[P, VideoNode],
    /,
    *,
    bits: int | None = 10,
    clamp_tv_range: bool = True,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None,
) -> Callable[P, ConstantFormatVideoNode]
finalize_output(
    *,
    bits: int | None = 10,
    clamp_tv_range: bool = True,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None
) -> Callable[[Callable[P, VideoNode]], Callable[P, ConstantFormatVideoNode]]
finalize_output(
    function: Callable[P, VideoNode] | None = None,
    /,
    *,
    bits: int | None = 10,
    clamp_tv_range: bool = True,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None,
) -> Union[
    Callable[P, VideoNode],
    Callable[[Callable[P, VideoNode]], Callable[P, ConstantFormatVideoNode]],
]

Decorator implementation of finalize_clip.

Source code
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def finalize_output(
    function: Callable[P, vs.VideoNode] | None = None,
    /, *,
    bits: int | None = 10,
    clamp_tv_range: bool = True, dither_type: DitherType = DitherType.AUTO, func: FuncExceptT | None = None
) -> Union[
    Callable[P, vs.VideoNode],
    Callable[[Callable[P, vs.VideoNode]], Callable[P, ConstantFormatVideoNode]]
]:
    """Decorator implementation of finalize_clip."""

    if function is None:
        return partial(finalize_output, bits=bits, clamp_tv_range=clamp_tv_range, dither_type=dither_type, func=func)

    @wraps(function)
    def _wrapper(*args: P.args, **kwargs: P.kwargs) -> ConstantFormatVideoNode:
        return finalize_clip(function(*args, **kwargs), bits, clamp_tv_range, dither_type, func=func)

    return _wrapper

initialize_clip

initialize_clip(
    clip: VideoNode,
    bits: int | None = None,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    strict: bool = False,
    dither_type: DitherType = AUTO,
    *,
    func: FuncExceptT | None = None
) -> ConstantFormatVideoNode

Initialize a clip with default props.

It is HIGHLY recommended to always use this function at the beginning of your scripts!

Parameters:

  • clip

    (VideoNode) –

    Clip to initialize.

  • bits

    (int | None, default: None ) –

    Bits to dither to. - If 0, no dithering is applied. - If None, 16 if bit depth is lower than it, else leave untouched. - If positive integer, dither to that bitdepth.

  • matrix

    (MatrixT | None, default: None ) –

    Matrix property to set. If None, tries to get the Matrix from existing props. If no props are set or Matrix=2, guess from the video resolution.

  • transfer

    (TransferT | None, default: None ) –

    Transfer property to set. If None, tries to get the Transfer from existing props. If no props are set or Transfer=2, guess from the video resolution.

  • primaries

    (PrimariesT | None, default: None ) –

    Primaries property to set. If None, tries to get the Primaries from existing props. If no props are set or Primaries=2, guess from the video resolution.

  • chroma_location

    (ChromaLocationT | None, default: None ) –

    ChromaLocation prop to set. If None, tries to get the ChromaLocation from existing props. If no props are set, guess from the video resolution.

  • color_range

    (ColorRangeT | None, default: None ) –

    ColorRange prop to set. If None, tries to get the ColorRange from existing props. If no props are set, assume Limited Range.

  • field_based

    (FieldBasedT | None, default: None ) –

    FieldBased prop to set. If None, tries to get the FieldBased from existing props. If no props are set, assume PROGRESSIVE.

  • strict

    (bool, default: False ) –

    Whether to be strict about existing properties. If True, throws an exception if certain frame properties are not found.

  • dither_type

    (DitherType, default: AUTO ) –

    Dithering used for the bitdepth conversion.

  • func

    (FuncExceptT | None, default: None ) –

    Function returned for custom error handling. This should only be set by VS package developers.

Returns:

  • ConstantFormatVideoNode

    Clip with relevant frame properties set, and optionally dithered up to 16 bits by default.

Source code
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def initialize_clip(
    clip: vs.VideoNode, bits: int | None = None,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    strict: bool = False,
    dither_type: DitherType = DitherType.AUTO, *, func: FuncExceptT | None = None
) -> ConstantFormatVideoNode:
    """
    Initialize a clip with default props.

    It is HIGHLY recommended to always use this function at the beginning of your scripts!

    :param clip:            Clip to initialize.
    :param bits:            Bits to dither to.
                            - If 0, no dithering is applied.
                            - If None, 16 if bit depth is lower than it, else leave untouched.
                            - If positive integer, dither to that bitdepth.
    :param matrix:          Matrix property to set. If None, tries to get the Matrix from existing props.
                            If no props are set or Matrix=2, guess from the video resolution.
    :param transfer:        Transfer property to set. If None, tries to get the Transfer from existing props.
                            If no props are set or Transfer=2, guess from the video resolution.
    :param primaries:       Primaries property to set. If None, tries to get the Primaries from existing props.
                            If no props are set or Primaries=2, guess from the video resolution.
    :param chroma_location: ChromaLocation prop to set. If None, tries to get the ChromaLocation from existing props.
                            If no props are set, guess from the video resolution.
    :param color_range:     ColorRange prop to set. If None, tries to get the ColorRange from existing props.
                            If no props are set, assume Limited Range.
    :param field_based:     FieldBased prop to set. If None, tries to get the FieldBased from existing props.
                            If no props are set, assume PROGRESSIVE.
    :param strict:          Whether to be strict about existing properties.
                            If True, throws an exception if certain frame properties are not found.
    :param dither_type:     Dithering used for the bitdepth conversion.
    :param func:            Function returned for custom error handling.
                            This should only be set by VS package developers.

    :return:                Clip with relevant frame properties set, and optionally dithered up to 16 bits by default.
    """

    func = func or initialize_clip

    assert check_variable_format(clip, func)

    values: list[tuple[type[PropEnum], Any]] = [
        (Matrix, matrix),
        (Transfer, transfer),
        (Primaries, primaries),
        (ChromaLocation, chroma_location),
        (ColorRange, color_range),
        (FieldBased, field_based)
    ]

    clip = PropEnum.ensure_presences(clip, [
        (cls if strict else cls.from_video(clip, False, func)) if value is None else cls.from_param(value, func)
        for cls, value in values
    ], func)

    if bits is None:
        bits = max(get_depth(clip), 16)
    elif bits <= 0:
        return clip

    return depth(clip, bits, dither_type=dither_type)

initialize_input

initialize_input(
    function: Callable[P, VideoNodeT],
    /,
    *,
    bits: int | None = 16,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    strict: bool = False,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None,
) -> Callable[P, VideoNodeT]
initialize_input(
    *,
    bits: int | None = 16,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None
) -> Callable[[Callable[P, VideoNodeT]], Callable[P, VideoNodeT]]
initialize_input(
    function: Callable[P, VideoNode] | None = None,
    /,
    *,
    bits: int | None = 16,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    strict: bool = False,
    dither_type: DitherType = AUTO,
    func: FuncExceptT | None = None,
) -> Union[
    Callable[P, VideoNodeT],
    Callable[[Callable[P, VideoNodeT]], Callable[P, VideoNodeT]],
]

Decorator implementation of initialize_clip

Source code
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
def initialize_input(
    function: Callable[P, vs.VideoNode] | None = None,
    /, *,
    bits: int | None = 16,
    matrix: MatrixT | None = None,
    transfer: TransferT | None = None,
    primaries: PrimariesT | None = None,
    chroma_location: ChromaLocationT | None = None,
    color_range: ColorRangeT | None = None,
    field_based: FieldBasedT | None = None,
    strict: bool = False,
    dither_type: DitherType = DitherType.AUTO, func: FuncExceptT | None = None
) -> Union[
    Callable[P, VideoNodeT],
    Callable[[Callable[P, VideoNodeT]], Callable[P, VideoNodeT]]
]:
    """
    Decorator implementation of ``initialize_clip``
    """

    if function is None:
        return partial(
            initialize_input,
            bits=bits,
            matrix=matrix, transfer=transfer, primaries=primaries,
            chroma_location=chroma_location, color_range=color_range,
            field_based=field_based, strict=strict, dither_type=dither_type, func=func
        )

    init_args = dict[str, Any](
        bits=bits,
        matrix=matrix, transfer=transfer, primaries=primaries,
        chroma_location=chroma_location, color_range=color_range,
        field_based=field_based, strict=strict, dither_type=dither_type, func=func
    )

    @wraps(function)
    def _wrapper(*args: P.args, **kwargs: P.kwargs) -> VideoNodeT:
        args_l = list(args)

        for i, obj in enumerate(args_l):
            if isinstance(obj, vs.VideoNode):
                args_l[i] = initialize_clip(obj, **init_args)
                return function(*args_l, **kwargs)  # type: ignore

        kwargs2 = kwargs.copy()

        for name, obj in kwargs2.items():
            if isinstance(obj, vs.VideoNode):
                kwargs2[name] = initialize_clip(obj, **init_args)
                return function(*args, **kwargs2)  # type: ignore

        for name, param in inspect.signature(function).parameters.items():
            if param.default is not inspect.Parameter.empty and isinstance(param.default, vs.VideoNode):
                return function(*args, **kwargs2 | {name: initialize_clip(param.default, **init_args)})  # type: ignore

        raise CustomValueError(
            'No VideoNode found in positional, keyword, nor default arguments!', func or initialize_input
        )

    return _wrapper