Skip to content

cache

Classes:

Functions:

ClipFramesCache

Bases: NodeFramesCache[VideoNode, VideoFrame]

ClipsCache

Bases: VSObject, dict[VideoNode, VideoNode]

DynamicClipsCache

DynamicClipsCache(cache_size: int = 2)

Bases: VSObject, dict[T, VideoNode]

Methods:

Attributes:

Source code in vstools/utils/cache.py
32
33
def __init__(self, cache_size: int = 2) -> None:
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

get_clip abstractmethod

get_clip(key: T) -> VideoNode
Source code in vstools/utils/cache.py
35
36
@abstractmethod
def get_clip(self, key: T) -> vs.VideoNode: ...

FramesCache

FramesCache(clip: _NodeT, cache_size: int = 10)

Bases: VSObject, dict[int, _FrameT]

Methods:

Attributes:

Source code in vstools/utils/cache.py
49
50
51
def __init__(self, clip: _NodeT, cache_size: int = 10) -> None:
    self.clip: _NodeT = clip
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip: _NodeT = clip

add_frame

add_frame(n: int, f: _FrameT) -> _FrameT
Source code in vstools/utils/cache.py
53
54
55
56
def add_frame(self, n: int, f: _FrameT) -> _FrameT:
    f = f.copy()
    self[n] = f
    return f

get_frame

get_frame(n: int, f: _FrameT) -> _FrameT
Source code in vstools/utils/cache.py
58
59
def get_frame(self, n: int, f: _FrameT) -> _FrameT:
    return self[n]

NodeFramesCache

Bases: VSObject, dict[_NodeT, FramesCache[_NodeT, _FrameT]]

NodesPropsCache

Bases: VSObject, dict[tuple[_NodeT, int], MutableMapping[str, '_PropValue']]

cache_clip

cache_clip(_clip: _NodeT, cache_size: int = 10) -> _NodeT
Source code in vstools/utils/cache.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def cache_clip[_NodeT: vs.RawNode](_clip: _NodeT, cache_size: int = 10) -> _NodeT:
    if isinstance(_clip, vs.VideoNode):
        cache = FramesCache[vs.VideoNode, vs.VideoFrame](_clip, cache_size)

        blank = vs.core.std.BlankClip(_clip)

        _to_cache_node = vs.core.std.ModifyFrame(blank, _clip, cache.add_frame)
        _from_cache_node = vs.core.std.ModifyFrame(blank, blank, cache.get_frame)

        return vs.core.std.FrameEval(blank, lambda n: _from_cache_node if n in cache else _to_cache_node)  # type: ignore[return-value]

    # elif isinstance(_clip, vs.AudioNode):
    #     ...

    return _clip