Skip to content

cache

Classes:

Functions:

FrameT module-attribute

FrameT = TypeVar('FrameT', bound=RawFrame)

NodeT module-attribute

NodeT = TypeVar('NodeT', bound=RawNode)

ClipFramesCache

Bases: NodeFramesCache[VideoNode, VideoFrame]

ClipsCache

Bases: vs_object, dict[VideoNode, VideoNode]

DynamicClipsCache

DynamicClipsCache(cache_size: int = 2)

Bases: vs_object, dict[T, VideoNodeT]

Methods:

Attributes:

Source code
53
54
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) -> VideoNodeT
Source code
56
57
58
@abstractmethod
def get_clip(self, key: T) -> VideoNodeT:
    ...

FramesCache

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

Bases: vs_object, Generic[NodeT, FrameT], dict[int, FrameT]

Methods:

Attributes:

Source code
71
72
73
def __init__(self, clip: NodeT, cache_size: int = 10) -> None:
    self.clip = clip
    self.cache_size = cache_size

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

add_frame

add_frame(n: int, f: FrameT) -> FrameT
Source code
75
76
77
def add_frame(self, n: int, f: FrameT) -> FrameT:
    self[n] = f.copy()
    return self[n]

get_frame

get_frame(n: int, f: FrameT) -> FrameT
Source code
79
80
def get_frame(self, n: int, f: FrameT) -> FrameT:
    return self[n]

NodeFramesCache

NodesPropsCache

Bases: vs_object, dict[tuple[NodeT, int], MutableMapping[str, _VapourSynthMapValue]]

SceneBasedDynamicCache

SceneBasedDynamicCache(
    clip: VideoNode, keyframes: Keyframes | str, cache_size: int = 5
)

Bases: DynamicClipsCache[int, VideoNode]

Methods:

Attributes:

Source code
125
126
127
128
129
def __init__(self, clip: vs.VideoNode, keyframes: Keyframes | str, cache_size: int = 5) -> None:
    super().__init__(cache_size)

    self.clip = clip
    self.keyframes = Keyframes.from_param(clip, keyframes)

cache_size instance-attribute

cache_size = cache_size

clip instance-attribute

clip = clip

keyframes instance-attribute

keyframes = from_param(clip, keyframes)

from_clip classmethod

from_clip(
    clip: VideoNode, keyframes: Keyframes | str, *args: Any, **kwargs: Any
) -> VideoNode
Source code
138
139
140
@classmethod
def from_clip(cls, clip: vs.VideoNode, keyframes: Keyframes | str, *args: Any, **kwargs: Any) -> vs.VideoNode:
    return cls(clip, keyframes, *args, **kwargs).get_eval()

get_clip abstractmethod

get_clip(key: int) -> VideoNode
Source code
131
132
133
@abstractmethod
def get_clip(self, key: int) -> vs.VideoNode:
    ...

get_eval

get_eval() -> VideoNode
Source code
135
136
def get_eval(self) -> vs.VideoNode:
    return self.clip.std.FrameEval(lambda n: self[self.keyframes.scenes.indices[n]])

cache_clip

cache_clip(_clip: NodeT, cache_size: int = 10) -> NodeT
Source code
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def cache_clip(_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 cast(NodeT, vs.core.std.FrameEval(blank, lambda n: _from_cache_node if n in cache else _to_cache_node))

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

    return _clip