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
46
47
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
49
50
@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
63
64
65
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
67
68
69
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
71
72
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
116
117
118
119
120
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
128
129
130
@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
122
123
@abstractmethod
def get_clip(self, key: int) -> vs.VideoNode: ...

get_eval

get_eval() -> VideoNode
Source code
125
126
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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