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
33
34
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
36
37
@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
50
51
52
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
54
55
56
57
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
59
60
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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