Skip to content

Commit

Permalink
Add tests for 'slide_out' transition
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed May 25, 2021
1 parent 66a7584 commit 55c9153
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
26 changes: 15 additions & 11 deletions moviepy/video/compositing/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def slide_in(clip, duration, side):
side : str
Side of the screen where the clip comes from. One of
'top' | 'bottom' | 'left' | 'right'
'top', 'bottom', 'left' or 'right'.
Examples
--------
Expand Down Expand Up @@ -91,26 +91,30 @@ def slide_out(clip, duration, side):
Parameters
----------
clip
clip : moviepy.Clip.Clip
A video clip.
duration
duration : float
Time taken for the clip to fully disappear.
side
side : str
Side of the screen where the clip goes. One of
'top' | 'bottom' | 'left' | 'right'
'top', 'bottom', 'left' or 'right'.
Examples
--------
>>> from moviepy import *
>>> clips = [... make a list of clips]
>>> slided_clips = [CompositeVideoClip([
clip.fx(transfx.slide_out, duration=1, side='left')])
for clip in clips]
>>> final_clip = concatenate_videoclips( slided_clips, padding=-1)
>>> slided_clips = [
... CompositeVideoClip([clip.fx(transfx.slide_out, 1, "left")])
... for clip in clips
... ]
>>> final_clip = concatenate_videoclips(slided_clips, padding=-1)
>>>
>>> clip = ColorClip(
... color=(255, 0, 0), duration=1, size=(300, 300)
... ).with_fps(60)
>>> final_clip = CompositeVideoClip([transfx.slide_out(clip, 1, "right")])
"""
w, h = clip.size
ts = clip.duration - duration # start time of the effect.
Expand Down
54 changes: 53 additions & 1 deletion tests/test_compositing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip, clips_array
from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.video.compositing.transitions import slide_in
from moviepy.video.compositing.transitions import slide_in, slide_out
from moviepy.video.fx.resize import resize
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import BitmapClip, ColorClip
Expand Down Expand Up @@ -171,5 +171,57 @@ def test_slide_in():
assert n_reds == n_reds_expected


def test_slide_out():
duration = 0.1
size = (11, 1)
fps = 10
color = (255, 0, 0)

# left and right sides
clip = ColorClip(
color=color,
duration=duration,
size=size,
).with_fps(fps)

for side in ["left", "right"]:
new_clip = CompositeVideoClip([slide_out(clip, duration, side)])

for t in np.arange(0, duration, duration / fps):
n_reds, n_reds_expected = (0, round(11 - t * 100, 6))

if t:
assert n_reds_expected

for r, g, b in new_clip.get_frame(t)[0]:
if r == color[0] and g == color[1] and g == color[2]:
n_reds += 1

assert n_reds == n_reds_expected

# top and bottom sides
clip = ColorClip(
color=color,
duration=duration,
size=(size[1], size[0]),
).with_fps(fps)

for side in ["top", "bottom"]:
new_clip = CompositeVideoClip([slide_out(clip, duration, side)])
for t in np.arange(0, duration, duration / fps):
n_reds, n_reds_expected = (0, round(11 - t * 100, 6))

if t:
assert n_reds_expected

for row in new_clip.get_frame(t):
r, g, b = row[0]

if r == color[0] and g == color[1] and g == color[2]:
n_reds += 1

assert n_reds == n_reds_expected


if __name__ == "__main__":
pytest.main()

0 comments on commit 55c9153

Please sign in to comment.