Video editing with Python
fixed make_frame bug in ImageSequenceClip. Fixed end_padding in freeze.
Zulkod20a43636c04
diff --git a/moviepy/video/fx/freeze.py b/moviepy/video/fx/freeze.pyindex ffbf3a00..2a0dfea7 100644--- a/moviepy/video/fx/freeze.py+++ b/moviepy/video/fx/freeze.py@@ -7,7 +7,8 @@ def freeze(clip, t=0, freeze_duration=None, total_duration=None,padding_end=0):""" Momentarily freeze the clip at time t.- Set `t='end'` to freeze the clip at its end.+ Set `t='end'` to freeze the clip at the end (actually it will freeze on the+ frame at time clip.duration - padding_end seconds).With ``duration``you can specify the duration of the freeze.With ``total_duration`` you can specify the total duration ofthe clip and the freeze (i.e. the duration of the freeze is@@ -15,7 +16,7 @@ def freeze(clip, t=0, freeze_duration=None, total_duration=None,"""if t=='end':- t = clip.duration+ t = clip.duration - padding_endif freeze_duration is None:freeze_duration = total_duration - clip.durationdiff --git a/moviepy/video/io/ImageSequenceClip.py b/moviepy/video/io/ImageSequenceClip.pyindex 307af605..041fdefa 100644--- a/moviepy/video/io/ImageSequenceClip.py+++ b/moviepy/video/io/ImageSequenceClip.py@@ -91,7 +91,7 @@ class ImageSequenceClip(VideoClip):self.lastindex = Noneself.lastimage = None- def get_frame(t):+ def make_frame(t):index = find_image_index(t)@@ -101,11 +101,11 @@ class ImageSequenceClip(VideoClip):return self.lastimage- if with_mask and (get_frame(0).shape[2]==4):+ if with_mask and (make_frame(0).shape[2]==4):self.mask = VideoClip(ismask=True)- def mask_get_frame(t):+ def mask_make_frame(t):index = find_image_index(t)if index != self.lastindex:@@ -114,17 +114,17 @@ class ImageSequenceClip(VideoClip):return self.mask.lastimage- self.mask.get_frame = mask_get_frame- self.mask.size = mask_get_frame(0).shape[:2][::-1]+ self.mask.make_frame = mask_make_frame+ self.mask.size = mask_make_frame(0).shape[:2][::-1]else:- def get_frame(t):+ def make_frame(t):index = find_image_index(t)return self.sequence[index]- self.get_frame = get_frame- self.size = get_frame(0).shape[:2][::-1]+ self.make_frame = make_frame+ self.size = make_frame(0).shape[:2][::-1]diff --git a/moviepy/video/tools/cuts.py b/moviepy/video/tools/cuts.pyindex 3770609d..8f1b5822 100644--- a/moviepy/video/tools/cuts.py+++ b/moviepy/video/tools/cuts.py@@ -44,8 +44,18 @@ class FramesMatches(list):n = len(self)*percent/100return self[0] if n==1 else FramesMatches(self[:n])- def filter(self, fun):- return FramesMatches(filter(fun, self))+ def filter(self, cond):+ """+ Returns a FramesMatches object obtained by filtering out the FramesMatch+ which do not satistify the condition ``cond``. ``cond`` is a function+ (FrameMatch -> bool).++ Examples+ ---------+ >>> # Only keep the matches corresponding to (> 1 second) sequences.+ >>> new_matches = matches.filter( lambda match: match.time_span > 1)+ """+ return FramesMatches(filter(cond, self))def save(self, filename):np.savetxt(filename, np.array([np.array(list(e)) for e in self]),@@ -53,6 +63,9 @@ class FramesMatches(list):@staticmethoddef load(filename):+ """ Loads a FramesMatches object from a file.+ >>> matching_frames = FramesMatches.load("somefile")+ """arr = np.loadtxt(filename)mfs = [FramesMatch(*e) for e in arr]return FramesMatches(mfs)@@ -160,9 +173,19 @@ class FramesMatches(list):- def select_scenes(self, match_thr, time_span_thr, nomatch_thr=None):+ def select_scenes(self, match_thr, min_time_span, nomatch_thr=None):"""+ match_thr+ The smaller, the better-looping the gifs are.++ min_time_span+ Only GIFs with a duration longer than min_time_span (in seconds)+ will be extracted.++ nomatch_thr+ If None, then it is chosen equal to match_thr+"""if nomatch_thr is None:@@ -183,11 +206,11 @@ class FramesMatches(list):if dist<match_thr]great_long_matches = [end for end in great_matches- if (end-start)>time_span_thr]+ if (end-start)>min_time_span]if (great_long_matches == []):- continue+ continue # No GIF can be made starting at this timepoor_matches = set([end for (end,dist) in ends_distancesif dist>nomatch_thr])