Skip to content

clip

Functions:

  • shift_clip

    Shift a clip forwards or backwards by N frames.

  • shift_clip_multi

    Shift a clip forwards or backwards multiple times by a varying amount of frames.

shift_clip

shift_clip(clip: VideoNodeT, offset: int) -> VideoNodeT

Shift a clip forwards or backwards by N frames.

This is useful for cases where you must compare every frame of a clip with the frame that comes before or after the current frame, like for example when performing temporal operations.

Both positive and negative integers are allowed. Positive values will shift a clip forward, negative will shift a clip backward.

Parameters:

  • clip

    (VideoNodeT) –

    Input clip.

  • offset

    (int) –

    Number of frames to offset the clip with. Negative values are allowed. Positive values will shift a clip forward, negative will shift a clip backward.

Returns:

  • VideoNodeT

    Clip that has been shifted forwards or backwards by N frames.

Source code
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def shift_clip(clip: VideoNodeT, offset: int) -> VideoNodeT:
    """
    Shift a clip forwards or backwards by *N* frames.

    This is useful for cases where you must compare every frame of a clip
    with the frame that comes before or after the current frame,
    like for example when performing temporal operations.

    Both positive and negative integers are allowed.
    Positive values will shift a clip forward, negative will shift a clip backward.

    :param clip:            Input clip.
    :param offset:          Number of frames to offset the clip with. Negative values are allowed.
                            Positive values will shift a clip forward,
                            negative will shift a clip backward.

    :return:                Clip that has been shifted forwards or backwards by *N* frames.
    """

    if offset > clip.num_frames - 1:
        raise FramesLengthError(shift_clip, 'offset')

    if offset < 0:
        return clip[0] * abs(offset) + clip[:offset]

    if offset > 0:
        return clip[offset:] + clip[-1] * offset

    return clip

shift_clip_multi

shift_clip_multi(
    clip: VideoNodeT, offsets: FrameRange = (-1, 1)
) -> list[VideoNodeT]

Shift a clip forwards or backwards multiple times by a varying amount of frames.

This will return a clip for every shifting operation performed. This is a convenience function that makes handling multiple shifts easier.

Example:

.. code-block:: python

>>> shift_clip_multi(clip, (-3, 3))
    [VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode]
        -3         -2         -1          0         +1         +2         +3

Parameters:

  • clip

    (VideoNodeT) –

    Input clip.

  • offsets

    (FrameRange, default: (-1, 1) ) –

    List of frame ranges for offsetting. A clip will be returned for every offset. Default: (-1, 1).

Returns:

  • list[VideoNodeT]

    A list of clips, the amount determined by the amount of offsets.

Source code
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def shift_clip_multi(clip: VideoNodeT, offsets: FrameRange = (-1, 1)) -> list[VideoNodeT]:
    """
    Shift a clip forwards or backwards multiple times by a varying amount of frames.

    This will return a clip for every shifting operation performed.
    This is a convenience function that makes handling multiple shifts easier.

    Example:

    .. code-block:: python

        >>> shift_clip_multi(clip, (-3, 3))
            [VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode]
                -3         -2         -1          0         +1         +2         +3

    :param clip:            Input clip.
    :param offsets:         List of frame ranges for offsetting.
                            A clip will be returned for every offset.
                            Default: (-1, 1).

    :return:                A list of clips, the amount determined by the amount of offsets.
    """

    ranges = normalize_franges(offsets)

    return [shift_clip(clip, x) for x in ranges]