Skip to content

motion

Classes:

  • MotionVectors –

    Class for storing and managing motion vectors for a video clip.

MotionVectors

MotionVectors(
    *args: Mapping[int, VideoNode] | Iterable[tuple[int, VideoNode]],
    blksize: int | tuple[int, int] | None = None,
    overlap: int | tuple[int, int] | None = None,
    pad: int | tuple[int, int] | None = None,
    pel: int | None = None,
    prefix: str = "MVTools",
    **kwargs: VideoNode,
)

Bases: VSObject, dict[int, VideoNode]

Class for storing and managing motion vectors for a video clip.

Contains both backward and forward motion vectors.

Methods:

  • clear –

    Clear all stored motion vectors.

  • get_vectors –

    Get the backward and forward vectors.

Attributes:

Source code in vsdenoise/mvtools/motion.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def __init__(
    self,
    *args: Mapping[int, vs.VideoNode] | Iterable[tuple[int, vs.VideoNode]],
    blksize: int | tuple[int, int] | None = None,
    overlap: int | tuple[int, int] | None = None,
    pad: int | tuple[int, int] | None = None,
    pel: int | None = None,
    prefix: str = "MVTools",
    **kwargs: vs.VideoNode,
) -> None:
    super().__init__(*args, **kwargs)

    self.blksize = blksize
    self.overlap = overlap
    self.pad = pad
    self.pel = pel
    self.prefix = prefix

blksize property writable

blksize: tuple[int, int] | None

overlap property writable

overlap: tuple[int, int] | None

pad property writable

pad: tuple[int, int] | None

pel instance-attribute

pel = pel

prefix instance-attribute

prefix = prefix

clear

clear() -> None

Clear all stored motion vectors.

Source code in vsdenoise/mvtools/motion.py
63
64
65
66
67
68
69
70
71
72
73
def clear(self) -> None:
    """
    Clear all stored motion vectors.
    """

    super().clear()

    self.blksize = None
    self.overlap = None
    self.pad = None
    self.pel = None

get_vectors

get_vectors(
    tr: int | None = None, delta: int | Sequence[int] | None = None
) -> tuple[list[VideoNode], list[VideoNode]]

Get the backward and forward vectors.

Parameters:

  • tr

    (int | None, default: None ) –

    The number of frames to get the vectors for.

  • delta

    (int | Sequence[int] | None, default: None ) –

    Specific delta(s) of motion vectors to use.

Returns:

  • list[VideoNode] –

    A tuple containing two lists of motion vectors.

  • list[VideoNode] –

    The first list contains backward vectors and the second contains forward vectors.

Source code in vsdenoise/mvtools/motion.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def get_vectors(
    self, tr: int | None = None, delta: int | Sequence[int] | None = None
) -> tuple[list[vs.VideoNode], list[vs.VideoNode]]:
    """
    Get the backward and forward vectors.

    Args:
        tr: The number of frames to get the vectors for.
        delta: Specific delta(s) of motion vectors to use.

    Returns:
        A tuple containing two lists of motion vectors.
        The first list contains backward vectors and the second contains forward vectors.
    """

    if delta:
        delta = to_arr(delta)
    elif tr:
        delta = chain(range(1, tr + 1), range(-tr, 0))
    else:
        delta = self.keys()

    vectors_backward = list[vs.VideoNode]()
    vectors_forward = list[vs.VideoNode]()

    for d in sorted(delta, key=abs):
        if d > 0:
            vectors_backward.append(self[d])
        elif d < 0:
            vectors_forward.append(self[d])

    return (vectors_backward, vectors_forward)