Skip to content

effects

Modules:

Classes:

BaseEffect

BaseEffect(**kwargs: Any)

Bases: ABC

kwargs: Effect-specific keyword arguments

Methods:

Source code in src/movfx/effects/base.py
36
37
38
39
40
41
def __init__(self, **kwargs: Any) -> None:
    """
    title: Initialize the effect with optional keyword arguments
    parameters:
        kwargs: Effect-specific keyword arguments
    """

build_clip

build_clip(
    img_from: ndarray,
    img_to: ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip
Source code in src/movfx/effects/base.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def build_clip(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip:
    """
    title: Build a moviepy VideoClip from the effect
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        duration: Duration of the clip in seconds
        fps: Frames per second
    returns: A moviepy VideoClip with the transition
    """

    def make_frame(t: float) -> np.ndarray:
        progress = t / duration if duration > 0 else 1.0
        progress = max(0.0, min(1.0, progress))
        return self.render_frame(img_from, img_to, progress)

    clip = VideoClip(make_frame, duration=duration)
    clip = clip.with_fps(fps)
    return clip

render_frame abstractmethod

render_frame(
    img_from: ndarray, img_to: ndarray, progress: float
) -> ndarray
Source code in src/movfx/effects/base.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@abstractmethod
def render_frame(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    progress: float,
) -> np.ndarray:
    """
    title: Render a single transition frame
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        progress: >
            Transition progress from 0.0 (fully source)
            to 1.0 (fully destination)
    returns: Blended frame as a NumPy RGB uint8 array
    """

DissolveEffect

DissolveEffect(
    *, grain_strength: float = 0.3, **kwargs: Any
)

Bases: BaseEffect

grain_strength: >
    Strength of the grain noise (0.0 to 1.0).
    Default is 0.3.

Methods:

Source code in src/movfx/effects/dissolve.py
33
34
35
36
37
38
39
40
41
42
def __init__(self, *, grain_strength: float = 0.3, **kwargs: Any) -> None:
    """
    title: Initialize dissolve effect
    parameters:
        grain_strength: >
            Strength of the grain noise (0.0 to 1.0).
            Default is 0.3.
    """
    super().__init__(**kwargs)
    self.grain_strength = max(0.0, min(1.0, grain_strength))

build_clip

build_clip(
    img_from: ndarray,
    img_to: ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip
Source code in src/movfx/effects/base.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def build_clip(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip:
    """
    title: Build a moviepy VideoClip from the effect
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        duration: Duration of the clip in seconds
        fps: Frames per second
    returns: A moviepy VideoClip with the transition
    """

    def make_frame(t: float) -> np.ndarray:
        progress = t / duration if duration > 0 else 1.0
        progress = max(0.0, min(1.0, progress))
        return self.render_frame(img_from, img_to, progress)

    clip = VideoClip(make_frame, duration=duration)
    clip = clip.with_fps(fps)
    return clip

render_frame

render_frame(
    img_from: ndarray, img_to: ndarray, progress: float
) -> ndarray
Source code in src/movfx/effects/dissolve.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def render_frame(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    progress: float,
) -> np.ndarray:
    """
    title: Render a dissolve frame
    parameters:
        img_from: Source image array
        img_to: Destination image array
        progress: Blend factor from 0.0 to 1.0
    returns: Grainy blended frame as uint8 array
    """
    h, w = img_from.shape[:2]
    noise = np.random.default_rng().uniform(
        -self.grain_strength, self.grain_strength, (h, w, 1)
    )
    per_pixel_progress = np.clip(progress + noise, 0.0, 1.0)
    blended = (1.0 - per_pixel_progress) * img_from + (
        per_pixel_progress * img_to
    )
    return blended.astype(np.uint8)

FadeEffect

FadeEffect(**kwargs: Any)

Bases: BaseEffect

kwargs: Effect-specific keyword arguments

Methods:

Source code in src/movfx/effects/base.py
36
37
38
39
40
41
def __init__(self, **kwargs: Any) -> None:
    """
    title: Initialize the effect with optional keyword arguments
    parameters:
        kwargs: Effect-specific keyword arguments
    """

build_clip

build_clip(
    img_from: ndarray,
    img_to: ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip
Source code in src/movfx/effects/base.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def build_clip(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip:
    """
    title: Build a moviepy VideoClip from the effect
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        duration: Duration of the clip in seconds
        fps: Frames per second
    returns: A moviepy VideoClip with the transition
    """

    def make_frame(t: float) -> np.ndarray:
        progress = t / duration if duration > 0 else 1.0
        progress = max(0.0, min(1.0, progress))
        return self.render_frame(img_from, img_to, progress)

    clip = VideoClip(make_frame, duration=duration)
    clip = clip.with_fps(fps)
    return clip

render_frame

render_frame(
    img_from: ndarray, img_to: ndarray, progress: float
) -> ndarray
Source code in src/movfx/effects/fade.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def render_frame(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    progress: float,
) -> np.ndarray:
    """
    title: Render a fade frame
    parameters:
        img_from: Source image array
        img_to: Destination image array
        progress: Blend factor from 0.0 to 1.0
    returns: Blended frame as uint8 array
    """
    blended = (1.0 - progress) * img_from + progress * img_to
    return blended.astype(np.uint8)

PushEffect

PushEffect(
    *,
    direction: Literal[
        "left", "right", "up", "down"
    ] = "left",
    **kwargs: Any,
)

Bases: BaseEffect

direction: >
    Direction the old image is pushed towards.
    Default is ``left``.

Methods:

Source code in src/movfx/effects/push.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    *,
    direction: Literal["left", "right", "up", "down"] = "left",
    **kwargs: Any,
) -> None:
    """
    title: Initialize push effect
    parameters:
        direction: >
            Direction the old image is pushed towards.
            Default is ``left``.
    """
    super().__init__(**kwargs)
    self.direction = direction

build_clip

build_clip(
    img_from: ndarray,
    img_to: ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip
Source code in src/movfx/effects/base.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def build_clip(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip:
    """
    title: Build a moviepy VideoClip from the effect
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        duration: Duration of the clip in seconds
        fps: Frames per second
    returns: A moviepy VideoClip with the transition
    """

    def make_frame(t: float) -> np.ndarray:
        progress = t / duration if duration > 0 else 1.0
        progress = max(0.0, min(1.0, progress))
        return self.render_frame(img_from, img_to, progress)

    clip = VideoClip(make_frame, duration=duration)
    clip = clip.with_fps(fps)
    return clip

render_frame

render_frame(
    img_from: ndarray, img_to: ndarray, progress: float
) -> ndarray
Source code in src/movfx/effects/push.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
def render_frame(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    progress: float,
) -> np.ndarray:
    """
    title: Render a push frame
    parameters:
        img_from: Source image array
        img_to: Destination image array
        progress: Push progress from 0.0 to 1.0
    returns: Composited frame as uint8 array
    """
    h, w = img_from.shape[:2]
    frame = np.zeros_like(img_from)

    if self.direction == "left":
        offset = int(w * progress)
        # Old image slides left
        if w - offset > 0:
            frame[:, : w - offset] = img_from[:, offset:]
        # New image enters from the right
        if offset > 0:
            frame[:, w - offset :] = img_to[:, :offset]
    elif self.direction == "right":
        offset = int(w * progress)
        # Old image slides right
        if w - offset > 0:
            frame[:, offset:] = img_from[:, : w - offset]
        # New image enters from the left
        if offset > 0:
            frame[:, :offset] = img_to[:, w - offset :]
    elif self.direction == "up":
        offset = int(h * progress)
        # Old image slides up
        if h - offset > 0:
            frame[: h - offset, :] = img_from[offset:, :]
        # New image enters from the bottom
        if offset > 0:
            frame[h - offset :, :] = img_to[:offset, :]
    elif self.direction == "down":
        offset = int(h * progress)
        # Old image slides down
        if h - offset > 0:
            frame[offset:, :] = img_from[: h - offset, :]
        # New image enters from the top
        if offset > 0:
            frame[:offset, :] = img_to[h - offset :, :]

    return frame

WipeEffect

WipeEffect(
    *,
    direction: Literal[
        "left", "right", "up", "down"
    ] = "left",
    **kwargs: Any,
)

Bases: BaseEffect

direction: >
    Direction of the wipe sweep.
    Default is ``left`` (left-to-right reveal).

Methods:

Source code in src/movfx/effects/wipe.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    *,
    direction: Literal["left", "right", "up", "down"] = "left",
    **kwargs: Any,
) -> None:
    """
    title: Initialize wipe effect
    parameters:
        direction: >
            Direction of the wipe sweep.
            Default is ``left`` (left-to-right reveal).
    """
    super().__init__(**kwargs)
    self.direction = direction

build_clip

build_clip(
    img_from: ndarray,
    img_to: ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip
Source code in src/movfx/effects/base.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def build_clip(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    duration: float,
    fps: int = 30,
) -> VideoClip:
    """
    title: Build a moviepy VideoClip from the effect
    parameters:
        img_from: Source image as a NumPy RGB array
        img_to: Destination image as a NumPy RGB array
        duration: Duration of the clip in seconds
        fps: Frames per second
    returns: A moviepy VideoClip with the transition
    """

    def make_frame(t: float) -> np.ndarray:
        progress = t / duration if duration > 0 else 1.0
        progress = max(0.0, min(1.0, progress))
        return self.render_frame(img_from, img_to, progress)

    clip = VideoClip(make_frame, duration=duration)
    clip = clip.with_fps(fps)
    return clip

render_frame

render_frame(
    img_from: ndarray, img_to: ndarray, progress: float
) -> ndarray
Source code in src/movfx/effects/wipe.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def render_frame(
    self,
    img_from: np.ndarray,
    img_to: np.ndarray,
    progress: float,
) -> np.ndarray:
    """
    title: Render a wipe frame
    parameters:
        img_from: Source image array
        img_to: Destination image array
        progress: Wipe progress from 0.0 to 1.0
    returns: Composited frame as uint8 array
    """
    h, w = img_from.shape[:2]
    frame = img_from.copy()

    if self.direction == "left":
        boundary = int(w * progress)
        frame[:, :boundary] = img_to[:, :boundary]
    elif self.direction == "right":
        boundary = int(w * (1.0 - progress))
        frame[:, boundary:] = img_to[:, boundary:]
    elif self.direction == "up":
        boundary = int(h * progress)
        frame[:boundary, :] = img_to[:boundary, :]
    elif self.direction == "down":
        boundary = int(h * (1.0 - progress))
        frame[boundary:, :] = img_to[boundary:, :]

    return frame