Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for 'slide_out' transition #1586

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()