Video editing with Python
Many fixes changes for faster tests - hopefully no regression
Valentin Zulkowerdbc9ab13c022
diff --git a/.gitignore b/.gitignoreindex 9f7132ca..afe46e52 100644--- a/.gitignore+++ b/.gitignore@@ -21,6 +21,7 @@ liblib64__pycache__.cache/+.vscode# Sublime.sublime-projectdiff --git a/docs/getting_started/compositing.rst b/docs/getting_started/compositing.rstindex f064527f..736cf8a2 100644--- a/docs/getting_started/compositing.rst+++ b/docs/getting_started/compositing.rst@@ -85,26 +85,26 @@ Positioning clipsIf ``clip2`` and ``clip3`` are smaller than ``clip1``, you can decide where they will appear in the composition by setting their position. Here we indicate the coordinates of the top-left pixel of the clips: ::video = CompositeVideoClip([clip1,- clip2.set_pos((45,150)),- clip3.set_pos((90,100))])+ clip2.set_position((45,150)),+ clip3.set_position((90,100))])There are many ways to specify the position: ::- clip2.set_pos((45,150)) # x=45, y=150 , in pixels+ clip2.set_position((45,150)) # x=45, y=150 , in pixels- clip2.set_pos("center") # automatically centered+ clip2.set_position("center") # automatically centered# clip2 is horizontally centered, and at the top of the picture- clip2.set_pos(("center","top"))+ clip2.set_position(("center","top"))# clip2 is vertically centered, at the left of the picture- clip2.set_pos(("left","center"))+ clip2.set_position(("left","center"))# clip2 is at 40% of the width, 70% of the height of the screen:- clip2.set_pos((0.4,0.7), relative=True)+ clip2.set_position((0.4,0.7), relative=True)# clip2's position is horizontally centered, and moving down !- clip2.set_pos(lambda t: ('center', 50+t) )+ clip2.set_position(lambda t: ('center', 50+t) )When indicating the position keep in mind that the ``y`` coordinate has its zero at the top of the picture:diff --git a/examples/logo.py b/examples/logo.pyindex 31ecf7a8..d76a0bf7 100644--- a/examples/logo.py+++ b/examples/logo.py@@ -18,7 +18,7 @@ logo = ImageClip("../../videos/logo_descr.png").\screen = logo.on_color(moviesize, color = (0,0,0), pos='center')-shade = ColorClip(moviesize,col=(0,0,0))+shade = ColorClip(moviesize,color=(0,0,0))mask_frame = lambda t : f(t,moviesize,duration)shade.mask = VideoClip(ismask=True, get_frame = mask_frame)diff --git a/moviepy/Clip.py b/moviepy/Clip.pyindex 9a1fc657..1b5a7c28 100644--- a/moviepy/Clip.py+++ b/moviepy/Clip.py@@ -494,10 +494,11 @@ class Clip:# Implementation note for subclasses:## * Memory-based resources can be left to the garbage-collector.- # * However, any open files should be closed, and subprocesses should be terminated.- # * Be wary that shallow copies are frequently used. Closing a Clip may affect its copies.+ # * However, any open files should be closed, and subprocesses+ # should be terminated.+ # * Be wary that shallow copies are frequently used.+ # Closing a Clip may affect its copies.# * Therefore, should NOT be called by __del__().-pass# Support the Context Manager protocol, to ensure that resources are cleaned up.diff --git a/moviepy/audio/fx/audio_normalize.py b/moviepy/audio/fx/audio_normalize.pyindex 127e9ea6..129daa6a 100644--- a/moviepy/audio/fx/audio_normalize.py+++ b/moviepy/audio/fx/audio_normalize.py@@ -1,4 +1,5 @@from moviepy.decorators import audio_video_fx+from .volumex import volumex@audio_video_fxdef audio_normalize(clip):@@ -6,4 +7,4 @@ def audio_normalize(clip):to 0db."""mv = clip.max_volume()- return clip.volumex(1 / mv)+ return volumex(clip, 1 / mv)diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.pyindex 853b4be1..9f28639e 100644--- a/moviepy/audio/io/readers.py+++ b/moviepy/audio/io/readers.py@@ -113,7 +113,10 @@ class FFMPEG_AudioReader:L = self.nchannels*chunksize*self.nbytess = self.proc.stdout.read(L)dt = {1: 'int8',2:'int16',4:'int32'}[self.nbytes]- result = np.fromstring(s, dtype=dt)+ if hasattr(np, 'frombuffer'):+ result = np.frombuffer(s, dtype='uint8')+ else:+ result = np.fromstring(s, dtype='uint8')result = (1.0*result / 2**(8*self.nbytes-1)).\reshape((int(len(result)/self.nchannels),self.nchannels))diff --git a/moviepy/utils.py b/moviepy/utils.pynew file mode 100644index 00000000..320ce270--- /dev/null+++ b/moviepy/utils.py@@ -0,0 +1,18 @@+from moviepy.video.io.VideoFileClip import VideoFileClip+from moviepy.audio.io.AudioFileClip import AudioFileClip+from moviepy.video.VideoClip import ImageClip++def close_all_clips(objects='globals', types=('audio', 'video', 'image')):+ if objects == 'globals':+ objects = globals()+ if hasattr(objects, 'values'):+ objects = objects.values()+ types_tuple = tuple([+ {'audio': AudioFileClip,+ 'video': VideoFileClip,+ 'image': ImageClip}[t]+ for t in types+ ])+ for obj in objects:+ if isinstance(obj, types_tuple):+ obj.close()diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 4e0c1176..3cdf5384 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -638,14 +638,14 @@ class VideoClip(Clip):size = self.sizeif pos is None:pos = 'center'- colorclip = ColorClip(size, color)+ colorclip = ColorClip(size, color=color)if col_opacity is not None:- colorclip = (ColorClip(size, color, duration=self.duration)+ colorclip = (ColorClip(size, color=color, duration=self.duration).set_opacity(col_opacity))- result = CompositeVideoClip([colorclip, self.set_pos(pos)])+ result = CompositeVideoClip([colorclip, self.set_position(pos)])else:- result = CompositeVideoClip([self.set_pos(pos)],+ result = CompositeVideoClip([self.set_position(pos)],size=size,bg_color=color)@@ -710,16 +710,16 @@ class VideoClip(Clip):Examples----------- >>> clip.set_pos((45,150)) # x=45, y=150+ >>> clip.set_position((45,150)) # x=45, y=150>>>>>> # clip horizontally centered, at the top of the picture- >>> clip.set_pos(("center","top"))+ >>> clip.set_position(("center","top"))>>>>>> # clip is at 40% of the width, 70% of the height:- >>> clip.set_pos((0.4,0.7), relative=True)+ >>> clip.set_position((0.4,0.7), relative=True)>>>>>> # clip's position is horizontally centered, and moving up !- >>> clip.set_pos(lambda t: ('center', 50+t) )+ >>> clip.set_position(lambda t: ('center', 50+t) )"""self.relative_pos = relativediff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.pyindex 50fe6921..65e1735f 100644--- a/moviepy/video/compositing/CompositeVideoClip.py+++ b/moviepy/video/compositing/CompositeVideoClip.py@@ -59,7 +59,12 @@ class CompositeVideoClip(VideoClip):if bg_color is None:bg_color = 0.0 if ismask else (0, 0, 0)- fpss = [c.fps for c in clips if hasattr(c, 'fps') and c.fps is not None]+ fpss = [+ c.fps+ for c in clips+ if hasattr(c, 'fps')+ and c.fps is not None+ ]if len(fpss) == 0:self.fps = Noneelse:@@ -78,7 +83,7 @@ class CompositeVideoClip(VideoClip):self.created_bg = Falseelse:self.clips = clips- self.bg = ColorClip(size, col=self.bg_color)+ self.bg = ColorClip(size, color=self.bg_color)self.created_bg = True@@ -97,7 +102,8 @@ class CompositeVideoClip(VideoClip):# compute mask if necessaryif transparent:maskclips = [(c.mask if (c.mask is not None) else- c.add_mask().mask).set_pos(c.pos).set_end(c.end).set_start(c.start, change_end=False)+ c.add_mask().mask).set_position(c.pos)+ .set_end(c.end).set_start(c.start, change_end=False)for c in self.clips]self.mask = CompositeVideoClip(maskclips,self.size, ismask=True,@@ -169,12 +175,12 @@ def clips_array(array, rows_widths=None, cols_widths=None,clip = array[i,j]w,h = clip.sizeif (w < cw) or (h < rw):- clip = (CompositeVideoClip([clip.set_pos('center')],+ clip = (CompositeVideoClip([clip.set_position('center')],size = (cw,rw),bg_color = bg_color).set_duration(clip.duration))- array[i,j] = clip.set_pos((x,y))+ array[i,j] = clip.set_position((x,y))return CompositeVideoClip(array.flatten(), size = (xx[-1],yy[-1]),bg_color = bg_color)diff --git a/moviepy/video/compositing/concatenate.py b/moviepy/video/compositing/concatenate.pyindex c482ea60..3097dcb4 100644--- a/moviepy/video/compositing/concatenate.py+++ b/moviepy/video/compositing/concatenate.py@@ -83,7 +83,7 @@ def concatenate_videoclips(clips, method="chain", transition=None,return clips[i].get_frame(t - tt[i])def get_mask(c):- mask = c.mask or ColorClip([1, 1], col=1, ismask=True)+ mask = c.mask or ColorClip([1, 1], color=1, ismask=True)if mask.duration is None:mask.duration = c.durationreturn mask@@ -91,10 +91,11 @@ def concatenate_videoclips(clips, method="chain", transition=None,result = VideoClip(ismask = ismask, make_frame = make_frame)if any([c.mask is not None for c in clips]):masks = [get_mask(c) for c in clips]- result.mask = concatenate_videoclips(masks, method="chain", ismask=True)+ result.mask = concatenate_videoclips(masks, method="chain",+ ismask=True)result.clips = clipselif method == "compose":- result = CompositeVideoClip( [c.set_start(t).set_pos('center')+ result = CompositeVideoClip( [c.set_start(t).set_position('center')for (c, t) in zip(clips, tt)],size = (w, h), bg_color=bg_color, ismask=ismask)else:@@ -120,4 +121,5 @@ def concatenate_videoclips(clips, method="chain", transition=None,return result-concatenate = deprecated_version_of(concatenate_videoclips, oldname="concatenate")+concatenate = deprecated_version_of(concatenate_videoclips,+ oldname="concatenate")diff --git a/moviepy/video/compositing/on_color.py b/moviepy/video/compositing/on_color.pyindex 0f635223..ed664535 100644--- a/moviepy/video/compositing/on_color.py+++ b/moviepy/video/compositing/on_color.py@@ -18,9 +18,9 @@ def on_color(clip, size=None, color=(0, 0, 0), pos=None, col_opacity=None):size = clip.sizeif pos is None:pos = 'center'- colorclip = ColorClip(size, color)+ colorclip = ColorClip(size, color=color)if col_opacity:colorclip = colorclip.with_mask().set_opacity(col_opacity)- return CompositeVideoClip([colorclip, clip.set_pos(pos)],+ return CompositeVideoClip([colorclip, clip.set_position(pos)],transparent=(col_opacity is not None))diff --git a/moviepy/video/compositing/transitions.py b/moviepy/video/compositing/transitions.pyindex 98c0155a..cf0a7ffa 100644--- a/moviepy/video/compositing/transitions.py+++ b/moviepy/video/compositing/transitions.py@@ -69,7 +69,7 @@ def slide_in(clip, duration, side):'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])+ return clip.set_position(pos_dict[side])@requires_duration@@ -110,7 +110,7 @@ def slide_out(clip, duration, side):'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])+ return clip.set_position(pos_dict[side])@requires_durationdiff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.pyindex 1086fe54..48c88464 100644--- a/moviepy/video/io/ffmpeg_reader.py+++ b/moviepy/video/io/ffmpeg_reader.py@@ -141,8 +141,10 @@ class FFMPEG_VideoReader:result = self.lastreadelse:-- result = np.fromstring(s, dtype='uint8')+ if hasattr(np, 'frombuffer'):+ result = np.frombuffer(s, dtype='uint8')+ else:+ result = np.fromstring(s, dtype='uint8')result.shape =(h, w, len(s)//(w*h)) # reshape((h, w, len(s)//(w*h)))self.lastread = resultdiff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.pyindex 7a3b14e5..eb433bba 100644--- a/moviepy/video/io/preview.py+++ b/moviepy/video/io/preview.py@@ -42,7 +42,7 @@ def show(clip, t=0, with_mask=True, interactive=False):if with_mask and (clip.mask is not None):import moviepy.video.compositing.CompositeVideoClip as cvc- clip = cvc.CompositeVideoClip([clip.set_pos((0, 0))])+ clip = cvc.CompositeVideoClip([clip.set_position((0, 0))])img = clip.get_frame(t)imdisplay(img)diff --git a/tests/conftest.py b/tests/conftest.pynew file mode 100644index 00000000..7ac5dece--- /dev/null+++ b/tests/conftest.py@@ -0,0 +1,7 @@+import pytest+from moviepy.utils import close_all_clips++# @pytest.fixture(autouse=True, scope='function')+# def clean_between_tests():+# yield+# close_all_clips(scope='global')\ No newline at end of filediff --git a/tests/test_AudioClips.py b/tests/test_AudioClips.pyindex 9f8376d8..2b50258d 100644--- a/tests/test_AudioClips.py+++ b/tests/test_AudioClips.py@@ -10,8 +10,8 @@ from moviepy.audio.io.AudioFileClip import AudioFileClipfrom moviepy.audio.AudioClip import AudioClip, concatenate_audioclips, CompositeAudioClipsys.path.append("tests")-import download_media-from test_helper import TMP_DIR+from . import download_media+from .test_helper import TMP_DIRdef test_download_media(capsys):diff --git a/tests/test_ImageSequenceClip.py b/tests/test_ImageSequenceClip.pyindex 37911be3..c2531a00 100644--- a/tests/test_ImageSequenceClip.py+++ b/tests/test_ImageSequenceClip.py@@ -7,8 +7,8 @@ import pytestfrom moviepy.video.io.ImageSequenceClip import ImageSequenceClipsys.path.append("tests")-import download_media-from test_helper import TMP_DIR+from . import download_media+from .test_helper import TMP_DIRdef test_download_media(capsys):with capsys.disabled():diff --git a/tests/test_PR.py b/tests/test_PR.pyindex 392c86d2..f86af3a8 100644--- a/tests/test_PR.py+++ b/tests/test_PR.py@@ -9,16 +9,17 @@ from moviepy.video.io.VideoFileClip import VideoFileClipfrom moviepy.video.tools.interpolators import Trajectoryfrom moviepy.video.VideoClip import ColorClip, ImageClip, TextClipfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip+from moviepy.utils import close_all_clipssys.path.append("tests")-from test_helper import TMP_DIR, FONT+from .test_helper import TMP_DIR, FONTdef test_download_media(capsys):"""Test downloading."""- import download_media+ from . import download_mediawith capsys.disabled():download_media.download()@@ -29,6 +30,7 @@ def test_PR_306():with pytest.raises(Exception, message="Expecting Exception"):TextClip.list('blah')+ close_all_clips(locals())def test_PR_339():# In caption mode.@@ -85,7 +87,7 @@ def test_PR_424():assert str(record[1].message) == message2def test_PR_458():- clip = ColorClip([1000, 600], color=(60, 60, 60), duration=10)+ clip = ColorClip([1000, 600], color=(60, 60, 60), duration=2)clip.write_videofile(os.path.join(TMP_DIR, "test.mp4"),progress_bar=False, fps=30)clip.close()@@ -101,7 +103,7 @@ def test_PR_515():def test_PR_528():with ImageClip("media/vacation_2017.jpg") as clip:new_clip = scroll(clip, w=1000, x_speed=50)- new_clip = new_clip.set_duration(20)+ new_clip = new_clip.set_duration(1)new_clip.fps = 24new_clip.write_videofile(os.path.join(TMP_DIR, "pano.mp4"))@@ -120,7 +122,6 @@ def test_PR_610():clip1.fps = 24clip2.fps = 25composite = CompositeVideoClip([clip1, clip2])-assert composite.fps == 25diff --git a/tests/test_TextClip.py b/tests/test_TextClip.pyindex cad9cd16..7cd30d56 100644--- a/tests/test_TextClip.py+++ b/tests/test_TextClip.py@@ -1,11 +1,12 @@import sysimport pytest+from moviepy.utils import close_all_clipsfrom moviepy.video.fx.blink import blinkfrom moviepy.video.VideoClip import TextClipsys.path.append("tests")-from test_helper import TMP_DIR+from .test_helper import TMP_DIRdef test_duration():@@ -17,7 +18,7 @@ def test_duration():clip2 = clip.fx(blink, d_on=1, d_off=1)clip2 = clip2.set_duration(5)assert clip2.duration == 5- clip2.close()+ close_all_clips(locals())# Moved from tests.py. Maybe we can remove these?def test_if_textclip_crashes_in_caption_mode():diff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.pyindex 1af36bba..35a22067 100644--- a/tests/test_VideoClip.py+++ b/tests/test_VideoClip.py@@ -9,10 +9,11 @@ from moviepy.video.io.VideoFileClip import VideoFileClipfrom moviepy.audio.AudioClip import AudioClipfrom moviepy.audio.io.AudioFileClip import AudioFileClipfrom moviepy.video.fx.speedx import speedx+from moviepy.utils import close_all_clipssys.path.append("tests")-import download_media-from test_helper import TMP_DIR+from . import download_media+from .test_helper import TMP_DIRdef test_download_media(capsys):@@ -28,6 +29,7 @@ def test_check_codec():except ValueError as e:assert "MoviePy couldn't find the codec associated with the filename." \" Provide the 'codec' parameter in write_videofile." in str(e)+ close_all_clips(locals())def test_save_frame():@@ -35,13 +37,16 @@ def test_save_frame():location = os.path.join(TMP_DIR, "save_frame.png")clip.save_frame(location, t=0.5)assert os.path.isfile(location)+ close_all_clips(locals())def test_write_image_sequence():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.3)- locations = clip.write_images_sequence(os.path.join(TMP_DIR, "frame%02d.png"))+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.5)+ locations = clip.write_images_sequence(+ os.path.join(TMP_DIR, "frame%02d.png"))for location in locations:assert os.path.isfile(location)+ close_all_clips(locals())def test_write_gif_imageio():@@ -49,26 +54,30 @@ def test_write_gif_imageio():location = os.path.join(TMP_DIR, "imageio_gif.gif")clip.write_gif(location, program="imageio")assert os.path.isfile(location)+ close_all_clips(locals())def test_write_gif_ffmpeg():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.4)location = os.path.join(TMP_DIR, "ffmpeg_gif.gif")clip.write_gif(location, program="ffmpeg")assert os.path.isfile(location)+ close_all_clips(locals())def test_write_gif_ffmpeg_tmpfiles():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.4)+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.5)location = os.path.join(TMP_DIR, "ffmpeg_tmpfiles_gif.gif")clip.write_gif(location, program="ffmpeg", tempfiles=True)assert os.path.isfile(location)+ close_all_clips(locals())def test_write_gif_ImageMagick():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.5)location = os.path.join(TMP_DIR, "imagemagick_gif.gif")clip.write_gif(location, program="ImageMagick")+ close_all_clips(locals())# Fails for some reason#assert os.path.isfile(location)@@ -78,44 +87,49 @@ def test_write_gif_ImageMagick_tmpfiles():location = os.path.join(TMP_DIR, "imagemagick_tmpfiles_gif.gif")clip.write_gif(location, program="ImageMagick", tempfiles=True)assert os.path.isfile(location)+ close_all_clips(locals())def test_subfx():- clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 5)+ clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 1)transform = lambda c: speedx(c, 0.5)- new_clip = clip.subfx(transform, 2, 4)+ new_clip = clip.subfx(transform, 0.5, 0.8)location = os.path.join(TMP_DIR, "subfx.mp4")new_clip.write_videofile(location)assert os.path.isfile(location)+ close_all_clips(locals())def test_oncolor():# It doesn't need to be a ColorClip- clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=4)+ clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=0.5)on_color_clip = clip.on_color(size=(200, 160), color=(0, 0, 255))location = os.path.join(TMP_DIR, "oncolor.mp4")on_color_clip.write_videofile(location, fps=24)assert os.path.isfile(location)+ close_all_clips(locals())def test_setaudio():- clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=2)+ clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=0.5)make_frame_440 = lambda t: [sin(440 * 2 * pi * t)]- audio = AudioClip(make_frame_440, duration=2)+ audio = AudioClip(make_frame_440, duration=0.5)audio.fps = 44100clip = clip.set_audio(audio)location = os.path.join(TMP_DIR, "setaudio.mp4")clip.write_videofile(location, fps=24)assert os.path.isfile(location)+ close_all_clips(locals())def test_setaudio_with_audiofile():- clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=2)- audio = AudioFileClip("media/crunching.mp3").subclip(0, 2)+ clip = ColorClip(size=(100, 60), color=(255, 0, 0), duration=0.5)+ audio = AudioFileClip("media/crunching.mp3").subclip(0, 0.5)clip = clip.set_audio(audio)location = os.path.join(TMP_DIR, "setaudiofile.mp4")clip.write_videofile(location, fps=24)assert os.path.isfile(location)+ close_all_clips(locals())def test_setopacity():@@ -125,20 +139,23 @@ def test_setopacity():location = os.path.join(TMP_DIR, "setopacity.mp4")clip.write_videofile(location)assert os.path.isfile(location)+ close_all_clips(locals())def test_toimageclip():clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.6)- clip = clip.to_ImageClip(t=0.1, duration=2)+ clip = clip.to_ImageClip(t=0.1, duration=0.4)location = os.path.join(TMP_DIR, "toimageclip.mp4")clip.write_videofile(location, fps=24)assert os.path.isfile(location)+ close_all_clips(locals())def test_withoutaudio():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0.2, 0.6)new_clip = clip.without_audio()assert new_clip.audio is None+ close_all_clips(locals())if __name__ == "__main__":diff --git a/tests/test_VideoFileClip.py b/tests/test_VideoFileClip.pyindex 584e5235..8a0f1f89 100644--- a/tests/test_VideoFileClip.py+++ b/tests/test_VideoFileClip.py@@ -7,55 +7,41 @@ import pytestfrom moviepy.video.compositing.CompositeVideoClip import clips_arrayfrom moviepy.video.VideoClip import ColorClipfrom moviepy.video.io.VideoFileClip import VideoFileClip+from moviepy.utils import close_all_clipssys.path.append("tests")-from test_helper import TMP_DIR+from .test_helper import TMP_DIRdef test_setup():"""Test VideoFileClip setup."""- red = ColorClip((1024,800), color=(255,0,0))- green = ColorClip((1024,800), color=(0,255,0))- blue = ColorClip((1024,800), color=(0,0,255))+ red = ColorClip((256,200), color=(255,0,0))+ green = ColorClip((256,200), color=(0,255,0))+ blue = ColorClip((256,200), color=(0,0,255))- red.fps = green.fps = blue.fps = 30+ red.fps = green.fps = blue.fps = 10with clips_array([[red, green, blue]]).set_duration(5) as video:video.write_videofile(os.path.join(TMP_DIR, "test.mp4"))assert os.path.exists(os.path.join(TMP_DIR, "test.mp4"))- with VideoFileClip(os.path.join(TMP_DIR, "test.mp4")) as clip:- assert clip.duration == 5- assert clip.fps == 30- assert clip.size == [1024*3, 800]-- red.close()- green.close()- blue.close()+ clip = VideoFileClip(os.path.join(TMP_DIR, "test.mp4"))+ assert clip.duration == 5+ assert clip.fps == 10+ assert clip.size == [256*3, 200]+ close_all_clips(locals())def test_ffmpeg_resizing():"""Test FFmpeg resizing, to include downscaling."""video_file = 'media/big_buck_bunny_432_433.webm'- target_resolution = (128, 128)- with VideoFileClip(video_file, target_resolution=target_resolution) as video:- frame = video.get_frame(0)- assert frame.shape[0:2] == target_resolution-- target_resolution = (128, None)- with VideoFileClip(video_file, target_resolution=target_resolution) as video:- frame = video.get_frame(0)- assert frame.shape[0] == target_resolution[0]-- target_resolution = (None, 128)- with VideoFileClip(video_file, target_resolution=target_resolution) as video:- frame = video.get_frame(0)- assert frame.shape[1] == target_resolution[1]-- # Test upscaling- target_resolution = (None, 2048)- with VideoFileClip(video_file, target_resolution=target_resolution) as video:+ target_resolutions = [(128, 128), (128, None),(None, 128), (None, 256)]+ for target_resolution in target_resolutions:+ video = VideoFileClip(video_file, target_resolution=target_resolution)frame = video.get_frame(0)- assert frame.shape[1] == target_resolution[1]+ for (target, observed) in zip(target_resolution, frame.shape):+ if target is not None:+ assert target == observed+ video.close()if __name__ == '__main__':- pytest.main()+ pytest.main()\ No newline at end of filediff --git a/tests/test_Videos.py b/tests/test_Videos.pyindex 7506c8ee..0a912db2 100644--- a/tests/test_Videos.py+++ b/tests/test_Videos.py@@ -8,25 +8,24 @@ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.fx.mask_color import mask_colorfrom moviepy.video.VideoClip import ColorClip, ImageClip-import download_media+from . import download_mediasys.path.append("tests")-from test_helper import TMP_DIR+from .test_helper import TMP_DIRdef test_download_media(capsys):with capsys.disabled():download_media.download()def test_afterimage():- with ImageClip("media/afterimage.png") as ai:- masked_clip = mask_color(ai, color=[0,255,1]) # for green-- with ColorClip((800,600), color=(255,255,255)) as some_background_clip:-- with CompositeVideoClip([some_background_clip, masked_clip],- use_bgclip=True) as final_clip:- final_clip.duration = 5- final_clip.write_videofile(os.path.join(TMP_DIR, "afterimage.mp4"), fps=30)+ ai = ImageClip("media/afterimage.png")+ masked_clip = mask_color(ai, color=[0,255,1]) # for green+ some_background_clip = ColorClip((800,600), color=(255,255,255))+ final_clip = CompositeVideoClip([some_background_clip, masked_clip],+ use_bgclip=True)+ final_clip.duration = 5+ final_clip.write_videofile(+ os.path.join(TMP_DIR, "afterimage.mp4"), fps=30)if __name__ == '__main__':- pytest.main()+ pytest.main()diff --git a/tests/test_compositing.py b/tests/test_compositing.pyindex fbb47970..bbe446e2 100644--- a/tests/test_compositing.py+++ b/tests/test_compositing.py@@ -4,42 +4,39 @@ from os.path import joinimport sysimport pytestfrom moviepy.editor import *+from moviepy.utils import close_all_clipssys.path.append("tests")-from test_helper import TMP_DIR+from .test_helper import TMP_DIR+def test_clips_array():- red = ColorClip((1024,800), color=(255,0,0))- green = ColorClip((1024,800), color=(0,255,0))- blue = ColorClip((1024,800), color=(0,0,255))+ red = ColorClip((1024, 800), color=(255, 0, 0))+ green = ColorClip((1024, 800), color=(0, 255, 0))+ blue = ColorClip((1024, 800), color=(0, 0, 255))video = clips_array([[red, green, blue]])with pytest.raises(ValueError,message="Expecting ValueError (duration not set)"):- video.resize(width=480).write_videofile(join(TMP_DIR, "test_clips_array.mp4"))- video.close()- red.close()- green.close()- blue.close()--def test_clips_array_duration():- for i in range(20):- red = ColorClip((1024,800), color=(255,0,0))- green = ColorClip((1024,800), color=(0,255,0))- blue = ColorClip((1024,800), color=(0,0,255))-- with clips_array([[red, green, blue]]).set_duration(5) as video:- with pytest.raises(AttributeError,- message="Expecting ValueError (fps not set)"):- video.write_videofile(join(TMP_DIR, "test_clips_array.mp4"))+ video.resize(width=480).write_videofile(+ join(TMP_DIR, "test_clips_array.mp4"))+ close_all_clips(locals())- #this one should work correctly- red.fps = green.fps = blue.fps = 30-- with clips_array([[red, green, blue]]).set_duration(5) as video:- video.write_videofile(join(TMP_DIR, "test_clips_array.mp4"))-- red.close()- green.close()- blue.close()+def test_clips_array_duration():+ # NOTE: anyone knows what behaviour this sets ? If yes please replace+ # this comment.+ red = ColorClip((256, 200), color=(255, 0, 0))+ green = ColorClip((256, 200), color=(0, 255, 0))+ blue = ColorClip((256, 200), color=(0, 0, 255))++ video = clips_array([[red, green, blue]]).set_duration(5)+ with pytest.raises(AttributeError,+ message="Expecting ValueError (fps not set)"):+ video.write_videofile(join(TMP_DIR, "test_clips_array.mp4"))++ # this one should work correctly+ red.fps = green.fps = blue.fps = 30+ video = clips_array([[red, green, blue]]).set_duration(5)+ video.write_videofile(join(TMP_DIR, "test_clips_array.mp4"))+ close_all_clips(locals())diff --git a/tests/test_examples.py b/tests/test_examples.pyindex cbafec1f..c0e74391 100644--- a/tests/test_examples.py+++ b/tests/test_examples.py@@ -9,8 +9,8 @@ TODO:## import pytest#-# import download_media-# from test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS+# from . import download_media+# from .test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS## sys.path.append("tests")#diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex a46fce96..d9471a11 100644--- a/tests/test_ffmpeg_reader.py+++ b/tests/test_ffmpeg_reader.py@@ -5,7 +5,7 @@ import sysimport pytestfrom moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos-import download_media+from . import download_mediasys.path.append("tests")diff --git a/tests/test_fx.py b/tests/test_fx.pyindex 41c1214c..3492b25d 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -2,6 +2,7 @@ import osimport sysimport pytest+from moviepy.utils import close_all_clipsfrom moviepy.video.fx.blackwhite import blackwhite# from moviepy.video.fx.blink import blinkfrom moviepy.video.fx.colorx import colorx@@ -26,19 +27,24 @@ from moviepy.video.io.VideoFileClip import VideoFileClipsys.path.append("tests")-import download_media-from test_helper import TMP_DIR-+from . import download_media+from .test_helper import TMP_DIRdef test_download_media(capsys):with capsys.disabled():- download_media.download()+ download_media.download()+++def get_test_video():+ return VideoFileClip("media/big_buck_bunny_432_433.webm").subclip(0, 1)+def test_blackwhite():- with VideoFileClip("media/big_buck_bunny_432_433.webm") as clip:- clip1 = blackwhite(clip)- clip1.write_videofile(os.path.join(TMP_DIR,"blackwhite1.webm"))+ clip = get_test_video()+ clip1 = blackwhite(clip)+ clip1.write_videofile(os.path.join(TMP_DIR, "blackwhite1.webm"))+ close_all_clips(locals())# This currently fails with a with_mask error!# def test_blink():@@ -46,186 +52,224 @@ def test_blackwhite():# clip1 = blink(clip, 1, 1)# clip1.write_videofile(os.path.join(TMP_DIR,"blink1.webm"))+def test_colorx():- with VideoFileClip("media/big_buck_bunny_432_433.webm") as clip:- clip1 = colorx(clip, 2)- clip1.write_videofile(os.path.join(TMP_DIR,"colorx1.webm"))+ clip = get_test_video()+ clip1 = colorx(clip, 2)+ clip1.write_videofile(os.path.join(TMP_DIR, "colorx1.webm"))+ close_all_clips(locals())def test_crop():- with VideoFileClip("media/big_buck_bunny_432_433.webm") as clip:+ clip = get_test_video()- clip1=crop(clip) #ie, no cropping (just tests all default values)- clip1.write_videofile(os.path.join(TMP_DIR, "crop1.webm"))+ clip1 = crop(clip) # ie, no cropping (just tests all default values)+ clip1.write_videofile(os.path.join(TMP_DIR, "crop1.webm"))- clip2=crop(clip, x1=50, y1=60, x2=460, y2=275)- clip2.write_videofile(os.path.join(TMP_DIR, "crop2.webm"))+ clip2 = crop(clip, x1=50, y1=60, x2=460, y2=275)+ clip2.write_videofile(os.path.join(TMP_DIR, "crop2.webm"))- clip3=crop(clip, y1=30) #remove part above y=30- clip3.write_videofile(os.path.join(TMP_DIR, "crop3.webm"))+ clip3 = crop(clip, y1=30) # remove part above y=30+ clip3.write_videofile(os.path.join(TMP_DIR, "crop3.webm"))- clip4=crop(clip, x1=10, width=200) # crop a rect that has width=200- clip4.write_videofile(os.path.join(TMP_DIR, "crop4.webm"))+ clip4 = crop(clip, x1=10, width=200) # crop a rect that has width=200+ clip4.write_videofile(os.path.join(TMP_DIR, "crop4.webm"))- clip5=crop(clip, x_center=300, y_center=400, width=50, height=150)- clip5.write_videofile(os.path.join(TMP_DIR, "crop5.webm"))+ clip5 = crop(clip, x_center=300, y_center=400, width=50, height=150)+ clip5.write_videofile(os.path.join(TMP_DIR, "crop5.webm"))- clip6=crop(clip, x_center=300, width=400, y1=100, y2=600)- clip6.write_videofile(os.path.join(TMP_DIR, "crop6.webm"))+ clip6 = crop(clip, x_center=300, width=400, y1=100, y2=600)+ clip6.write_videofile(os.path.join(TMP_DIR, "crop6.webm"))+ close_all_clips(locals())def test_fadein():- with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,5) as clip:- clip1 = fadein(clip, 1)- clip1.write_videofile(os.path.join(TMP_DIR,"fadein1.webm"))+ clip = get_test_video()+ clip1 = fadein(clip, 0.5)+ clip1.write_videofile(os.path.join(TMP_DIR, "fadein1.webm"))+ close_all_clips(locals())+def test_fadeout():- with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,5) as clip:- clip1 = fadeout(clip, 1)- clip1.write_videofile(os.path.join(TMP_DIR,"fadeout1.webm"))+ clip = get_test_video()+ clip1 = fadeout(clip, 0.5)+ clip1.write_videofile(os.path.join(TMP_DIR, "fadeout1.webm"))+ close_all_clips(locals())+def test_invert_colors():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()clip1 = invert_colors(clip)clip1.write_videofile(os.path.join(TMP_DIR, "invert_colors1.webm"))+ close_all_clips(locals())+def test_loop():- #these do not work.. what am I doing wrong??+ # these do not work.. what am I doing wrong??return- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")- clip1 = clip.loop() #infinite looping+ clip = get_test_video()+ clip1 = clip.loop() # infinite loopingclip1.write_videofile(os.path.join(TMP_DIR, "loop1.webm"))- clip2 = clip.loop(duration=10) #loop for 10 seconds+ clip2 = clip.loop(duration=10) # loop for 10 secondsclip2.write_videofile(os.path.join(TMP_DIR, "loop2.webm"))- clip3 = clip.loop(n=3) #loop 3 times+ clip3 = clip.loop(n=3) # loop 3 timesclip3.write_videofile(os.path.join(TMP_DIR, "loop3.webm"))+ close_all_clips(objects=locals())+def test_lum_contrast():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()clip1 = lum_contrast(clip)clip1.write_videofile(os.path.join(TMP_DIR, "lum_contrast1.webm"))+ close_all_clips(locals())++ # what are the correct value ranges for function arguments lum,+ # contrast and contrast_thr? Maybe we should check for these in+ # lum_contrast.- #what are the correct value ranges for function arguments lum,- #contrast and contrast_thr? Maybe we should check for these in- #lum_contrast.def test_make_loopable():- clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,10)- clip1 = make_loopable(clip, 1)+ clip = get_test_video()+ clip1 = make_loopable(clip, 0.4)clip1.write_videofile(os.path.join(TMP_DIR, "make_loopable1.webm"))+ close_all_clips(locals())+def test_margin():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")- clip1 = margin(clip) #does the default values change anything?+ clip = get_test_video()+ clip1 = margin(clip) # does the default values change anything?clip1.write_videofile(os.path.join(TMP_DIR, "margin1.webm"))- clip2 = margin(clip, mar=100) # all margins are 100px+ clip2 = margin(clip, mar=100) # all margins are 100pxclip2.write_videofile(os.path.join(TMP_DIR, "margin2.webm"))- clip3 = margin(clip, mar=100, color=(255,0,0)) #red margin+ clip3 = margin(clip, mar=100, color=(255, 0, 0)) # red marginclip3.write_videofile(os.path.join(TMP_DIR, "margin3.webm"))+ close_all_clips(locals())+def test_mask_and():pass+def test_mask_color():pass+def test_mask_or():pass+def test_mirror_x():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()clip1 = mirror_x(clip)clip1.write_videofile(os.path.join(TMP_DIR, "mirror_x1.webm"))+ close_all_clips(locals())+def test_mirror_y():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()clip1 = mirror_y(clip)clip1.write_videofile(os.path.join(TMP_DIR, "mirror_y1.webm"))+ close_all_clips(locals())+def test_painting():pass+def test_resize():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()- clip1=clip.resize( (460,720) ) # New resolution: (460,720)- assert clip1.size == (460,720)+ clip1 = resize(clip, (460, 720)) # New resolution: (460,720)+ assert clip1.size == (460, 720)clip1.write_videofile(os.path.join(TMP_DIR, "resize1.webm"))- clip2=clip.resize(0.6) # width and heigth multiplied by 0.6- assert clip2.size == (clip.size[0]*0.6, clip.size[1]*0.6)+ clip2 = resize(clip, 0.6) # width and heigth multiplied by 0.6+ assert clip2.size == (clip.size[0] * 0.6, clip.size[1] * 0.6)clip2.write_videofile(os.path.join(TMP_DIR, "resize2.webm"))- clip3=clip.resize(width=800) # height computed automatically.+ clip3 = resize(clip, width=800) # height computed automatically.assert clip3.w == 800- #assert clip3.h == ??+ # assert clip3.h == ??clip3.write_videofile(os.path.join(TMP_DIR, "resize3.webm"))+ close_all_clips(locals())- #I get a general stream error when playing this video.- #clip4=clip.resize(lambda t : 1+0.02*t) # slow swelling of the clip+ # I get a general stream error when playing this video.+ # clip4=clip.resize(lambda t : 1+0.02*t) # slow swelling of the clip#clip4.write_videofile(os.path.join(TMP_DIR, "resize4.webm"))+def test_rotate():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()- clip1=rotate(clip, 90) # rotate 90 degrees+ clip1 = rotate(clip, 90) # rotate 90 degreesassert clip1.size == (clip.size[1], clip.size[0])clip1.write_videofile(os.path.join(TMP_DIR, "rotate1.webm"))- clip2=rotate(clip, 180) # rotate 90 degrees+ clip2 = rotate(clip, 180) # rotate 90 degreesassert clip2.size == tuple(clip.size)clip2.write_videofile(os.path.join(TMP_DIR, "rotate2.webm"))- clip3=rotate(clip, 270) # rotate 90 degrees+ clip3 = rotate(clip, 270) # rotate 90 degreesassert clip3.size == (clip.size[1], clip.size[0])clip3.write_videofile(os.path.join(TMP_DIR, "rotate3.webm"))- clip4=rotate(clip, 360) # rotate 90 degrees+ clip4 = rotate(clip, 360) # rotate 90 degreesassert clip4.size == tuple(clip.size)clip4.write_videofile(os.path.join(TMP_DIR, "rotate4.webm"))+ close_all_clips(locals())+def test_scroll():pass+def test_speedx():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()- clip1=speedx(clip, factor=0.5) # 1/2 speed+ clip1 = speedx(clip, factor=0.5) # 1/2 speedassert clip1.duration == 2clip1.write_videofile(os.path.join(TMP_DIR, "speedx1.webm"))- clip2=speedx(clip, final_duration=2) # 1/2 speed+ clip2 = speedx(clip, final_duration=2) # 1/2 speedassert clip2.duration == 2clip2.write_videofile(os.path.join(TMP_DIR, "speedx2.webm"))- clip2=speedx(clip, final_duration=3) # 1/2 speed+ clip2 = speedx(clip, final_duration=3) # 1/2 speedassert clip2.duration == 3clip2.write_videofile(os.path.join(TMP_DIR, "speedx3.webm"))+ close_all_clips(locals())+def test_supersample():pass+def test_time_mirror():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()- clip1=time_mirror(clip)+ clip1 = time_mirror(clip)assert clip1.duration == clip.durationclip1.write_videofile(os.path.join(TMP_DIR, "time_mirror1.webm"))+ close_all_clips(locals())+def test_time_symmetrize():- clip = VideoFileClip("media/big_buck_bunny_432_433.webm")+ clip = get_test_video()- clip1=time_symmetrize(clip)+ clip1 = time_symmetrize(clip)clip1.write_videofile(os.path.join(TMP_DIR, "time_symmetrize1.webm"))+ close_all_clips(locals())+def test_normalize():clip = AudioFileClip('media/crunching.mp3')clip = audio_normalize(clip)assert clip.max_volume() == 1+ close_all_clips(locals())if __name__ == '__main__':- pytest.main()+ pytest.main()diff --git a/tests/test_issues.py b/tests/test_issues.pyindex ebfb91e0..677c2a96 100644--- a/tests/test_issues.py+++ b/tests/test_issues.py@@ -5,22 +5,26 @@ import sysimport pytestfrom moviepy.editor import *+from moviepy.utils import close_all_clipssys.path.append("tests")-import download_media-from test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS+from . import download_media+from .test_helper import PYTHON_VERSION, TMP_DIR, TRAVISfrom moviepy.video.fx.blink import blinkfrom moviepy.video.fx.resize import resize+def test_download_media(capsys):with capsys.disabled():- download_media.download()+ download_media.download()+def test_issue_145():- with ColorClip((800, 600), color=(255,0,0)).set_duration(5) as video:- with pytest.raises(Exception, message='Expecting Exception'):- concatenate_videoclips([video], method='composite')+ video = ColorClip((800, 600), color=(255, 0, 0)).set_duration(5)+ with pytest.raises(Exception, message='Expecting Exception'):+ concatenate_videoclips([video], method='composite')+def test_issue_190():#from PIL import Image@@ -33,18 +37,19 @@ def test_issue_190():#clip.write_videofile(os.path.join(TMP_DIR, "issue_190.mp4"))pass+def test_issue_285():clip_1, clip_2, clip_3 = ImageClip('media/python_logo.png', duration=10), \- ImageClip('media/python_logo.png', duration=10), \- ImageClip('media/python_logo.png', duration=10)+ ImageClip('media/python_logo.png', duration=10), \+ ImageClip('media/python_logo.png', duration=10)merged_clip = concatenate_videoclips([clip_1, clip_2, clip_3])assert merged_clip.duration == 30- clip_1.close()- clip_2.close()- clip_3.close()+ close_all_clips(locals())+def test_issue_334():+ # NOTE: this is horrible. Any simpler version ?last_move = Nonelast_move1 = None@@ -97,50 +102,54 @@ def test_issue_334():def posi(t):global last_moveif len(lis) == 0:- return (last_move[1], last_move[2])+ return (last_move[1], last_move[2])if t >= lis[0][0]:- last_move = item = lis.pop(0)- return (item[1], item[2])+ last_move = item = lis.pop(0)+ return (item[1], item[2])else:- if len(lis) > 0:- dura = lis[0][0] - last_move[0]- now = t - last_move[0]- w = (lis[0][1] - last_move[1]) * (now / dura)- h = (lis[0][2] - last_move[2]) * (now / dura)- # print t, last_move[1] + w, last_move[2] + h- return (last_move[1] + w, last_move[2] + h)- return (last_move[1], last_move[2])+ if len(lis) > 0:+ dura = lis[0][0] - last_move[0]+ now = t - last_move[0]+ w = (lis[0][1] - last_move[1]) * (now / dura)+ h = (lis[0][2] - last_move[2]) * (now / dura)+ # print t, last_move[1] + w, last_move[2] + h+ return (last_move[1] + w, last_move[2] + h)+ return (last_move[1], last_move[2])def size(t):global last_move1if len(lis1) == 0:- return (last_move1[3], last_move1[3] * 1.33)+ return (last_move1[3], last_move1[3] * 1.33)if t >= lis1[0][0]:- last_move1 = item = lis1.pop(0)- return (item[3], item[3] * 1.33)+ last_move1 = item = lis1.pop(0)+ return (item[3], item[3] * 1.33)else:- if len(lis) > 0:- dura = lis1[0][0] - last_move1[0]- now = t - last_move1[0]- s = (lis1[0][3] - last_move1[3]) * (now / dura)- nsw = last_move1[3] + s- nsh = nsw * 1.33- # print t, nsw, nsh- return (nsw, nsh)- return (last_move1[3], last_move1[3] * 1.33)-- with VideoFileClip("media/big_buck_bunny_432_433.webm", has_mask=True) as avatar:- avatar.audio=None- maskclip = ImageClip("media/afterimage.png", ismask=True, transparent=True)- avatar.set_mask(maskclip) #must set maskclip here..-- concatenated = concatenate_videoclips([avatar]*11)-- with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,11) as tt:- # TODO: Setting mask here does not work: .set_mask(maskclip).resize(size)])- final = CompositeVideoClip([tt, concatenated.set_position(posi).resize(size)])- final.duration = tt.duration- final.write_videofile(os.path.join(TMP_DIR, 'issue_334.mp4'), fps=24)+ if len(lis) > 0:+ dura = lis1[0][0] - last_move1[0]+ now = t - last_move1[0]+ s = (lis1[0][3] - last_move1[3]) * (now / dura)+ nsw = last_move1[3] + s+ nsh = nsw * 1.33+ # print t, nsw, nsh+ return (nsw, nsh)+ return (last_move1[3], last_move1[3] * 1.33)++ avatar = VideoFileClip("media/big_buck_bunny_432_433.webm", has_mask=True)+ avatar.audio = None+ maskclip = ImageClip("media/afterimage.png",+ ismask=True, transparent=True)+ avatar.set_mask(maskclip) # must set maskclip here..+ concatenated = concatenate_videoclips([avatar] * 3)++ tt = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 3)+ # TODO: Setting mask here does not work:+ # .set_mask(maskclip).resize(size)])+ final = CompositeVideoClip(+ [tt, concatenated.set_position(posi).resize(size)])+ final.duration = tt.duration+ final.write_videofile(+ os.path.join(TMP_DIR, 'issue_334.mp4'), fps=10)+def test_issue_354():with ImageClip("media/python_logo.png") as clip:@@ -159,9 +168,10 @@ def test_issue_354():fadecaption = clip.crossfadein(crosstime).crossfadeout(crosstime)CompositeVideoClip([clip, fadecaption]).close()+def test_issue_359():- with ColorClip((800, 600), color=(255,0,0)).set_duration(5) as video:- video.fps=30+ with ColorClip((800, 600), color=(255, 0, 0)).set_duration(5) as video:+ video.fps = 30video.write_gif(filename=os.path.join(TMP_DIR, "issue_359.gif"),tempfiles=True)@@ -203,8 +213,9 @@ def test_issue_359():# animation = VideoClip(make_frame, duration=2)# animation.write_gif(os.path.join(TMP_DIR, "svm.gif"), fps=20)+def test_issue_407():- red = ColorClip((800, 600), color=(255,0,0)).set_duration(5)+ red = ColorClip((800, 600), color=(255, 0, 0)).set_duration(5)red.fps = 30assert red.fps == 30@@ -213,28 +224,30 @@ def test_issue_407():assert red.size == (800, 600)# ColorClip has no fps attribute.- green = ColorClip((640, 480), color=(0,255,0)).set_duration(2)- blue = ColorClip((640, 480), color=(0,0,255)).set_duration(2)+ green = ColorClip((640, 480), color=(0, 255, 0)).set_duration(2)+ blue = ColorClip((640, 480), color=(0, 0, 255)).set_duration(2)assert green.w == blue.w == 640assert green.h == blue.h == 480assert green.size == blue.size == (640, 480)with pytest.raises(AttributeError, message="Expecting ValueError Exception"):- green.fps+ green.fpswith pytest.raises(AttributeError, message="Expecting ValueError Exception"):- blue.fps+ blue.fps- video=concatenate_videoclips([red, green, blue])+ video = concatenate_videoclips([red, green, blue])assert video.fps == red.fps+def test_issue_416():# ColorClip has no fps attribute.- green = ColorClip((640, 480), color=(0,255,0)).set_duration(2)+ green = ColorClip((640, 480), color=(0, 255, 0)).set_duration(2)video1 = concatenate_videoclips([green])assert video1.fps == None+def test_issue_417():# failed in python2cad = u'media/python_logo.png'@@ -242,13 +255,15 @@ def test_issue_417():CompositeVideoClip([myclip], size=(1280, 720))#final.set_duration(7).write_videofile("test.mp4", fps=30)+def test_issue_467():cad = 'media/python_logo.png'clip = ImageClip(cad)- #caused an error, NameError: global name 'copy' is not defined+ # caused an error, NameError: global name 'copy' is not definedclip = clip.fx(blink, d_on=1, d_off=1)+def test_issue_470():audio_clip = AudioFileClip('media/crunching.mp3')@@ -256,11 +271,14 @@ def test_issue_470():subclip = audio_clip.subclip(t_start=6, t_end=9)with pytest.raises(IOError, message="Expecting IOError"):- subclip.write_audiofile(os.path.join(TMP_DIR, 'issue_470.wav'), write_logfile=True)+ subclip.write_audiofile(os.path.join(+ TMP_DIR, 'issue_470.wav'), write_logfile=True)- #but this one should work..+ # but this one should work..subclip = audio_clip.subclip(t_start=6, t_end=8)- subclip.write_audiofile(os.path.join(TMP_DIR, 'issue_470.wav'), write_logfile=True)+ subclip.write_audiofile(os.path.join(+ TMP_DIR, 'issue_470.wav'), write_logfile=True)+def test_issue_246():def test_audio_reader():@@ -269,34 +287,35 @@ def test_issue_246():subclip.write_audiofile(os.path.join(TMP_DIR, 'issue_246.wav'),write_logfile=True)+def test_issue_547():- red = ColorClip((640, 480), color=(255,0,0)).set_duration(1)- green = ColorClip((640, 480), color=(0,255,0)).set_duration(2)- blue = ColorClip((640, 480), color=(0,0,255)).set_duration(3)+ red = ColorClip((640, 480), color=(255, 0, 0)).set_duration(1)+ green = ColorClip((640, 480), color=(0, 255, 0)).set_duration(2)+ blue = ColorClip((640, 480), color=(0, 0, 255)).set_duration(3)- video=concatenate_videoclips([red, green, blue], method="compose")+ video = concatenate_videoclips([red, green, blue], method="compose")assert video.duration == 6assert video.mask.duration == 6- video=concatenate_videoclips([red, green, blue])+ video = concatenate_videoclips([red, green, blue])assert video.duration == 6+def test_issue_636():- with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,11) as video:- with video.subclip(0,1) as subclip:- pass+ with VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 11) as video:+ with video.subclip(0, 1) as subclip:+ pass+def test_issue_655():video_file = 'media/fire2.mp4'- for subclip in [(0,2),(1,2),(2,3)]:+ for subclip in [(0, 2), (1, 2), (2, 3)]:with VideoFileClip(video_file) as v:- with v.subclip(1,2) as s:+ with v.subclip(1, 2) as s:passnext(v.subclip(*subclip).iter_frames())assert True-if __name__ == '__main__':- pytest.main()-+ pytest.main()diff --git a/tests/test_misc.py b/tests/test_misc.pyindex 6942f638..64c0530c 100644--- a/tests/test_misc.py+++ b/tests/test_misc.py@@ -2,6 +2,7 @@ import osimport sysimport moviepy.video.tools.cuts as cuts+from moviepy.utils import close_all_clipsimport pytestfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.compositing.concatenate import concatenate_videoclips@@ -9,35 +10,38 @@ from moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitlesfrom moviepy.video.VideoClip import ColorClip, TextClipfrom moviepy.video.io.VideoFileClip import VideoFileClip-import download_media-from test_helper import TMP_DIR, FONT+from . import download_media+from .test_helper import TMP_DIR, FONTsys.path.append("tests")def test_download_media(capsys):with capsys.disabled():- download_media.download()+ download_media.download()+def test_cuts1():- with VideoFileClip("media/big_buck_bunny_432_433.webm").resize(0.2) as clip:- cuts.find_video_period(clip) == pytest.approx(0.966666666667, 0.0001)+ clip = VideoFileClip("media/big_buck_bunny_432_433.webm").resize(0.2)+ cuts.find_video_period(clip) == pytest.approx(0.966666666667, 0.0001)+ close_all_clips(locals())+def test_subtitles():- red = ColorClip((800, 600), color=(255,0,0)).set_duration(10)- green = ColorClip((800, 600), color=(0,255,0)).set_duration(10)- blue = ColorClip((800, 600), color=(0,0,255)).set_duration(10)- myvideo = concatenate_videoclips([red,green,blue])+ red = ColorClip((800, 600), color=(255, 0, 0)).set_duration(10)+ green = ColorClip((800, 600), color=(0, 255, 0)).set_duration(10)+ blue = ColorClip((800, 600), color=(0, 0, 255)).set_duration(10)+ myvideo = concatenate_videoclips([red, green, blue])assert myvideo.duration == 30generator = lambda txt: TextClip(txt, font=FONT,- size=(800,600), fontsize=24,+ size=(800, 600), fontsize=24,method='caption', align='South',color='white')subtitles = SubtitlesClip("media/subtitles1.srt", generator)- with CompositeVideoClip([myvideo, subtitles]) as final:- final.to_videofile(os.path.join(TMP_DIR, "subtitles1.mp4"), fps=30)+ final = CompositeVideoClip([myvideo, subtitles])+ final.write_videofile(os.path.join(TMP_DIR, "subtitles1.mp4"), fps=30)data = [([0.0, 4.0], 'Red!'), ([5.0, 9.0], 'More Red!'),([10.0, 14.0], 'Green!'), ([15.0, 19.0], 'More Green!'),@@ -47,6 +51,8 @@ def test_subtitles():subtitles = SubtitlesClip(data, generator)assert subtitles.subtitles == data+ close_all_clips(locals())+def test_file_to_subtitles():data = [([0.0, 4.0], 'Red!'), ([5.0, 9.0], 'More Red!'),@@ -56,4 +62,4 @@ def test_file_to_subtitles():assert data == file_to_subtitles("media/subtitles1.srt")if __name__ == '__main__':- pytest.main()+ pytest.main()diff --git a/tests/test_resourcerelease.py b/tests/test_resourcerelease.pyindex 98c9eb0c..87ac1beb 100644--- a/tests/test_resourcerelease.py+++ b/tests/test_resourcerelease.py@@ -12,7 +12,7 @@ from os.path import joinimport subprocess as spimport time# from tempfile import NamedTemporaryFile-from test_helper import TMP_DIR+from .test_helper import TMP_DIRfrom moviepy.video.compositing.CompositeVideoClip import clips_arrayfrom moviepy.video.VideoClip import ColorClip@@ -21,26 +21,27 @@ from moviepy.video.io.VideoFileClip import VideoFileClipdef test_release_of_file_via_close():# Create a random video file.- red = ColorClip((1024, 800), color=(255, 0, 0))- green = ColorClip((1024, 800), color=(0, 255, 0))- blue = ColorClip((1024, 800), color=(0, 0, 255))+ red = ColorClip((256, 200), color=(255, 0, 0))+ green = ColorClip((256, 200), color=(0, 255, 0))+ blue = ColorClip((256, 200), color=(0, 0, 255))- red.fps = green.fps = blue.fps = 30+ red.fps = green.fps = blue.fps = 10# Repeat this so we can see no conflicts.- for i in range(5):+ for i in range(3):# Get the name of a temporary file we can use.- local_video_filename = join(TMP_DIR, "test_release_of_file_via_close_%s.mp4" % int(time.time()))+ local_video_filename = join(+ TMP_DIR,+ "test_release_of_file_via_close_%s.mp4" % int(time.time())+ )- with clips_array([[red, green, blue]]) as ca:- video = ca.set_duration(1)-- video.write_videofile(local_video_filename)+ clip = clips_array([[red, green, blue]]).set_duration(0.5)+ clip.write_videofile(local_video_filename)# Open it up with VideoFileClip.- with VideoFileClip(local_video_filename) as clip:- # Normally a client would do processing here.- pass+ video = VideoFileClip(local_video_filename)+ video.close()+ clip.close()# Now remove the temporary file.# This would fail on Windows if the file is still locked.diff --git a/tests/test_resourcereleasedemo.py b/tests/test_resourcereleasedemo.pyindex e190a913..f68c41f8 100644--- a/tests/test_resourcereleasedemo.py+++ b/tests/test_resourcereleasedemo.py@@ -12,34 +12,35 @@ from os.path import joinimport subprocess as spimport time# from tempfile import NamedTemporaryFile-from test_helper import TMP_DIR+from .test_helper import TMP_DIRfrom moviepy.video.compositing.CompositeVideoClip import clips_arrayfrom moviepy.video.VideoClip import ColorClipfrom moviepy.video.io.VideoFileClip import VideoFileClip# import pytest-def test_failure_to_release_file():+def test_failure_to_release_file():""" This isn't really a test, because it is expected to fail.It demonstrates that there *is* a problem with not releasing resources when running onWindows.-+The real issue was that, as of movepy 0.2.3.2, there was no way around it.-+See test_resourcerelease.py to see how the close() methods provide a solution."""# Get the name of a temporary file we can use.- local_video_filename = join(TMP_DIR, "test_release_of_file_%s.mp4" % int(time.time()))+ local_video_filename = join(+ TMP_DIR, "test_release_of_file_%s.mp4" % int(time.time()))# Repeat this so we can see that the problems escalate:for i in range(5):# Create a random video file.- red = ColorClip((1024,800), color=(255,0,0))- green = ColorClip((1024,800), color=(0,255,0))- blue = ColorClip((1024,800), color=(0,0,255))+ red = ColorClip((256, 200), color=(255, 0, 0))+ green = ColorClip((256, 200), color=(0, 255, 0))+ blue = ColorClip((256, 200), color=(0, 0, 255))red.fps = green.fps = blue.fps = 30video = clips_array([[red, green, blue]]).set_duration(1)@@ -53,15 +54,19 @@ def test_failure_to_release_file():# Normally a client would do processing here.# All finished, so delete the clipS.+ clip.close()+ video.close()del clipdel videoexcept IOError:- print("On Windows, this succeeds the first few times around the loop, but eventually fails.")- print("Need to shut down the process now. No more tests in this file.")+ print(+ "On Windows, this succeeds the first few times around the loop"+ " but eventually fails.")+ print("Need to shut down the process now. No more tests in"+ "this file.")return-try:# Now remove the temporary file.# This will fail on Windows if the file is still locked.diff --git a/tests/test_videotools.py b/tests/test_videotools.pyindex c4016359..fd8161b1 100644--- a/tests/test_videotools.py+++ b/tests/test_videotools.py@@ -6,7 +6,7 @@ import osfrom moviepy.video.tools.credits import credits1sys.path.append("tests")-from test_helper import TMP_DIR+from .test_helper import TMP_DIRdef test_credits():