Video editing with Python
Unify any modification method on clip to use the with_ prefix
osaajanic3fbfe03467f
diff --git a/moviepy/Clip.py b/moviepy/Clip.pyindex 5c2d88b2..c2907830 100644--- a/moviepy/Clip.py+++ b/moviepy/Clip.py@@ -144,8 +144,8 @@ class Clip:def time_transform(self, time_func, apply_to=None, keep_duration=False):"""Returns a Clip instance playing the content of the current clip- but with a modified timeline, time ``t`` being replaced by another- time `time_func(t)`.+ but with a modified timeline, time ``t`` being replaced by the return+ of `time_func(t)`.Parameters----------@@ -351,37 +351,10 @@ class Clip:"""self.memoize = memoize- @convert_parameter_to_seconds(["t"])- def is_playing(self, t):- """If ``t`` is a time, returns true if t is between the start and the end- of the clip. ``t`` can be expressed in seconds (15.35), in (min, sec), in- (hour, min, sec), or as a string: '01:03:05.35'. If ``t`` is a numpy- array, returns False if none of the ``t`` is in the clip, else returns a- vector [b_1, b_2, b_3...] where b_i is true if tti is in the clip.- """- if isinstance(t, np.ndarray):- # is the whole list of t outside the clip ?- tmin, tmax = t.min(), t.max()-- if (self.end is not None) and (tmin >= self.end):- return False-- if tmax < self.start:- return False-- # If we arrive here, a part of t falls in the clip- result = 1 * (t >= self.start)- if self.end is not None:- result *= t <= self.end- return result-- else:- return (t >= self.start) and ((self.end is None) or (t < self.end))-@convert_parameter_to_seconds(["start_time", "end_time"])@apply_to_mask@apply_to_audio- def subclip(self, start_time=0, end_time=None):+ def with_subclip(self, start_time=0, end_time=None):"""Returns a clip playing the content of the current clip between times``start_time`` and ``end_time``, which can be expressed in seconds(15.35), in (min, sec), in (hour, min, sec), or as a string:@@ -407,7 +380,7 @@ class Clip:For instance:>>> # cut the last two seconds of the clip:- >>> new_clip = clip.subclip(0, -2)+ >>> new_clip = clip.with_subclip(0, -2)If ``end_time`` is provided or if the clip has a duration attribute,the duration of the returned clip is set automatically.@@ -449,7 +422,7 @@ class Clip:return new_clip@convert_parameter_to_seconds(["start_time", "end_time"])- def cutout(self, start_time, end_time):+ def with_cutout(self, start_time, end_time):"""Returns a clip playing the content of the current clip butskips the extract between ``start_time`` and ``end_time``, which can be@@ -538,6 +511,34 @@ class Clip:else:yield frame+ @convert_parameter_to_seconds(["t"])+ def is_playing(self, t):+ """If ``t`` is a time, returns true if t is between the start and the end+ of the clip. ``t`` can be expressed in seconds (15.35), in (min, sec), in+ (hour, min, sec), or as a string: '01:03:05.35'. If ``t`` is a numpy+ array, returns False if none of the ``t`` is in the clip, else returns a+ vector [b_1, b_2, b_3...] where b_i is true if tti is in the clip.+ """+ if isinstance(t, np.ndarray):+ # is the whole list of t outside the clip ?+ tmin, tmax = t.min(), t.max()++ if (self.end is not None) and (tmin >= self.end):+ return False++ if tmax < self.start:+ return False++ # If we arrive here, a part of t falls in the clip+ result = 1 * (t >= self.start)+ if self.end is not None:+ result *= t <= self.end+ return result++ else:+ return (t >= self.start) and ((self.end is None) or (t < self.end))++def close(self):"""Release any resources that are in use."""# Implementation note for subclasses:@@ -584,7 +585,7 @@ class Clip:Simple slicing is implemented via `subclip`.So, ``clip[t_start:t_end]`` is equivalent to- ``clip.subclip(t_start, t_end)``. If ``t_start`` is not+ ``clip.with_subclip(t_start, t_end)``. If ``t_start`` is notgiven, default to ``0``, if ``t_end`` is not given,default to ``self.duration``.@@ -609,7 +610,7 @@ class Clip:if isinstance(key, slice):# support for [start:end:speed] slicing. If speed is negative# a time mirror is applied.- clip = self.subclip(key.start or 0, key.stop or self.duration)+ clip = self.with_subclip(key.start or 0, key.stop or self.duration)if key.step:# change speed of the subclipdiff --git a/moviepy/version.py b/moviepy/version.pyindex 6e9bc966..8c0d5d5b 100644--- a/moviepy/version.py+++ b/moviepy/version.py@@ -1 +1 @@-__version__ = "2.0.0.dev2"+__version__ = "2.0.0"diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex bda75101..c45d2284 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -142,7 +142,7 @@ class VideoClip(Clip):This method is intensively used to produce new clips every timethere is an outplace transformation of the clip (clip.resize,- clip.subclip, etc.)+ clip.with_subclip, etc.)Acts like a deepcopy except for the fact that readers and otherpossible unpickleables objects are not copied.@@ -318,7 +318,7 @@ class VideoClip(Clip):-------->>> from moviepy import VideoFileClip- >>> clip = VideoFileClip("myvideo.mp4").subclip(100,120)+ >>> clip = VideoFileClip("myvideo.mp4").with_subclip(100,120)>>> clip.write_videofile("my_new_video.mp4")>>> clip.close()@@ -593,9 +593,9 @@ class VideoClip(Clip):>>> new_clip = clip.subapply(lambda c:c.multiply_speed(0.5) , 3,6)"""- left = None if (start_time == 0) else self.subclip(0, start_time)- center = self.subclip(start_time, end_time).fx(fx, **kwargs)- right = None if (end_time is None) else self.subclip(start_time=end_time)+ left = None if (start_time == 0) else self.with_subclip(0, start_time)+ center = self.with_subclip(start_time, end_time).fx(fx, **kwargs)+ right = None if (end_time is None) else self.with_subclip(start_time=end_time)clips = [clip for clip in [left, center, right] if clip is not None]@@ -701,7 +701,7 @@ class VideoClip(Clip):pos = map(int, pos)return blit(im_img, picture, pos, mask=im_mask)- def add_mask(self):+ def with_add_mask(self):"""Add a mask VideoClip to the VideoClip.Returns a copy of the clip with a completely opaque mask@@ -722,7 +722,7 @@ class VideoClip(Clip):mask = VideoClip(is_mask=True, make_frame=make_frame)return self.with_mask(mask.with_duration(self.duration))- def on_color(self, size=None, color=(0, 0, 0), pos=None, col_opacity=None):+ def with_on_color(self, size=None, color=(0, 0, 0), pos=None, col_opacity=None):"""Place the clip on a colored background.Returns a clip made of the current clip overlaid on a colordiff --git a/moviepy/video/fx/make_loopable.py b/moviepy/video/fx/make_loopable.pyindex f06065e6..65aeee82 100644--- a/moviepy/video/fx/make_loopable.py+++ b/moviepy/video/fx/make_loopable.py@@ -17,4 +17,4 @@ def make_loopable(clip, overlap_duration):clip2 = clip.fx(transfx.crossfadein, overlap_duration).with_start(clip.duration - overlap_duration)- return CompositeVideoClip([clip, clip2]).subclip(overlap_duration, clip.duration)+ return CompositeVideoClip([clip, clip2]).with_subclip(overlap_duration, clip.duration)diff --git a/moviepy/video/tools/cuts.py b/moviepy/video/tools/cuts.pyindex 1bf4e6cc..3fb16350 100644--- a/moviepy/video/tools/cuts.py+++ b/moviepy/video/tools/cuts.py@@ -31,7 +31,7 @@ def find_video_period(clip, fps=None, start_time=0.3):>>> from moviepy.editor import *>>> from moviepy.video.tools.cuts import find_video_period>>>- >>> clip = VideoFileClip("media/chaplin.mp4").subclip(0, 1).loop(2)+ >>> clip = VideoFileClip("media/chaplin.mp4").with_subclip(0, 1).loop(2)>>> round(videotools.find_video_period(clip, fps=80), 6)1"""@@ -237,7 +237,7 @@ class FramesMatches(list):... clip, distance_threshold=10, max_duration=3, # will take time... )>>> best = matches.filter(lambda m: m.time_span > 1.5).best()- >>> clip.subclip(best.start_time, best.end_time).write_gif("foo.gif")+ >>> clip.with_subclip(best.start_time, best.end_time).write_gif("foo.gif")"""N_pixels = clip.w * clip.h * 3@@ -342,7 +342,7 @@ class FramesMatches(list):>>> from moviepy.editor import *>>> from moviepy.video.tools.cuts import FramesMatches>>>- >>> ch_clip = VideoFileClip("media/chaplin.mp4").subclip(1, 4)+ >>> ch_clip = VideoFileClip("media/chaplin.mp4").with_subclip(1, 4)>>> clip = concatenate_videoclips([ch_clip.time_mirror(), ch_clip])>>>>>> result = FramesMatches.from_clip(clip, 10, 3).select_scenes(@@ -429,7 +429,7 @@ class FramesMatches(list):>>> from moviepy.editor import *>>> from moviepy.video.tools.cuts import FramesMatches>>>- >>> ch_clip = VideoFileClip("media/chaplin.mp4").subclip(1, 4)+ >>> ch_clip = VideoFileClip("media/chaplin.mp4").with_subclip(1, 4)>>> clip = concatenate_videoclips([ch_clip.time_mirror(), ch_clip])>>>>>> result = FramesMatches.from_clip(clip, 10, 3).select_scenes(@@ -445,7 +445,7 @@ class FramesMatches(list):"""for start, end, _, _ in self:name = "%s/%08d_%08d.gif" % (gifs_dir, 100 * start, 100 * end)- clip.subclip(start, end).write_gif(name, **kwargs)+ clip.with_subclip(start, end).write_gif(name, **kwargs)@use_clip_fps_by_default