Video editing with Python
The surgery worked: get_frame now a class method. make_frame is the new get_frame.
Zulkoe31e778413ee
diff --git a/moviepy/Clip.py b/moviepy/Clip.pyindex ca8323fd..9ee99d41 100644--- a/moviepy/Clip.py+++ b/moviepy/Clip.py@@ -49,8 +49,7 @@ class Clip:self.start = 0self.end = Noneself.duration = None--+def copy(self):""" Shallow copy of the clip.@@ -70,7 +69,12 @@ class Clip:return newclip-+ def get_frame(self, t):+ """+ Gets a numpy array representing the RGB picture of the clip at time t.+ """+ # Coming soon: smart error handling for debugging at this point+ return self.make_frame(t)def fl(self, fun, apply_to=[] , keep_duration=True):""" General processing of a clip.@@ -110,8 +114,8 @@ class Clip:"""- gf = copy(self.get_frame)- newclip = self.set_get_frame(lambda t: fun(gf, t))+ #mf = copy(self.make_frame)+ newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))if not keep_duration:newclip.duration = None@@ -272,12 +276,12 @@ class Clip:@outplace- def set_get_frame(self, gf):+ def set_make_frame(self, gf):"""- Sets a ``get_frame`` attribute for the clip. Useful for setting+ Sets a ``make_frame`` attribute for the clip. Useful for settingarbitrary/complicated videoclips."""- self.get_frame = gf+ self.make_frame = gfdiff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.pyindex 8d9693bb..6c54724d 100644--- a/moviepy/audio/AudioClip.py+++ b/moviepy/audio/AudioClip.py@@ -13,7 +13,7 @@ class AudioClip(Clip):See ``SoundClip`` and ``CompositeSoundClip`` for usable classes.- An AudioClip is a Clip with a ``get_frame`` attribute of+ An AudioClip is a Clip with a ``make_frame`` attribute ofthe form `` t -> [ f_t ]`` for mono sound and``t-> [ f1_t, f2_t ]`` for stereo sound (the arrays are Numpy arrays).The `f_t` are floats between -1 and 1. These bounds can be@@ -23,7 +23,7 @@ class AudioClip(Clip):Parameters------------ get_frame+ make_frameA function `t-> frame at time t`. The frame does not mean muchfor a sound, it is just a float. What 'makes' the sound arethe variations of that float in the time.@@ -36,21 +36,24 @@ class AudioClip(Clip):>>> # Plays the note A (a sine wave of frequency 404HZ)>>> import numpy as np- >>> gf = lambda t : 2*[ np.sin(404 * 2 * np.pi * t) ]- >>> clip = AudioClip().set_get_frame(gf)- >>> clip.set_duration(5).preview()+ >>> make_frame = lambda t : 2*[ np.sin(404 * 2 * np.pi * t) ]+ >>> clip = AudioClip(make_frame, duration=5)+ >>> clip.preview()"""- def __init__(self, get_frame = None):+ def __init__(self, make_frame = None, duration=None):Clip.__init__(self)- if get_frame:- self.get_frame = get_frame+ if make_frame is not None:+ self.make_frame = make_frameframe0 = self.get_frame(0)if hasattr(frame0, '__iter__'):self.nchannels = len(list(frame0))else:self.nchannels = 1+ if duration is not None:+ self.duration = duration+ self.end = duration@requires_durationdef to_soundarray(self,tt=None,fps=None, nbytes=2):@@ -168,7 +171,7 @@ class AudioArrayClip(AudioClip):self.duration = 1.0 * len(array) / fps- def get_frame(t):+ def make_frame(t):""" complicated, but must be able to handle the case where tis a list of the form sin(t) """@@ -185,7 +188,7 @@ class AudioArrayClip(AudioClip):else:return self.array[i]- self.get_frame = get_frame+ self.make_frame = make_frameself.nchannels = len(list(self.get_frame(0)))@@ -216,7 +219,7 @@ class CompositeAudioClip(AudioClip):self.duration = max(ends)self.end = max(ends)- def get_frame(t):+ def make_frame(t):played_parts = [c.is_playing(t) for c in self.clips]@@ -232,7 +235,8 @@ class CompositeAudioClip(AudioClip):return zero + sum(sounds)- self.get_frame = get_frame+ self.make_frame = make_frame+def concatenate_audio(clips):durations = [c.duration for c in clips]diff --git a/moviepy/audio/io/AudioFileClip.py b/moviepy/audio/io/AudioFileClip.pyindex 4709d8b8..0518e78c 100644--- a/moviepy/audio/io/AudioFileClip.py+++ b/moviepy/audio/io/AudioFileClip.py@@ -66,7 +66,7 @@ class AudioFileClip(AudioClip):self.end = self.duration- self.get_frame = lambda t: self.reader.get_frame(t)+ self.make_frame = lambda t: self.reader.get_frame(t)self.nchannels = self.reader.nchannelsdiff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 27fc014e..f678d2b3 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -74,7 +74,7 @@ class VideoClip(Clip):ismaskBoolean set to `True` if the clip is a mask.- get_frame+ make_frameA function ``t-> frame at time t`` where ``frame`` is aw*h*3 RGB array.@@ -95,16 +95,19 @@ class VideoClip(Clip):"""- def __init__(self, ismask=False, get_frame=None):+ def __init__(self, make_frame=None, ismask=False, duration=None):Clip.__init__(self)self.mask = Noneself.audio = Noneself.pos = lambda t: (0, 0)self.relative_pos = False- if get_frame is not None:- self.get_frame = get_frame- self.size =get_frame(0).shape[:2][::-1]+ if make_frame is not None:+ self.make_frame = make_frame+ self.size =self.get_frame(0).shape[:2][::-1]self.ismask = ismask+ if duration is not None:+ self.duration = duration+ self.end = duration@propertydef w(self):@@ -743,8 +746,8 @@ class VideoClip(Clip):mask = ColorClip(self.size, 1.0, ismask=True)return self.set_mask( mask.set_duration(self.duration))else:- get_frame = lambda t: np.ones(self.get_frame(t).shape, dtype=float)- mask = VideoClip(ismask=True, get_frame = get_frame)+ make_frame = lambda t: np.ones(self.get_frame(t).shape, dtype=float)+ mask = VideoClip(ismask=True, make_frame = make_frame)return self.set_mask(mask.set_duration(self.duration))@@ -803,14 +806,14 @@ class VideoClip(Clip):@outplace- def set_get_frame(self, gf):+ def set_make_frame(self, mf):""" Change the clip's ``get_frame``.- Returns a copy of the VideoClip instance, with the get_frame- attribute set to `gf`.+ Returns a copy of the VideoClip instance, with the make_frame+ attribute set to `mf`."""- self.get_frame = gf- self.size = gf(0).shape[:2][::-1]+ self.make_frame = mf+ self.size = self.get_frame(0).shape[:2][::-1]@@ -1026,7 +1029,7 @@ class ImageClip(VideoClip):# if the image was just a 2D mask, it should arrive here# unchanged- self.get_frame = lambda t: img+ self.make_frame = lambda t: imgself.size = img.shape[:2][::-1]self.img = img@@ -1060,7 +1063,7 @@ class ImageClip(VideoClip):arr = image_func(self.get_frame(0))self.size = arr.shape[:2][::-1]- self.get_frame = lambda t: arr+ self.make_frame = lambda t: arrself.img = arrfor attr in apply_to:diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.pyindex 28ae6677..23d05ef7 100644--- a/moviepy/video/compositing/CompositeVideoClip.py+++ b/moviepy/video/compositing/CompositeVideoClip.py@@ -78,7 +78,7 @@ class CompositeVideoClip(VideoClip):self.mask = CompositeVideoClip(maskclips,self.size,transparent=False, ismask=True)- def gf(t):+ def make_frame(t):""" The clips playing at time `t` are blitted over oneanother. """@@ -87,7 +87,7 @@ class CompositeVideoClip(VideoClip):f = c.blit_on(f, t)return f- self.get_frame = gf+ self.make_frame = make_framedef playing_clips(self, t=0):""" Returns a list of the clips in the composite clips that arediff --git a/moviepy/video/compositing/concatenate.py b/moviepy/video/compositing/concatenate.pyindex 068c01f6..9f97d315 100644--- a/moviepy/video/compositing/concatenate.py+++ b/moviepy/video/compositing/concatenate.py@@ -75,11 +75,11 @@ def concatenate(clipslist, method="chain", transition=None, bg_color=(0, 0, 0),tt = np.maximum(0, tt + padding*np.arange(len(tt)))if method == "chain":- def gf(t):+ def make_frame(t):i = max([i for i, e in enumerate(tt) if e <= t])return clipslist[i].get_frame(t - tt[i])- result.get_frame = gf- result = VideoClip(ismask = ismask, get_frame = gf)++ result = VideoClip(ismask = ismask, make_frame = make_frame)if transparent:clips_w_masks = [(c.add_mask() if c.mask is None else c) for c in clips]masks = [c.mask for c in clips_w_masks]diff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.pyindex 66ce00f1..0cf2425e 100644--- a/moviepy/video/io/VideoFileClip.py+++ b/moviepy/video/io/VideoFileClip.py@@ -63,19 +63,19 @@ class VideoFileClip(VideoClip):if has_mask:- self.get_frame = lambda t: self.reader.get_frame(t)[:,:,:3]- mask_gf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0- self.mask = (VideoClip(ismask = True, get_frame = mask_gf)+ self.make_frame = lambda t: self.reader.get_frame(t)[:,:,:3]+ mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0+ self.mask = (VideoClip(ismask = True, make_frame = mask_mf).set_duration(self.duration))self.mask.fps = self.fpselse:- self.get_frame = lambda t: self.reader.get_frame(t)+ self.make_frame = lambda t: self.reader.get_frame(t)# Make a reader for the audio, if any.if audio and self.reader.infos['audio_found']:-+self.audio = AudioFileClip(filename,buffersize= audio_buffersize,fps = audio_fps,