Skip to content

Video editing with Python

changed padding in concatenate. Added slide_in/out transitions (not tested)

Zulkoa467696f09d8
diff --git a/moviepy/conf.py b/moviepy/conf.py
index 13da1d47..76602c2f 100644
--- a/moviepy/conf.py
+++ b/moviepy/conf.py
@@ -26,7 +26,7 @@ IMAGEMAGICK_BINARY = 'convert'
# =====================================================================
-# CODE. Don't write anything below this line :O
+# CODE. Don't write anything below this line !
import subprocess as sp
diff --git a/moviepy/video/compositing/concatenate.py b/moviepy/video/compositing/concatenate.py
index 0c2956f6..e998c388 100644
--- a/moviepy/video/compositing/concatenate.py
+++ b/moviepy/video/compositing/concatenate.py
@@ -7,7 +7,8 @@ from moviepy.audio.AudioClip import CompositeAudioClip
from moviepy.video.compositing.on_color import on_color
def concatenate(clipslist, method = 'chain', transition=None,
- bg_color=(0, 0, 0), transparent=False, ismask=False, crossover = 0):
+ bg_color=(0, 0, 0), transparent=False, ismask=False,
+ padding = 0):
""" Concatenates several video clips
Returns a video clip made by clip by concatenating several video clips.
@@ -41,16 +42,24 @@ def concatenate(clipslist, method = 'chain', transition=None,
the masks of the clips in the list. If the clips do not have the
same resolution, the border around the smaller clips will be
transparent.
-
-
+
+ padding
+ Duration during two consecutive clips. If negative, a clip will
+ play at the same time as the clip it follows. A non-null padding
+ automatically sets the method to `compose`.
+
"""
+ if padding != 0:
+ method = 'compose'
+
if transition != None:
l = [[v, transition] for v in clipslist[:-1]]
clipslist = reduce(lambda x, y: x + y, l) + [clipslist[-1]]
transition = None
tt = np.cumsum([0] + [c.duration for c in clipslist])
+
sizes = [v.size for v in clipslist]
w = max([r[0] for r in sizes])
h = max([r[1] for r in sizes])
@@ -70,7 +79,8 @@ def concatenate(clipslist, method = 'chain', transition=None,
result = result.fx( on_color, (w,h), bg_color, 'center')
elif method == 'compose':
- tt = np.maximum(0, tt - crossover*np.arange(len(tt)))
+
+ tt = np.maximum(0, tt + padding*np.arange(len(tt)))
result = concatenate( [c.set_start(t).set_pos('center')
for (c, t) in zip(clipslist, tt)],
size = (w, h), bg_color=bg_color, ismask=ismask,
diff --git a/moviepy/video/compositing/transitions.py b/moviepy/video/compositing/transitions.py
index fd2dcd45..dc674bfe 100644
--- a/moviepy/video/compositing/transitions.py
+++ b/moviepy/video/compositing/transitions.py
@@ -11,8 +11,7 @@ from moviepy.video.fx.fadeout import fadeout
@add_mask_if_none
def crossfadein(clip, duration):
- """
- Makes the clip appear progressively, over ``duration`` seconds.
+ """ Makes the clip appear progressively, over ``duration`` seconds.
Only works when the clip is included in a CompositeVideoClip.
"""
newclip = clip.copy()
@@ -23,8 +22,7 @@ def crossfadein(clip, duration):
@requires_duration
@add_mask_if_none
def crossfadeout(clip, duration):
- """
- Makes the clip disappear progressively, over ``duration`` seconds.
+ """ Makes the clip disappear progressively, over ``duration`` seconds.
Only works when the clip is included in a CompositeVideoClip.
"""
newclip = clip.copy()
@@ -34,6 +32,90 @@ def crossfadeout(clip, duration):
+def slide_in(clip, duration, side):
+ """ Makes the clip arrive from one side of the screen.
+
+ Only works when the clip is included in a CompositeVideoClip,
+ and if the clip has the same size as the clip it follows / the
+ clip it is composed with.
+
+ Parameters
+ ===========
+
+ clip
+ A video clip.
+
+ duration
+ Time taken for the clip to be fully visible
+
+ side
+ Side of the screen where the clip comes from. One of
+ 'top' | 'bottom' | 'left' | 'right'
+
+ Examples
+ =========
+
+ >>> from moviepy.editor import *
+ >>> clips = [... make a list of clips]
+ >>> slided_clips = [clip.fx( transfx.slide_in, 1, 'left')
+ for clip in clips]
+ >>> final_clip = concatenate( slided_clips, padding=-1)
+
+ """
+ w,h = clip.size
+ pos_dict = {'left' : lambda t: (min(0,w*(t/duration-1)),'center'),
+ 'right' : lambda t: (max(0,w*(1-t/duration)),'center'),
+ 'top' : lambda t: ('center',min(0,h*(t/duration-1))),
+ 'bottom': lambda t: ('center',max(0,h*(1-t/duration)))}
+
+ return clip.set_pos( pos_dict[side] )
+
+
+
+@requires_duration
+def slide_out(clip, duration, side):
+ """ Makes the clip go away by one side of the screen.
+
+ Only works when the clip is included in a CompositeVideoClip,
+ and if the clip has the same size as the clip it follows / the
+ clip it is composed with.
+
+ Parameters
+ ===========
+
+ clip
+ A video clip.
+
+ duration
+ Time taken for the clip to fully disappear.
+
+ side
+ Side of the screen where the clip goes. One of
+ 'top' | 'bottom' | 'left' | 'right'
+
+ Examples
+ =========
+
+ >>> from moviepy.editor import *
+ >>> clips = [... make a list of clips]
+ >>> slided_clips = [clip.fx( transfx.slide_out, 1, 'bottom')
+ for clip in clips]
+ >>> final_clip = concatenate( slided_clips, padding=-1)
+
+ """
+
+ w,h = clip.size
+ t_s = clip.duration - duration # start time of the effect.
+ pos_dict = {'left' : lambda t: (min(0,w*(1-(t-ts)/duration)),'center'),
+ 'right' : lambda t: (max(0,w*((t-ts)/duration-1)),'center'),
+ 'top' : lambda t: ('center',min(0,h*(1-(t-ts)/duration))),
+ 'bottom': lambda t: ('center',max(0,h*((t-ts)/duration-1))) }
+
+ return clip.set_pos( pos_dict[side] )
+
+
+
+