Video editing with Python
Added transparency at import in VideoFileClip. Now clip.preview() accepts (h,m,s). Fixed mask-related bug in to_ImageClip Fixed mask-related bug in clip.resize(function(t)) Made clips_array available from moviepy.editor
Zulko6eedcffdd215
diff --git a/moviepy/editor.py b/moviepy/editor.pyindex eaec5715..b81bd929 100644--- a/moviepy/editor.py+++ b/moviepy/editor.py@@ -22,7 +22,7 @@ clip.preview().from .video.io.VideoFileClip import VideoFileClipfrom .video.io.ImageSequenceClip import ImageSequenceClipfrom .video.VideoClip import VideoClip, ImageClip, ColorClip, TextClip-from .video.compositing.CompositeVideoClip import CompositeVideoClip+from .video.compositing.CompositeVideoClip import CompositeVideoClip, clips_arrayfrom .video.compositing.concatenate import concatenatefrom .audio.AudioClip import AudioClip, CompositeAudioClipdiff --git a/moviepy/tools.py b/moviepy/tools.pyindex df100302..1002ec45 100644--- a/moviepy/tools.py+++ b/moviepy/tools.py@@ -5,6 +5,7 @@ Misc. useful functions that can be used at many places in the program.import subprocess as spimport sys+def sys_write_flush(s):""" writes and flushes witout delay a text in the console """sys.stdout.write(s)diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 758da598..0eaa15b8 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -616,12 +616,16 @@ class VideoClip(Clip):colorclip = colorclip.set_duration(self.duration)result = CompositeVideoClip([colorclip, self.set_pos(pos)],- transparent=(col_opacity != None))+ transparent=(col_opacity is not None))if isinstance(self, ImageClip):- result = result.to_ImageClip()+ new_result = result.to_ImageClip()+ if result.mask is not None:+ new_result.mask = result.mask.to_ImageClip()+ return new_result- return result+ else:+ return result@outplacediff --git a/moviepy/video/fx/freeze_at_end.py b/moviepy/video/fx/freeze_at_end.pyindex 4a0ed1db..89f9f8ac 100644--- a/moviepy/video/fx/freeze_at_end.py+++ b/moviepy/video/fx/freeze_at_end.py@@ -4,16 +4,19 @@ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip@requires_duration-def freeze_at_end(clip, freeze_duration=None, total_duration=None):+def freeze_at_end(clip, freeze_duration=None,+ total_duration=None, delta=0.05):"""Makes the clip freeze on its last frame. With ``duration`` you canspecify the duration of the freeze. With ``total_duration`` you canspecify the total duration of the clip and the freeze (i.e. theduration of the freeze is automatically calculated). If neitheris provided, the freeze will have an infinite length.++ The clip is frozen on the frame at time (clip.duration - delta)"""- freezed_clip = ImageClip(clip.get_frame(clip.end))+ freezed_clip = ImageClip(clip.get_frame(clip.end - delta))if total_duration:freeze_duration = total_duration - clip.durationif freeze_duration:diff --git a/moviepy/video/fx/resize.py b/moviepy/video/fx/resize.pyindex b96d9e28..b80167c5 100644--- a/moviepy/video/fx/resize.py+++ b/moviepy/video/fx/resize.py@@ -99,7 +99,7 @@ def resize(clip, newsize=None, height=None, width=None):fun = lambda gf,t: resizer(gf(t).astype('uint8'),newsize2(t))- return clip.fl(fun, keep_duration=True, apply_to='mask')+ return clip.fl(fun, keep_duration=True)else:diff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.pyindex a36f240c..abc188ce 100644--- a/moviepy/video/io/VideoFileClip.py+++ b/moviepy/video/io/VideoFileClip.py@@ -63,7 +63,18 @@ class VideoFileClip(VideoClip):self.fps = self.reader.fpsself.size = self.reader.size- self.get_frame = lambda t: self.reader.get_frame(t)++ 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)+ .set_duration(self.duration))+ self.mask.fps = self.fps++ else:++ self.get_frame = lambda t: self.reader.get_frame(t)# Make a reader for the audio, if any.if audio and self.reader.infos['audio_found']:diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.pyindex f35beae7..7c086c18 100644--- a/moviepy/video/io/ffmpeg_reader.py+++ b/moviepy/video/io/ffmpeg_reader.py@@ -111,7 +111,7 @@ class FFMPEG_VideoReader:ffmpeg can be painfully slow if some decoding has to be done.This function tries to avoid fectching arbitrary frameswhenever possible, by moving between adjacent frames.- """+ """# these definitely need to be rechecked sometime. Seems to work.#pos = min( self.nframes, int(np.round(self.fps*t))+1 )diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.pyindex cde44017..de8b875f 100644--- a/moviepy/video/io/preview.py+++ b/moviepy/video/io/preview.py@@ -1,9 +1,12 @@-from moviepy.decorators import requires_duration+import threadingimport timeimport pygame as pgimport numpy as np+from moviepy.decorators import requires_duration+from moviepy.tools import cvsecs+pg.init()pg.display.set_caption('MoviePy')@@ -33,6 +36,9 @@ def show(clip, t=0, with_mask=True):"""+ if isinstance(t, tuple):+ t = cvsecs(*t)+if clip.ismask:clip = clip.to_RGB()if with_mask and (clip.mask != None):