Video editing with Python
Remove useless test, format doc examples, add doc for dev guide, update readme
osaajanif6e467f5e2a5
diff --git a/README.rst b/README.rstindex 6656f7ac..4d83a337 100644--- a/README.rst+++ b/README.rst@@ -14,35 +14,39 @@ MoviePy:target: https://coveralls.io/github/Zulko/moviepy?branch=master:alt: Code coverage from coveralls.io-MoviePy (full documentation_) is a Python library for video editing: cutting, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects. See the gallery_ for some examples of use.+MoviePy (full documentation_) is a Python library for video editing: cutting, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects.-MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with Python 3.6+. Here it is in action in an IPython notebook:--.. image:: https://raw.githubusercontent.com/Zulko/moviepy/master/docs/demo_preview.jpeg- :alt: [logo]- :align: center+MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with Python 3.7+.Example--------In this example we open a video file, select the subclip between t=50s and t=60s, add a title at the center of the screen, and write the result to a new file:+In this example we open a video file, select the subclip between 10 and 20 seconds, add a title at the center of the screen, and write the result to a new file:.. code:: python+ # Import everything needed to edit video clipsfrom moviepy import *- video = VideoFileClip("myHolidays.mp4").subclip(50,60)+ # Load file example.mp4 and extract only the subclip from 00:00:10 to 00:00:20+ clip = VideoFileClip("long_examples/example2.mp4").with_subclip(10, 20)- # Make the text. Many more options are available.- txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')- .with_position('center')- .with_duration(10) )+ # Reduce the audio volume to 80% of his original volume+ clip = clip.with_multiply_volume(0.8)- result = CompositeVideoClip([video, txt_clip]) # Overlay text on video- result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...--*Note:* This example uses the new 2.x API, for MoviePy 1.0.3, currently on PyPI, see `this snippet <https://gist.github.com/Zulko/57e6e50debef1834fb9b60700b1b9f99>`_.+ # Generate a text clip. You can customize the font, color, etc.+ txt_clip = TextClip(font="example.ttf", text="Big Buck Bunny", font_size=70, color='white')++ # Say that you want it to appear for 10s at the center of the screen+ txt_clip = txt_clip.with_position('center').with_duration(10)++ # Overlay the text clip on the first video clip+ video = CompositeVideoClip([clip, txt_clip])++ # Write the result to a file (many options available!)+ video.write_videofile("result.mp4")+Maintainers wanted!-------------------@@ -52,51 +56,9 @@ As there are more and more people seeking support (270 open issues as of Jan. 20Installation-------------MoviePy depends on the Python modules NumPy_, Imageio_, Decorator_, and Proglog_, which will be automatically installed during MoviePy's installation. The software FFMPEG should be automatically downloaded/installed (by imageio) during your first use of MoviePy (installation will take a few seconds). If you want to use a specific version of FFMPEG, follow the instructions in ``config_defaults.py``. In case of trouble, provide feedback.--**Installation by hand:** download the sources, either from PyPI_ or, if you want the development version, from GitHub_, unzip everything into one folder, open a terminal and type:--.. code:: bash-- $ (sudo) python setup.py install--**Installation with pip:** if you have ``pip`` installed, just type this in a terminal:--.. code:: bash-- $ (sudo) pip install moviepy--If you have neither ``setuptools`` nor ``ez_setup`` installed, the command above will fail. In this case type this before installing:--.. code:: bash-- $ (sudo) pip install setuptools-+For standard installation, see documentation_install_.-Optional but useful dependencies-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--You can install ``moviepy`` with all dependencies via:--.. code:: bash-- $ (sudo) pip install moviepy[optional]--ImageMagick_ is not strictly required, but needed if you want to incorporate texts. It can also be used as a backend for GIFs, though you can also create GIFs with MoviePy without ImageMagick.--Once you have installed ImageMagick, MoviePy will try to autodetect the path to its executable. If it fails, you can still configure it by setting environment variables (see the documentation).--PyGame_ is needed for video and sound previews (not relevant if you intend to work with MoviePy on a server but essential for advanced video editing by hand).--For advanced image processing, you will need one or several of the following packages:--- The Python Imaging Library (PIL) or, even better, its branch Pillow_.-- Scipy_ (for tracking, segmenting, etc.) can be used to resize video clips if PIL and OpenCV are not installed.-- `Scikit Image`_ may be needed for some advanced image manipulation.-- `OpenCV 2.4.6`_ or a more recent version (one that provides the package ``cv2``) may be needed for some advanced image manipulation.-- `Matplotlib`_--For instance, using the method ``clip.resize`` requires that at least one of Scipy, PIL, Pillow or OpenCV is installed.+For contributors installation, see documentation_dev_install_.Documentation@@ -122,30 +84,7 @@ You can pass additional arguments to the documentation build, such as clean builMore information is available from the `Sphinx`_ documentation.-New in 1.0.0: Progress bars and messages with Proglog----------------------------------------------------------Non-backwards-compatible changes were introduced in 1.0.0 to-manage progress bars and messages using-`Proglog <https://github.com/Edinburgh-Genome-Foundry/Proglog>`_, which-enables to display nice progress bars in the console as well as in-a Jupyter notebook or any user interface, like a website.--To display notebook friendly progress bars, first install IPyWidgets:--.. code::-- sudo pip install ipywidgets- sudo jupyter nbextension enable --py --sys-prefix widgetsnbextension--Then at the beginning of your notebook enter:--.. code:: python-- import proglog- proglog.notebook()-Have a look at the Proglog project page for more options.Contribute----------@@ -170,8 +109,9 @@ Maintainers.. MoviePy links-.. _gallery: https://zulko.github.io/moviepy/gallery.html.. _documentation: https://zulko.github.io/moviepy/+.. _documentation_install: https://zulko.github.io/moviepy/getting_started/install.html+.. _documentation_dev_install: https://zulko.github.io/moviepy/developer_guide/developers_install.rst.. _`download MoviePy`: https://github.com/Zulko/moviepy.. _`Label Wiki`: https://github.com/Zulko/moviepy/wiki/Label-Wiki.. _Contributing Guidelines: https://github.com/Zulko/moviepy/blob/master/CONTRIBUTING.md@@ -183,18 +123,6 @@ Maintainers.. _Gitter: https://gitter.im/movie-py/Lobby.. Software, Tools, Libraries-.. _Pillow: https://pillow.readthedocs.org/en/latest/-.. _Scipy: https://www.scipy.org/-.. _`OpenCV 2.4.6`: https://github.com/skvark/opencv-python-.. _Pygame: https://www.pygame.org/download.shtml-.. _Numpy: https://www.scipy.org/install.html-.. _imageio: https://imageio.github.io/-.. _`Scikit Image`: https://scikit-image.org/docs/stable/install.html-.. _Decorator: https://pypi.python.org/pypi/decorator-.. _proglog: https://github.com/Edinburgh-Genome-Foundry/Proglog-.. _ffmpeg: https://www.ffmpeg.org/download.html-.. _ImageMagick: https://www.imagemagick.org/script/index.php-.. _`Matplotlib`: https://matplotlib.org/.. _`Sphinx`: https://www.sphinx-doc.org/en/master/setuptools.html.. Peoplediff --git a/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py b/docs/_static/code/getting_started/moviepy_10_minutes/trailer.pyindex 5cbb7db7..f530c383 100644--- a/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py+++ b/docs/_static/code/getting_started/moviepy_10_minutes/trailer.py@@ -19,8 +19,10 @@ video = VideoFileClip("./resources/bbb.mp4")intro_clip = video.with_subclip(1, 11)bird_clip = video.with_subclip(16, 20)bunny_clip = video.with_subclip(37, 55)-rodents_clip = video.with_subclip('00:03:34.75', '00:03:56') # we can also use string notation with format HH:MM:SS.uS-rambo_clip = video.with_subclip('04:41.5', '04:44.70')+rodents_clip = video.with_subclip(+ "00:03:34.75", "00:03:56"+) # we can also use string notation with format HH:MM:SS.uS+rambo_clip = video.with_subclip("04:41.5", "04:44.70")#####################@@ -45,7 +47,7 @@ rambo_clip.preview(fps=20)rodents_clip = rodents_clip.with_cutout(start_time=4, end_time=10)# Note: You may have noticed that we have reassign rodents_clip, this is because all with_* methods return a modified *copy* of the-# original clip instead of modifying it directly. In MoviePy any function starting by with_* is out-place instead of in-place+# original clip instead of modifying it directly. In MoviePy any function starting by with_* is out-place instead of in-place# meaning it does not modify the original data, but instead copy it and modify/return the copy# Lets check the result@@ -56,16 +58,28 @@ rodents_clip.preview(fps=10)############################# Lets create the texts to put between our clipsfont = "./resources/font/font.ttf"-intro_text = TextClip(font=font, text="The Blender Foundation and\nPeach Project presents", font_size=50, color='#fff', text_align="center")-bird_text = TextClip(font=font, text="An unlucky bird", font_size=50, color='#fff')-bunny_text = TextClip(font=font, text="A (slightly overweight) bunny", font_size=50, color='#fff')-rodents_text = TextClip(font=font, text="And three rodent pests", font_size=50, color='#fff')-revenge_text = TextClip(font=font, text="Revenge is coming...", font_size=50, color='#fff')-made_with_text = TextClip(font=font, text="Made with", font_size=50, color='#fff')+intro_text = TextClip(+ font=font,+ text="The Blender Foundation and\nPeach Project presents",+ font_size=50,+ color="#fff",+ text_align="center",+)+bird_text = TextClip(font=font, text="An unlucky bird", font_size=50, color="#fff")+bunny_text = TextClip(+ font=font, text="A (slightly overweight) bunny", font_size=50, color="#fff"+)+rodents_text = TextClip(+ font=font, text="And three rodent pests", font_size=50, color="#fff"+)+revenge_text = TextClip(+ font=font, text="Revenge is coming...", font_size=50, color="#fff"+)+made_with_text = TextClip(font=font, text="Made with", font_size=50, color="#fff")# We will also need the big buck bunny logo, so lets load it and resize it-logo_clip = ImageClip('./resources/logo_bbb.png').resized(width=400)-moviepy_clip = ImageClip('./resources/logo_moviepy.png').resized(width=300)+logo_clip = ImageClip("./resources/logo_bbb.png").resized(width=400)+moviepy_clip = ImageClip("./resources/logo_moviepy.png").resized(width=300)################@@ -75,11 +89,19 @@ moviepy_clip = ImageClip('./resources/logo_moviepy.png').resized(width=300)# all our clips would start at the same time and play on top of each other, which is obviously not what we want.# To fix that, we need to say when a clip should start and stop in the final clip.# So, lets start by telling when each clip must start and end with appropriate with_* methods-intro_text = intro_text.with_duration(6).with_start(3) # Intro for 6 seconds, start after 3 seconds-logo_clip = logo_clip.with_start(intro_text.start + 2).with_end(intro_text.end) # Logo start 2 second after intro text and stop with it-bird_clip = bird_clip.with_start(intro_clip.end) # Make bird clip start after intro, duration already known-bird_text = bird_text.with_start(bird_clip.start).with_end(bird_clip.end) # Make text synchro with clip-bunny_clip = bunny_clip.with_start(bird_clip.end) # Make bunny clip follow bird clip+intro_text = intro_text.with_duration(6).with_start(+ 3+) # Intro for 6 seconds, start after 3 seconds+logo_clip = logo_clip.with_start(intro_text.start + 2).with_end(+ intro_text.end+) # Logo start 2 second after intro text and stop with it+bird_clip = bird_clip.with_start(+ intro_clip.end+) # Make bird clip start after intro, duration already known+bird_text = bird_text.with_start(bird_clip.start).with_end(+ bird_clip.end+) # Make text synchro with clip+bunny_clip = bunny_clip.with_start(bird_clip.end) # Make bunny clip follow bird clipbunny_text = bunny_text.with_start(bunny_clip.start + 2).with_duration(7)rodents_clip = rodents_clip.with_start(bunny_clip.end)rodents_text = rodents_text.with_start(rodents_clip.start).with_duration(4)@@ -94,8 +116,23 @@ moviepy_clip = moviepy_clip.with_start(made_with_text.start).with_duration(3)######################### Lets make a first compositing of thoses clips into one single clip and do a quick preview to see if everything is synchro-quick_compo = CompositeVideoClip([intro_clip, intro_text, logo_clip, bird_clip, bird_text, bunny_clip, bunny_text, rodents_clip,- rodents_text, rambo_clip, revenge_text, made_with_text, moviepy_clip])+quick_compo = CompositeVideoClip(+ [+ intro_clip,+ intro_text,+ logo_clip,+ bird_clip,+ bird_text,+ bunny_clip,+ bunny_text,+ rodents_clip,+ rodents_text,+ rambo_clip,+ revenge_text,+ made_with_text,+ moviepy_clip,+ ]+)quick_compo.preview(fps=10)@@ -104,22 +141,37 @@ quick_compo.preview(fps=10)####################### Now that we have set the timing of our different clips, we need to make sure they are in the right position# We will keep things simple, and almost always set center center for every texts-bird_text = bird_text.with_position(('center', 'center'))-bunny_text = bunny_text.with_position(('center', 'center'))-rodents_text = rodents_text.with_position(('center', 'center'))-revenge_text = revenge_text.with_position(('center', 'center'))+bird_text = bird_text.with_position(("center", "center"))+bunny_text = bunny_text.with_position(("center", "center"))+rodents_text = rodents_text.with_position(("center", "center"))+revenge_text = revenge_text.with_position(("center", "center"))# For the logos and intro/end, we will use pixel position instead of centertop = intro_clip.h // 2-intro_text = intro_text.with_position(('center', 200))+intro_text = intro_text.with_position(("center", 200))logo_clip = logo_clip.with_position(("center", top))-made_with_text = made_with_text.with_position(('center', 300))-moviepy_clip = moviepy_clip.with_position(('center', 360))+made_with_text = made_with_text.with_position(("center", 300))+moviepy_clip = moviepy_clip.with_position(("center", 360))# Lets take another look to check positions-quick_compo = CompositeVideoClip([intro_clip, intro_text, logo_clip, bird_clip, bird_text, bunny_clip, bunny_text, rodents_clip,- rodents_text, rambo_clip, revenge_text, made_with_text, moviepy_clip])-# quick_compo.preview(fps=10)+quick_compo = CompositeVideoClip(+ [+ intro_clip,+ intro_text,+ logo_clip,+ bird_clip,+ bird_text,+ bunny_clip,+ bunny_text,+ rodents_clip,+ rodents_text,+ rambo_clip,+ revenge_text,+ made_with_text,+ moviepy_clip,+ ]+)+quick_compo.preview(fps=10)################################@@ -137,12 +189,24 @@ rodents_text = rodents_text.with_effects([vfx.CrossFadeIn(0.5), vfx.CrossFadeOut# Also add cross fading on video clips and video clips audio# See how video effects are under vfx and audio ones under afx-intro_clip = intro_clip.with_effects([vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)])-bird_clip = bird_clip.with_effects([vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)])-bunny_clip = bunny_clip.with_effects([vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)])-rodents_clip = rodents_clip.with_effects([vfx.FadeIn(1), vfx.CrossFadeOut(1.5), afx.AudioFadeIn(1), afx.AudioFadeOut(1.5)]) # Just fade in, rambo clip will do the cross fade-rambo_clip = rambo_clip.with_effects([vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)])-rambo_clip = rambo_clip.with_effects([vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)])+intro_clip = intro_clip.with_effects(+ [vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)]+)+bird_clip = bird_clip.with_effects(+ [vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)]+)+bunny_clip = bunny_clip.with_effects(+ [vfx.FadeIn(1), vfx.FadeOut(1), afx.AudioFadeIn(1), afx.AudioFadeOut(1)]+)+rodents_clip = rodents_clip.with_effects(+ [vfx.FadeIn(1), vfx.CrossFadeOut(1.5), afx.AudioFadeIn(1), afx.AudioFadeOut(1.5)]+) # Just fade in, rambo clip will do the cross fade+rambo_clip = rambo_clip.with_effects(+ [vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)]+)+rambo_clip = rambo_clip.with_effects(+ [vfx.CrossFadeIn(1.5), vfx.FadeOut(1), afx.AudioFadeIn(1.5), afx.AudioFadeOut(1)]+)# Effects are not only for transition, they can also change a clip timing or apparence# To show that, lets also modify the Rambo-like part of our clip to be in slow motion@@ -155,45 +219,62 @@ made_with_text = made_with_text.with_start(rambo_clip.end).with_duration(3)moviepy_clip = moviepy_clip.with_start(made_with_text.start).with_duration(3)# Let's have a last look at the result to make sure everything is working as expected-quick_comp = CompositeVideoClip([intro_clip, intro_text, logo_clip, bird_clip, bird_text, bunny_clip, bunny_text,- rodents_clip, rodents_text, rambo_clip, revenge_text, made_with_text, moviepy_clip])+quick_comp = CompositeVideoClip(+ [+ intro_clip,+ intro_text,+ logo_clip,+ bird_clip,+ bird_text,+ bunny_clip,+ bunny_text,+ rodents_clip,+ rodents_text,+ rambo_clip,+ revenge_text,+ made_with_text,+ moviepy_clip,+ ]+)quick_comp.preview(fps=10)################ CLIP FILTER ################-# Lets finish by modifying our rambo clip to make it sepia+# Lets finish by modifying our rambo clip to make it sepia+# We will start by defining a function that turn a numpy image into sepia# It takes the image as numpy array in entry and return the modified image as outputdef sepia_fitler(frame: np.ndarray):- # Sepia filter transformation matrix- # Sepia transform works by applying to each pixel of the image the following rules- # res_R = (R * .393) + (G *.769) + (B * .189)- # res_G = (R * .349) + (G *.686) + (B * .168)- # res_B = (R * .272) + (G *.534) + (B * .131)- #- # With numpy we can do that very efficiently by multiplying the image matrix by a transformation matrix- sepia_matrix = np.array([[0.393, 0.769, 0.189],- [0.349, 0.686, 0.168],- [0.272, 0.534, 0.131]])+ # Sepia filter transformation matrix+ # Sepia transform works by applying to each pixel of the image the following rules+ # res_R = (R * .393) + (G *.769) + (B * .189)+ # res_G = (R * .349) + (G *.686) + (B * .168)+ # res_B = (R * .272) + (G *.534) + (B * .131)+ #+ # With numpy we can do that very efficiently by multiplying the image matrix by a transformation matrix+ sepia_matrix = np.array(+ [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]+ )++ # Convert the image to float32 format for matrix multiplication+ frame = frame.astype(np.float32)- # Convert the image to float32 format for matrix multiplication- frame = frame.astype(np.float32)+ # Apply the sepia transformation+ # .T is needed because multiplying matrix of shape (n,m) * (m,k) result in a matrix of shape (n,k)+ # what we want is (n,m), so we must transpose matrix (m,k) to (k,m)+ sepia_image = np.dot(frame, sepia_matrix.T)- # Apply the sepia transformation- # .T is needed because multiplying matrix of shape (n,m) * (m,k) result in a matrix of shape (n,k)- # what we want is (n,m), so we must transpose matrix (m,k) to (k,m)- sepia_image = np.dot(frame, sepia_matrix.T)+ # Because final result can be > 255, we limit the result to range [0, 255]+ sepia_image = np.clip(sepia_image, 0, 255)- # Because final result can be > 255, we limit the result to range [0, 255]- sepia_image = np.clip(sepia_image, 0, 255)+ # Convert the image back to uint8 format, because we need integer not float+ sepia_image = sepia_image.astype(np.uint8)- # Convert the image back to uint8 format, because we need integer not float- sepia_image = sepia_image.astype(np.uint8)+ return sepia_image- return sepia_image# Now, we simply apply the filter to our clip by calling image_transform, which will call our filter on every framerambo_clip = rambo_clip.image_transform(sepia_fitler)@@ -206,6 +287,21 @@ rambo_clip.preview(fps=10)# CLIP RENDERING #################### Everything is good and ready, we can finally render our clip into a file-final_clip = CompositeVideoClip([intro_clip, intro_text, logo_clip, bird_clip, bird_text, bunny_clip, bunny_text,- rodents_clip, rodents_text, rambo_clip, revenge_text, made_with_text, moviepy_clip])-final_clip.write_videofile("./result.mp4")\ No newline at end of file+final_clip = CompositeVideoClip(+ [+ intro_clip,+ intro_text,+ logo_clip,+ bird_clip,+ bird_text,+ bunny_clip,+ bunny_text,+ rodents_clip,+ rodents_text,+ rambo_clip,+ revenge_text,+ made_with_text,+ moviepy_clip,+ ]+)+final_clip.write_videofile("./result.mp4")diff --git a/docs/_static/code/getting_started/quick_presentation/basic_example.py b/docs/_static/code/getting_started/quick_presentation/basic_example.pyindex 109e4c07..2a32d0ec 100644--- a/docs/_static/code/getting_started/quick_presentation/basic_example.py+++ b/docs/_static/code/getting_started/quick_presentation/basic_example.py@@ -8,10 +8,12 @@ clip = VideoFileClip("long_examples/example2.mp4").with_subclip(10, 20)clip = clip.with_multiply_volume(0.8)# Generate a text clip. You can customize the font, color, etc.-txt_clip = TextClip(font="example.ttf", text="Big Buck Bunny", font_size=70, color='white')+txt_clip = TextClip(+ font="example.ttf", text="Big Buck Bunny", font_size=70, color="white"+)# Say that you want it to appear for 10s at the center of the screen-txt_clip = txt_clip.with_position('center').with_duration(10)+txt_clip = txt_clip.with_position("center").with_duration(10)# Overlay the text clip on the first video clipvideo = CompositeVideoClip([clip, txt_clip])diff --git a/docs/_static/code/user_guide/compositing/CompositeAudioClip.py b/docs/_static/code/user_guide/compositing/CompositeAudioClip.pyindex 8dff9ff7..a810bfcf 100644--- a/docs/_static/code/user_guide/compositing/CompositeAudioClip.py+++ b/docs/_static/code/user_guide/compositing/CompositeAudioClip.py@@ -6,9 +6,13 @@ aclip2 = AudioFileClip("example2.wav")aclip3 = AudioFileClip("example3.wav")# All clip will play one after the other-concat = concatenate_audioclips([aclip1, aclip2, aclip3])+concat = concatenate_audioclips([aclip1, aclip2, aclip3])# We will play aclip1, then ontop of it aclip2 after 5s, and the aclip3 on top of both after 9s-compo = CompositeAudioClip([aclip1.with_multiply_volume(1.2),- aclip2.with_start(5), # start at t=5s- aclip3.with_start(9)])\ No newline at end of file+compo = CompositeAudioClip(+ [+ aclip1.with_multiply_volume(1.2),+ aclip2.with_start(5), # start at t=5s+ aclip3.with_start(9),+ ]+)diff --git a/docs/_static/code/user_guide/compositing/CompositeVideoClip.py b/docs/_static/code/user_guide/compositing/CompositeVideoClip.pyindex 33e3ccfc..1c178550 100644--- a/docs/_static/code/user_guide/compositing/CompositeVideoClip.py+++ b/docs/_static/code/user_guide/compositing/CompositeVideoClip.py@@ -1,4 +1,5 @@from moviepy import *+# We load all the clips we want to composeclip1 = VideoFileClip("example.mp4")clip2 = VideoFileClip("example2.mp4").with_subclip(0, 1)@@ -6,4 +7,4 @@ clip3 = VideoFileClip("example3.mp4")# We concatenate them and write theme stacked on top of each other, with clip3 over clip2 over clip1final_clip = CompositeVideoClip([clip1, clip2, clip3])-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/compositing/concatenate.py b/docs/_static/code/user_guide/compositing/concatenate.pyindex f10fc48e..edc99137 100644--- a/docs/_static/code/user_guide/compositing/concatenate.py+++ b/docs/_static/code/user_guide/compositing/concatenate.py@@ -6,5 +6,5 @@ clip2 = VideoFileClip("example2.mp4").with_subclip(0, 1)clip3 = VideoFileClip("example3.mp4")# We concatenate them and write the result-final_clip = concatenate_videoclips([clip1,clip2,clip3])-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip = concatenate_videoclips([clip1, clip2, clip3])+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/compositing/crossfadein.py b/docs/_static/code/user_guide/compositing/crossfadein.pyindex 63060de4..ffdae5d2 100644--- a/docs/_static/code/user_guide/compositing/crossfadein.py+++ b/docs/_static/code/user_guide/compositing/crossfadein.py@@ -2,18 +2,17 @@ from moviepy import *# We load all the clips we want to composeclip1 = VideoFileClip("example.mp4")-clip2 = VideoFileClip("example2.mp4").with_subclip(0,1)+clip2 = VideoFileClip("example2.mp4").with_subclip(0, 1)# Clip2 will be on top of clip1 for 1sclip1 = clip1.with_end(2)clip2 = clip2.with_start(1)# We will add a crossfadein on clip2 for 1s-# As the other effects, transitions are added to Clip methods at runtime-clip2 = clip2.with_effects([vfx.CrossFadeIn(1)])-+# As the other effects, transitions are added to Clip methods at runtime+clip2 = clip2.with_effects([vfx.CrossFadeIn(1)])# We write the resultfinal_clip = CompositeVideoClip([clip1, clip2])-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/compositing/juxtaposing.py b/docs/_static/code/user_guide/compositing/juxtaposing.pyindex e81f471a..6d81620a 100644--- a/docs/_static/code/user_guide/compositing/juxtaposing.py+++ b/docs/_static/code/user_guide/compositing/juxtaposing.py@@ -1,14 +1,16 @@from moviepy import VideoFileClip, clips_array, vfx# We will use the same clip and transform it in 3 ways-clip1 = VideoFileClip("example.mp4").with_effects([vfx.Margin(10)]) # add 10px contour-clip2 = clip1.with_effects([vfx.MirrorX()]) # Flip horizontaly-clip3 = clip1.with_effects([vfx.MirrorY()]) # Flip verticaly-clip4 = clip1.resized(0.60) # downsize to 60% of original+clip1 = VideoFileClip("example.mp4").with_effects([vfx.Margin(10)]) # add 10px contour+clip2 = clip1.with_effects([vfx.MirrorX()]) # Flip horizontaly+clip3 = clip1.with_effects([vfx.MirrorY()]) # Flip verticaly+clip4 = clip1.resized(0.60) # downsize to 60% of original# The form of the final clip will depend of the shape of the array# We want our clip to be our 4 videos, 2x2, so we make an array of 2x2-final_clip = clips_array([[clip1, clip2], [clip3, clip4]])-final_clip = final_clip.resized(width=480) # We resize the resulting clip to have the dimensions we want+final_clip = clips_array([[clip1, clip2], [clip3, clip4]])+final_clip = final_clip.resized(+ width=480+) # We resize the resulting clip to have the dimensions we want-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/compositing/with_position.py b/docs/_static/code/user_guide/compositing/with_position.pyindex 3dc21c20..bd801d3f 100644--- a/docs/_static/code/user_guide/compositing/with_position.py+++ b/docs/_static/code/user_guide/compositing/with_position.py@@ -2,9 +2,30 @@ from moviepy import *# We load all the clips we want to composebackground = VideoFileClip("example2.mp4").with_subclip(0, 2)-title = TextClip("./example.ttf", text="Big Buck Bunny", font_size=80, color="#fff", text_align="center", duration=1)-author = TextClip("./example.ttf", text="Blender Foundation", font_size=40, color="#fff", text_align="center", duration=1)-copyright = TextClip("./example.ttf", text="© CC BY 3.0", font_size=20, color="#fff", text_align="center", duration=1)+title = TextClip(+ "./example.ttf",+ text="Big Buck Bunny",+ font_size=80,+ color="#fff",+ text_align="center",+ duration=1,+)+author = TextClip(+ "./example.ttf",+ text="Blender Foundation",+ font_size=40,+ color="#fff",+ text_align="center",+ duration=1,+)+copyright = TextClip(+ "./example.ttf",+ text="© CC BY 3.0",+ font_size=20,+ color="#fff",+ text_align="center",+ duration=1,+)logo = ImageClip("./example2.png", duration=1).resized(height=50)# We want our title to be at the center horizontaly and start at 25% of the video verticaly@@ -15,7 +36,7 @@ title = title.with_position(("center", 0.25), relative=True)# We can set as pixelstop = background.h * 0.25 + title.h + 30left = (background.w - author.w) / 2-author = author.with_position((left, top))+author = author.with_position((left, top))# We want the copyright to be 30px before bottomcopyright = copyright.with_position(("center", background.h - copyright.h - 30))@@ -23,8 +44,8 @@ copyright = copyright.with_position(("center", background.h - copyright.h - 30))# Finally, we want the logo to be in the center, but to drop as time pass# We can do so by setting position as a function that take time as argument, a lot like make_frametop = (background.h - logo.h) / 2-logo = logo.with_position(lambda t: ('center', top + t*30))+logo = logo.with_position(lambda t: ("center", top + t * 30))# We write the resultfinal_clip = CompositeVideoClip([background, title, author, copyright, logo])-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/compositing/with_start.py b/docs/_static/code/user_guide/compositing/with_start.pyindex affebd2a..e59848da 100644--- a/docs/_static/code/user_guide/compositing/with_start.py+++ b/docs/_static/code/user_guide/compositing/with_start.py@@ -2,7 +2,7 @@ from moviepy import *# We load all the clips we want to composeclip1 = VideoFileClip("example.mp4")-clip2 = VideoFileClip("example2.mp4").with_subclip(0,1)+clip2 = VideoFileClip("example2.mp4").with_subclip(0, 1)clip3 = VideoFileClip("example3.mp4")# We want to stop clip1 after 1s@@ -12,8 +12,10 @@ clip1 = clip1.with_end(1)clip2 = clip2.with_start(1.5)# We want to play clip3 at the end of clip2, and so for 3 seconds only-clip3 = clip3.with_start(clip2.end).with_duration(1) # Some times its more practical to modify the duration of a clip instead of his end+clip3 = clip3.with_start(clip2.end).with_duration(+ 1+) # Some times its more practical to modify the duration of a clip instead of his end# We write the result-final_clip = CompositeVideoClip([clip1,clip2,clip3])-final_clip.write_videofile("final_clip.mp4")\ No newline at end of file+final_clip = CompositeVideoClip([clip1, clip2, clip3])+final_clip.write_videofile("final_clip.mp4")diff --git a/docs/_static/code/user_guide/effects/custom_effect.py b/docs/_static/code/user_guide/effects/custom_effect.pyindex 21fda2b0..51bf04b9 100644--- a/docs/_static/code/user_guide/effects/custom_effect.py+++ b/docs/_static/code/user_guide/effects/custom_effect.py@@ -2,10 +2,10 @@ from moviepy import VideoClipfrom moviepy.decorators import requires_duration-# Here you see a decorator that will verify if our clip have a duration+# Here you see a decorator that will verify if our clip have a duration# MoviePy offer a few of thoses that may come handy when writing your own effects@requires_duration-def progress_bar(clip: VideoClip, color: tuple, height: int = 10) :+def progress_bar(clip: VideoClip, color: tuple, height: int = 10):"""Add a progress bar at the bottom of our clip@@ -16,9 +16,9 @@ def progress_bar(clip: VideoClip, color: tuple, height: int = 10) :height: The height of the bar in pixels. Default = 10"""- # Because we have define the filter func inside our global effect,+ # Because we have define the filter func inside our global effect,# it have access to global effect scope and can use clip from inside filter- def filter(get_frame, t) :+ def filter(get_frame, t):progression = t / clip.durationbar_width = int(progression * clip.w)@@ -28,4 +28,4 @@ def progress_bar(clip: VideoClip, color: tuple, height: int = 10) :return frame- return clip.transform(filter, apply_to='mask')\ No newline at end of file+ return clip.transform(filter, apply_to="mask")diff --git a/docs/_static/code/user_guide/effects/image_transform.py b/docs/_static/code/user_guide/effects/image_transform.pyindex f51b6939..2983b812 100644--- a/docs/_static/code/user_guide/effects/image_transform.py+++ b/docs/_static/code/user_guide/effects/image_transform.py@@ -3,8 +3,9 @@ import numpymy_clip = VideoFileClip("example.mp4")-def invert_green_blue(image: numpy.ndarray) -> numpy.ndarray :- return image[:,:,[0,2,1]]+def invert_green_blue(image: numpy.ndarray) -> numpy.ndarray:+ return image[:, :, [0, 2, 1]]-modified_clip1 = my_clip.image_transform(invert_green_blue)\ No newline at end of file++modified_clip1 = my_clip.image_transform(invert_green_blue)diff --git a/docs/_static/code/user_guide/effects/modify_copy_example.py b/docs/_static/code/user_guide/effects/modify_copy_example.pyindex 4918c8e6..49595e94 100644--- a/docs/_static/code/user_guide/effects/modify_copy_example.py+++ b/docs/_static/code/user_guide/effects/modify_copy_example.py@@ -15,6 +15,5 @@ clip_whisper = clip.with_multiply_volume(0.1)# This replace the original clip with a copy of it where volume is only 10% of the original# If you was to render clip now, the audio would be at 10%-# The original clip is now lost+# The original clip is now lostclip = clip.with_multiply_volume(0.1)-diff --git a/docs/_static/code/user_guide/effects/time_transform.py b/docs/_static/code/user_guide/effects/time_transform.pyindex ad0ed320..c5ccad25 100644--- a/docs/_static/code/user_guide/effects/time_transform.py+++ b/docs/_static/code/user_guide/effects/time_transform.py@@ -3,11 +3,13 @@ import mathmy_clip = VideoFileClip("example.mp4")+# You can define a function the classical way-def accel_x3(time: float) -> float :+def accel_x3(time: float) -> float:return time * 3+modified_clip1 = my_clip.time_transform(accel_x3)# Of you can also use lambda function-modified_clip2 = my_clip.time_transform(lambda t: 1 + math.sin(t))\ No newline at end of file+modified_clip2 = my_clip.time_transform(lambda t: 1 + math.sin(t))diff --git a/docs/_static/code/user_guide/effects/transform.py b/docs/_static/code/user_guide/effects/transform.pyindex 0765a482..38678f86 100644--- a/docs/_static/code/user_guide/effects/transform.py+++ b/docs/_static/code/user_guide/effects/transform.py@@ -3,13 +3,15 @@ import mathmy_clip = VideoFileClip("example.mp4")+def scroll(get_frame, t):"""This function returns a 'region' of the current frame.The position of this region depends on the time."""frame = get_frame(t)- frame_region = frame[int(t):int(t)+360,:]+ frame_region = frame[int(t) : int(t) + 360, :]return frame_region-modified_clip1 = my_clip.transform(scroll)\ No newline at end of file++modified_clip1 = my_clip.transform(scroll)diff --git a/docs/_static/code/user_guide/effects/using_effects.py b/docs/_static/code/user_guide/effects/using_effects.pyindex 7588991a..8cf6cc93 100644--- a/docs/_static/code/user_guide/effects/using_effects.py+++ b/docs/_static/code/user_guide/effects/using_effects.py@@ -2,10 +2,14 @@ from moviepy import VideoFileClipfrom moviepy import vfx, afxmyclip = VideoFileClip("example.mp4")-myclip = myclip.with_effects([vfx.Resize(width=460)]) # resize clip to be 460px in width, keeping aspect ratio+myclip = myclip.with_effects(+ [vfx.Resize(width=460)]+) # resize clip to be 460px in width, keeping aspect ratio# fx method return a copy of the clip, so we can easily chain them-myclip = myclip.with_effects([vfx.MultiplySpeed(2), afx.MultiplyVolume(0.5)]) # double the speed and half the audio volume+myclip = myclip.with_effects(+ [vfx.MultiplySpeed(2), afx.MultiplyVolume(0.5)]+) # double the speed and half the audio volume# because effects are added to Clip at runtime, you can also call them directly from your clip as methods-myclip = myclip.with_effects([vfx.MultiplyColor(0.5)]) # darken the clip\ No newline at end of file+myclip = myclip.with_effects([vfx.MultiplyColor(0.5)]) # darken the clipdiff --git a/docs/_static/code/user_guide/effects/using_with_methods.py b/docs/_static/code/user_guide/effects/using_with_methods.pyindex 422fb5ff..0267dc18 100644--- a/docs/_static/code/user_guide/effects/using_with_methods.py+++ b/docs/_static/code/user_guide/effects/using_with_methods.py@@ -2,5 +2,5 @@ from moviepy import VideoFileClipfrom moviepy import vfx, afxmyclip = VideoFileClip("example.mp4")-myclip = myclip.with_end(5) # stop the clip after 5 sec-myclip = myclip.without_audio() # remove the audio of the clip+myclip = myclip.with_end(5) # stop the clip after 5 sec+myclip = myclip.without_audio() # remove the audio of the clipdiff --git a/docs/_static/code/user_guide/loading/AudioArrayClip.py b/docs/_static/code/user_guide/loading/AudioArrayClip.pyindex 1350401b..1ed74ade 100644--- a/docs/_static/code/user_guide/loading/AudioArrayClip.py+++ b/docs/_static/code/user_guide/loading/AudioArrayClip.py@@ -2,26 +2,28 @@ import numpy as npfrom moviepy import *# We want to play those notes-notes = {'A': 440, 'B': 494, 'C': 523, 'D': 587, 'E': 659, 'F': 698}+notes = {"A": 440, "B": 494, "C": 523, "D": 587, "E": 659, "F": 698}-note_duration = 0.5+note_duration = 0.5total_duration = len(notes) * note_durationsample_rate = 44100 # Number of samples per secondnote_size = int(note_duration * sample_rate)total_size = note_size * len(notes)-def make_frame (t, note_frequency) :++def make_frame(t, note_frequency):return np.sin(note_frequency * 2 * np.pi * t)+# We generate all frames timepointstimes = np.linspace(0, total_duration, total_size)# We make an array of size N*1, where N is the number of frames * total durationaudio_array = np.zeros((total_size, 2))i = 0-for note, frequency in notes.items() :- for _ in range(note_size) :+for note, frequency in notes.items():+ for _ in range(note_size):audio_array[i][0] = make_frame(times[i], frequency)i += 1@@ -29,4 +31,4 @@ for note, frequency in notes.items() :audio_clip = AudioArrayClip(audio_array, fps=sample_rate)# Write the audio clip to a WAV file-audio_clip.write_audiofile('result.wav', fps=44100)\ No newline at end of file+audio_clip.write_audiofile("result.wav", fps=44100)diff --git a/docs/_static/code/user_guide/loading/AudioClip.py b/docs/_static/code/user_guide/loading/AudioClip.pyindex f402ba8b..37f51b4c 100644--- a/docs/_static/code/user_guide/loading/AudioClip.py+++ b/docs/_static/code/user_guide/loading/AudioClip.py@@ -5,4 +5,4 @@ import numpy as npmake_frame_audio = lambda t: np.sin(440 * 2 * np.pi * t)# AUDIO CLIPS-clip = AudioClip(make_frame_audio, duration=3)\ No newline at end of file+clip = AudioClip(make_frame_audio, duration=3)diff --git a/docs/_static/code/user_guide/loading/AudioFileClip.py b/docs/_static/code/user_guide/loading/AudioFileClip.pyindex 89f2c8ac..e9aecd89 100644--- a/docs/_static/code/user_guide/loading/AudioFileClip.py+++ b/docs/_static/code/user_guide/loading/AudioFileClip.py@@ -2,5 +2,5 @@ from moviepy import *import numpy as np# Works for audio files, but also videos file where you only want the keep the audio track-clip = AudioFileClip("example.wav")-clip.write_audiofile('./result.wav')+clip = AudioFileClip("example.wav")+clip.write_audiofile("./result.wav")diff --git a/docs/_static/code/user_guide/loading/ColorClip.py b/docs/_static/code/user_guide/loading/ColorClip.pyindex 2fab5fed..9bf5d967 100644--- a/docs/_static/code/user_guide/loading/ColorClip.py+++ b/docs/_static/code/user_guide/loading/ColorClip.py@@ -1,4 +1,8 @@from moviepy import *-myclip = ColorClip(size=(200, 100), color=(255, 0, 0), duration=1) # Color is passed as a RGB tuple-myclip.write_videofile('result.mp4', fps=1) # We really dont need more than 1 fps do we ?+myclip = ColorClip(+ size=(200, 100), color=(255, 0, 0), duration=1+) # Color is passed as a RGB tuple+myclip.write_videofile(+ "result.mp4", fps=1+) # We really dont need more than 1 fps do we ?diff --git a/docs/_static/code/user_guide/loading/DataVideoClip.py b/docs/_static/code/user_guide/loading/DataVideoClip.pyindex 74175d2c..d44e04e4 100644--- a/docs/_static/code/user_guide/loading/DataVideoClip.py+++ b/docs/_static/code/user_guide/loading/DataVideoClip.py@@ -11,13 +11,15 @@ dataset = [(255, 255, 0),]+# The function make frame take data and create an image of 200x100 px fill with the color-def make_frame (data) :+def make_frame(data):frame = np.full((100, 200, 3), data, dtype=np.uint8)return frame+# We create the DataVideoClip, and we set FPS at 2, making a 3s clip (because len(dataset) = 6, so 6/2=3)myclip = DataVideoClip(data=dataset, data_to_frame=make_frame, fps=2)# Modifying fps here will change video FPS, not clip FPS-myclip.write_videofile("result.mp4", fps=30)\ No newline at end of file+myclip.write_videofile("result.mp4", fps=30)diff --git a/docs/_static/code/user_guide/loading/ImageClip.py b/docs/_static/code/user_guide/loading/ImageClip.pyindex 1d3373a6..f704a550 100644--- a/docs/_static/code/user_guide/loading/ImageClip.py+++ b/docs/_static/code/user_guide/loading/ImageClip.py@@ -2,8 +2,10 @@ from moviepy import *import numpy as np# Random RGB noise image of 200x100-noise_image = np.random.randint(low=0, high=255, size=(100, 200, 3))+noise_image = np.random.randint(low=0, high=255, size=(100, 200, 3))-myclip1 = ImageClip("example.png") # You can create it from a path-myclip2 = ImageClip(noise_image) # from a (height x width x 3) RGB numpy array-myclip3 = VideoFileClip("./example.mp4").to_ImageClip(t='00:00:01') # Or load videoclip and extract frame at a given time+myclip1 = ImageClip("example.png") # You can create it from a path+myclip2 = ImageClip(noise_image) # from a (height x width x 3) RGB numpy array+myclip3 = VideoFileClip("./example.mp4").to_ImageClip(+ t="00:00:01"+) # Or load videoclip and extract frame at a given timediff --git a/docs/_static/code/user_guide/loading/ImageSequenceClip.py b/docs/_static/code/user_guide/loading/ImageSequenceClip.pyindex a394c8d8..a1943298 100644--- a/docs/_static/code/user_guide/loading/ImageSequenceClip.py+++ b/docs/_static/code/user_guide/loading/ImageSequenceClip.py@@ -1,14 +1,27 @@from moviepy import *# A clip with a list of images showed for 1 second each-myclip = ImageSequenceClip(['example_img_dir/image_0001.jpg', 'example_img_dir/image_0002.jpg', 'example_img_dir/image_0003.jpg'], durations=[1, 1, 1])-print('Clip duration: {}'.format(myclip.duration)) # 3 images, 1 seconds each, duration = 3-print('Clip fps: {}'.format(myclip.fps)) # 3 seconds, 3 images, fps is 3/3 = 1+myclip = ImageSequenceClip(+ [+ "example_img_dir/image_0001.jpg",+ "example_img_dir/image_0002.jpg",+ "example_img_dir/image_0003.jpg",+ ],+ durations=[1, 1, 1],+)+print(+ "Clip duration: {}".format(myclip.duration)+) # 3 images, 1 seconds each, duration = 3+print("Clip fps: {}".format(myclip.fps)) # 3 seconds, 3 images, fps is 3/3 = 1# This time we will load all images in the dir, and instead of showing theme for X seconds, we will define FPSmyclip2 = ImageSequenceClip("./example_img_dir", fps=30)-print('Clip duration: {}'.format(myclip2.duration)) # fps = 30, so duration = nb images in dir / 30-print('Clip fps: {}'.format(myclip2.fps)) # fps = 30+print(+ "Clip duration: {}".format(myclip2.duration)+) # fps = 30, so duration = nb images in dir / 30+print("Clip fps: {}".format(myclip2.fps)) # fps = 30-myclip.write_gif("result.gif") # the gif will be 3 sec and 1 fps-myclip2.write_gif("result2.gif") # the gif will be 30 fps, duration will vary based on number of images in dir\ No newline at end of file+myclip.write_gif("result.gif") # the gif will be 3 sec and 1 fps+myclip2.write_gif(+ "result2.gif"+) # the gif will be 30 fps, duration will vary based on number of images in dirdiff --git a/docs/_static/code/user_guide/loading/TextClip.py b/docs/_static/code/user_guide/loading/TextClip.pyindex 6f0b0517..c3dd2310 100644--- a/docs/_static/code/user_guide/loading/TextClip.py+++ b/docs/_static/code/user_guide/loading/TextClip.py@@ -1,17 +1,33 @@from moviepy import *-font="./example.ttf"+font = "./example.ttf"# First we use as string and let system autocalculate clip dimensions to fit the text# we set clip duration to 2 secs, if we do not, it got an infinite duration-txt_clip1 = TextClip(font=font, text="Hello World !", font_size=30, color="#FF0000", bg_color="#FFFFFF", duration=2) # Red+txt_clip1 = TextClip(+ font=font,+ text="Hello World !",+ font_size=30,+ color="#FF0000",+ bg_color="#FFFFFF",+ duration=2,+) # Red# This time we load text from a file, we set a fixed size for clip and let the system find best font size,# allowing for line breaking-txt_clip2 = TextClip(font=font, filename="./example.txt", size=(500, 200), bg_color="#FFFFFF", method="caption", color=(0, 0, 255, 127)) # Blue with 50% transparency+txt_clip2 = TextClip(+ font=font,+ filename="./example.txt",+ size=(500, 200),+ bg_color="#FFFFFF",+ method="caption",+ color=(0, 0, 255, 127),+) # Blue with 50% transparency# we set duration, because by default image clip are infinite, and we cannot render infinite-txt_clip2 = txt_clip2.with_duration(2)+txt_clip2 = txt_clip2.with_duration(2)-txt_clip1.write_videofile("result1.mp4", fps=24) # ImageClip have no FPS either, so we must defined it-txt_clip2.write_videofile("result2.mp4", fps=24)\ No newline at end of file+txt_clip1.write_videofile(+ "result1.mp4", fps=24+) # ImageClip have no FPS either, so we must defined it+txt_clip2.write_videofile("result2.mp4", fps=24)diff --git a/docs/_static/code/user_guide/loading/UpdatedVideoClip.py b/docs/_static/code/user_guide/loading/UpdatedVideoClip.pyindex e35dc0f7..c45f7192 100644--- a/docs/_static/code/user_guide/loading/UpdatedVideoClip.py+++ b/docs/_static/code/user_guide/loading/UpdatedVideoClip.py@@ -2,15 +2,15 @@ from moviepy import *import numpy as npimport random+# Imagine we want to make a video that become more and more red as we repeat same face on coinflip in a row# because coinflip are done in real time, we need to wait until a winning row is done to be able# to make the next frame.# This is a world simulating that. Sorry, it's hard to come up with examples...-class CoinFlipWorld :-- def __init__(self, fps) :+class CoinFlipWorld:+ def __init__(self, fps):"""- FPS is usefull because we must increment clip_t by 1/FPS to have UpdatedVideoClip run with a certain FPS+ FPS is usefull because we must increment clip_t by 1/FPS to have UpdatedVideoClip run with a certain FPS"""self.clip_t = 0@@ -18,30 +18,32 @@ class CoinFlipWorld :self.reset = Falseself.fps = fps- def update(self) :- if self.reset :+ def update(self):+ if self.reset:self.win_strike = 0self.reset = False- print('strike : {}, clip_t : {}'.format(self.win_strike, self.clip_t))+ print("strike : {}, clip_t : {}".format(self.win_strike, self.clip_t))print(self.win_strike)# 0 tails, 1 heads, this is our simulation of coinflipchoice = random.randint(0, 1)- face = random.randint(0, 1)-+ face = random.randint(0, 1)+# We win, we increment our serie and retry- if choice == face :+ if choice == face:self.win_strike += 1return-+# Different face, we increment clip_t and set reset so we will reset on next update.# We dont reset immediately because we will need current state to make frameself.reset = Trueself.clip_t += 1 / self.fps- def to_frame(self) :- red_intensity = 255 * (self.win_strike / 10) # 100% red for 10 victories and more+ def to_frame(self):+ red_intensity = 255 * (+ self.win_strike / 10+ ) # 100% red for 10 victories and morered_intensity = min(red_intensity, 255)# A 200x100 image with red more or less intense based on number of victories in a row@@ -52,5 +54,5 @@ world = CoinFlipWorld(fps=5)myclip = UpdatedVideoClip(world=world, duration=10)# We will set FPS to same as world, if we was to use a different FPS, the lowest from world.fps and our write_videofile fps param-# will be the real visible fps-myclip.write_videofile("result.mp4", fps=5)\ No newline at end of file+# will be the real visible fps+myclip.write_videofile("result.mp4", fps=5)diff --git a/docs/_static/code/user_guide/loading/VideoClip.py b/docs/_static/code/user_guide/loading/VideoClip.pyindex 73bd8959..6d548530 100644--- a/docs/_static/code/user_guide/loading/VideoClip.py+++ b/docs/_static/code/user_guide/loading/VideoClip.py@@ -6,9 +6,10 @@ import mathWIDTH, HEIGHT = (128, 128)RED = (255, 0, 0)+def make_frame(t):- frequency = 1 # One pulse per second- coef = (0.5 * (1 + math.sin(2 * math.pi * frequency * t))) # radius varies over time+ frequency = 1 # One pulse per second+ coef = 0.5 * (1 + math.sin(2 * math.pi * frequency * t)) # radius varies over timeradius = WIDTH * coefx1 = WIDTH / 2 - radius / 2@@ -16,11 +17,16 @@ def make_frame(t):x2 = WIDTH / 2 + radius / 2y2 = HEIGHT / 2 + radius / 2- img = Image.new('RGB', (WIDTH, HEIGHT))+ img = Image.new("RGB", (WIDTH, HEIGHT))draw = ImageDraw.Draw(img)draw.ellipse((x1, y1, x2, y2), fill=RED)-+return np.array(img) # returns a 8-bit RGB array-clip = VideoClip(make_frame, duration=2) # we define a 2s duration for the clip to be able to render it later-clip.write_gif("circle.gif", fps=15) # we must set a framerate because VideoClip have no framerate by default\ No newline at end of file++clip = VideoClip(+ make_frame, duration=2+) # we define a 2s duration for the clip to be able to render it later+clip.write_gif(+ "circle.gif", fps=15+) # we must set a framerate because VideoClip have no framerate by defaultdiff --git a/docs/_static/code/user_guide/loading/VideoFileClip.py b/docs/_static/code/user_guide/loading/VideoFileClip.pyindex 2b63a69c..f798b687 100644--- a/docs/_static/code/user_guide/loading/VideoFileClip.py+++ b/docs/_static/code/user_guide/loading/VideoFileClip.py@@ -3,11 +3,13 @@ from moviepy import *myclip = VideoFileClip("example.mp4")# video file clips already have fps and duration-print('Clip duration: {}'.format(myclip.duration))-print('Clip fps: {}'.format(myclip.fps))+print("Clip duration: {}".format(myclip.duration))+print("Clip fps: {}".format(myclip.fps))-myclip = myclip.with_subclip(0.5, 2) # Cutting the clip between 0.5 and 2 secs.-print('Clip duration: {}'.format(myclip.duration)) # Cuting will update duration-print('Clip fps: {}'.format(myclip.fps)) # and keep fps+myclip = myclip.with_subclip(0.5, 2) # Cutting the clip between 0.5 and 2 secs.+print("Clip duration: {}".format(myclip.duration)) # Cuting will update duration+print("Clip fps: {}".format(myclip.fps)) # and keep fps-myclip.write_videofile("result.mp4") # the output video will be 1.5 sec long and use original fps\ No newline at end of file+myclip.write_videofile(+ "result.mp4"+) # the output video will be 1.5 sec long and use original fpsdiff --git a/docs/_static/code/user_guide/loading/closing.py b/docs/_static/code/user_guide/loading/closing.pyindex 352e15e1..c8d818ff 100644--- a/docs/_static/code/user_guide/loading/closing.py+++ b/docs/_static/code/user_guide/loading/closing.py@@ -4,5 +4,5 @@ try:with AudioFileClip("example.wav") as clip:raise Exception("Let's simulate an exception")except Exception as e:- print('{}'.format(e))-# clip.close() is implicitly called, so the lock on my_audiofile.mp3 file is immediately released.\ No newline at end of file+ print("{}".format(e))+# clip.close() is implicitly called, so the lock on my_audiofile.mp3 file is immediately released.diff --git a/docs/_static/code/user_guide/loading/loading.py b/docs/_static/code/user_guide/loading/loading.pyindex b32c3e0b..4eb9b780 100644--- a/docs/_static/code/user_guide/loading/loading.py+++ b/docs/_static/code/user_guide/loading/loading.py@@ -2,22 +2,34 @@ from moviepy import *import numpy as np# Define some constants for later use-black = (255, 255, 255) # RGB for black+black = (255, 255, 255) # RGB for black# Random noise image of 200x100-make_frame = lambda t: np.random.randint(low=0, high=255, size=(100, 200, 3))+make_frame = lambda t: np.random.randint(low=0, high=255, size=(100, 200, 3))# A note by producing a sinewave of 440 Hzmake_frame_audio = lambda t: np.sin(440 * 2 * np.pi * t)# Now lets see how to load different type of resources !# VIDEO CLIPS`-clip = VideoClip(make_frame, duration=5) # for custom animations, where make_frame is a function returning an image as numpy array for a given time-clip = VideoFileClip("example.mp4") # for videos-clip = ImageSequenceClip('example_img_dir', fps=24) # for a list or directory of images to be used as a video sequence-clip = ImageClip("example.png") # For a picture-clip = TextClip(font="./example.ttf", text="Hello!", font_size=70, color="black") # To create the image of a text-clip = ColorClip(size=(460,380), color=black) # a clip of a single unified color, where color is a RGB tuple/array/list+clip = VideoClip(+ make_frame, duration=5+) # for custom animations, where make_frame is a function returning an image as numpy array for a given time+clip = VideoFileClip("example.mp4") # for videos+clip = ImageSequenceClip(+ "example_img_dir", fps=24+) # for a list or directory of images to be used as a video sequence+clip = ImageClip("example.png") # For a picture+clip = TextClip(+ font="./example.ttf", text="Hello!", font_size=70, color="black"+) # To create the image of a text+clip = ColorClip(+ size=(460, 380), color=black+) # a clip of a single unified color, where color is a RGB tuple/array/list# AUDIO CLIPS-clip = AudioFileClip("example.wav") # for audio files, but also videos where you only want the keep the audio track-clip = AudioClip(make_frame_audio, duration=3) # for custom audio, where make_frame is a function returning a float (or tuple for stereo) for a given time\ No newline at end of file+clip = AudioFileClip(+ "example.wav"+) # for audio files, but also videos where you only want the keep the audio track+clip = AudioClip(+ make_frame_audio, duration=3+) # for custom audio, where make_frame is a function returning a float (or tuple for stereo) for a given timediff --git a/docs/_static/code/user_guide/loading/masks.py b/docs/_static/code/user_guide/loading/masks.pyindex 6caa1009..1ebc002e 100644--- a/docs/_static/code/user_guide/loading/masks.py+++ b/docs/_static/code/user_guide/loading/masks.py@@ -2,15 +2,15 @@ from moviepy import *import numpy as np# Random RGB noise image of 200x100-makeframe = lambda t : np.random.rand(100, 200)+makeframe = lambda t: np.random.rand(100, 200)-# To define the VideoClip as a mask, just pass parameter is_mask as True-maskclip1 = VideoClip(makeframe, duration=4, is_mask=True) # A random noise mask-maskclip2 = ImageClip("example_mask.jpg", is_mask=True) # A fixed mask as jpeg-maskclip3 = VideoFileClip("example_mask.mp4", is_mask=True) # A video as a mask+# To define the VideoClip as a mask, just pass parameter is_mask as True+maskclip1 = VideoClip(makeframe, duration=4, is_mask=True) # A random noise mask+maskclip2 = ImageClip("example_mask.jpg", is_mask=True) # A fixed mask as jpeg+maskclip3 = VideoFileClip("example_mask.mp4", is_mask=True) # A video as a mask-# Load our basic clip, resize to 200x100 and apply each mask+# Load our basic clip, resize to 200x100 and apply each maskclip = VideoFileClip("example.mp4")clip_masked1 = clip.with_mask(maskclip1)clip_masked2 = clip.with_mask(maskclip2)-clip_masked3 = clip.with_mask(maskclip3)\ No newline at end of file+clip_masked3 = clip.with_mask(maskclip3)diff --git a/docs/_static/code/user_guide/rendering/display_in_notebook.py b/docs/_static/code/user_guide/rendering/display_in_notebook.pyindex f9630958..5ed5829e 100644--- a/docs/_static/code/user_guide/rendering/display_in_notebook.py+++ b/docs/_static/code/user_guide/rendering/display_in_notebook.py@@ -4,14 +4,14 @@ from moviepy import *# ... some jupyter specifics stuff# ...-my_video_clip = VideoFileClip('./example.mp4')-my_image_clip = ImageClip('./example.png')-my_audio_clip = AudioFileClip('./example.wav')+my_video_clip = VideoFileClip("./example.mp4")+my_image_clip = ImageClip("./example.png")+my_audio_clip = AudioFileClip("./example.wav")# We can show any type of clip-my_video_clip.display_in_notebook() # embeds a video-my_image_clip.display_in_notebook() # embeds an image-my_audio_clip.display_in_notebook() # embeds a sound+my_video_clip.display_in_notebook() # embeds a video+my_image_clip.display_in_notebook() # embeds an image+my_audio_clip.display_in_notebook() # embeds a sound# We can display only a snaphot of a videomy_video_clip.display_in_notebook(t=1)@@ -20,6 +20,6 @@ my_video_clip.display_in_notebook(t=1)# For instance, if the clip is too big, we can set widthmy_video_clip.display_in_notebook(width=400)-# We can also make it loop, for example to check if a GIF is+# We can also make it loop, for example to check if a GIF is# looping as expectedmy_video_clip.display_in_notebook(autoplay=1, loop=1)diff --git a/docs/_static/code/user_guide/rendering/preview.py b/docs/_static/code/user_guide/rendering/preview.pyindex 02da0e2c..be7ff92f 100644--- a/docs/_static/code/user_guide/rendering/preview.py+++ b/docs/_static/code/user_guide/rendering/preview.py@@ -1,6 +1,6 @@from moviepy import *-myclip = VideoFileClip('./example.mp4').with_subclip(0, 1) # Keep only 0 to 1 sec+myclip = VideoFileClip("./example.mp4").with_subclip(0, 1) # Keep only 0 to 1 sec# We preview our clip as a video, inheriting FPS and audio of the original clipmyclip.preview()diff --git a/docs/_static/code/user_guide/rendering/save_frame.py b/docs/_static/code/user_guide/rendering/save_frame.pyindex 4c16c9d2..89a26512 100644--- a/docs/_static/code/user_guide/rendering/save_frame.py+++ b/docs/_static/code/user_guide/rendering/save_frame.py@@ -2,4 +2,4 @@ from moviepy import *# We load all the clips we want to composemyclip = VideoFileClip("example.mp4")-myclip.save_frame("result.png", t=1) # Save frame at 1 sec+myclip.save_frame("result.png", t=1) # Save frame at 1 secdiff --git a/docs/_static/code/user_guide/rendering/show.py b/docs/_static/code/user_guide/rendering/show.pyindex 9caca29f..f4959b05 100644--- a/docs/_static/code/user_guide/rendering/show.py+++ b/docs/_static/code/user_guide/rendering/show.py@@ -1,6 +1,6 @@from moviepy import *-myclip = VideoFileClip('./example.mp4')+myclip = VideoFileClip("./example.mp4")# We show the first frame of our clipmyclip.show()diff --git a/docs/_static/code/user_guide/rendering/write_gif.py b/docs/_static/code/user_guide/rendering/write_gif.pyindex 14fb4bbb..8f28aa4b 100644--- a/docs/_static/code/user_guide/rendering/write_gif.py+++ b/docs/_static/code/user_guide/rendering/write_gif.py@@ -6,4 +6,4 @@ myclip = VideoFileClip("example.mp4").with_subclip(0, 2)myclip.write_gif("result.gif")# Here we save as GIF, but we set the FPS of our GIF at 10-myclip.write_gif('result.gif', fps=10)\ No newline at end of file+myclip.write_gif("result.gif", fps=10)diff --git a/docs/_static/code/user_guide/rendering/write_images_sequence.py b/docs/_static/code/user_guide/rendering/write_images_sequence.pyindex c0cc5b1f..55900c45 100644--- a/docs/_static/code/user_guide/rendering/write_images_sequence.py+++ b/docs/_static/code/user_guide/rendering/write_images_sequence.py@@ -4,7 +4,7 @@ import osmyclip = VideoFileClip("example.mp4")# Here we just save in dir output with filename being his index (start at 0, then +1 for each frame)-os.mkdir('./output')+os.mkdir("./output")myclip.write_images_sequence("./output/%d.jpg")# We set the FPS of our GIF at 10, and we leftpad name with 0 up to 4 digitsdiff --git a/docs/_static/code/user_guide/rendering/write_videofile.py b/docs/_static/code/user_guide/rendering/write_videofile.pyindex 288f5023..e42538a6 100644--- a/docs/_static/code/user_guide/rendering/write_videofile.py+++ b/docs/_static/code/user_guide/rendering/write_videofile.py@@ -2,7 +2,14 @@ from moviepy import *# We load all the clips we want to composebackground = VideoFileClip("long_examples/example2.mp4").with_subclip(0, 10)-title = TextClip("./example.ttf", text="Big Buck Bunny", font_size=80, color="#fff", text_align="center", duration=3).with_position(("center", "center"))+title = TextClip(+ "./example.ttf",+ text="Big Buck Bunny",+ font_size=80,+ color="#fff",+ text_align="center",+ duration=3,+).with_position(("center", "center"))# We make our final clip through compositionfinal_clip = CompositeVideoClip([background, title])@@ -16,8 +23,10 @@ final_clip.write_videofile("result.mp4")final_clip.write_videofile("result24fps.mp4", fps=24)# Now we save as WEBM instead, and we want tu use codec libvpx-vp9 (usefull when mp4 + transparency).-# We also want ffmpeg compression optimisation as minimal as possible. This will not change+# We also want ffmpeg compression optimisation as minimal as possible. This will not change# the video quality and it will decrease time for encoding, but increase final file size a lot.# Finally, we want ffmpeg to use 4 threads for video encoding. You should probably leave that# to default, as ffmpeg is already quite good at using the best setting on his own.-final_clip.write_videofile("result.webm", codec="libvpx-vp9", fps=24, preset="ultrafast", threads=4)\ No newline at end of file+final_clip.write_videofile(+ "result.webm", codec="libvpx-vp9", fps=24, preset="ultrafast", threads=4+)diff --git a/docs/_static/code/user_guide/rendering/write_videofile_duration.py b/docs/_static/code/user_guide/rendering/write_videofile_duration.pyindex a3945fe2..99086016 100644--- a/docs/_static/code/user_guide/rendering/write_videofile_duration.py+++ b/docs/_static/code/user_guide/rendering/write_videofile_duration.py@@ -1,13 +1,13 @@from moviepy import *# By default an ImageClip has no duration-my_clip = ImageClip("example.png")+my_clip = ImageClip("example.png")-try :+try:# This will fail! We cannot write a clip with no duration!- my_clip.write_videofile("result.mp4")-except :- print('Cannot write a video without duration')+ my_clip.write_videofile("result.mp4")+except:+ print("Cannot write a video without duration")# By calling with_duration on our clip, we fix the problem! We also need to set fps-my_clip.with_duration(2).write_videofile("result.mp4", fps=1)\ No newline at end of file+my_clip.with_duration(2).write_videofile("result.mp4", fps=1)diff --git a/docs/conf.py b/docs/conf.pyindex a794d137..f63da772 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -24,13 +24,10 @@ extensions = ["sphinx.ext.autodoc","sphinx.ext.autosummary","sphinx.ext.napoleon",-"sphinx_design",-"sphinx.ext.coverage","sphinx.ext.todo","sphinx.ext.viewcode",-"sphinx.ext.autosectionlabel",]@@ -109,7 +106,7 @@ html_theme = "pydata_sphinx_theme" # formerly 'kr'# Theme options are theme-specific and customize the look and feel of a theme# further. For a list of options available for each theme, see the# documentation.-v2_page = 'https://zulko.github.io/moviepy/getting_started/updating_to_v2.html'+v2_page = "https://zulko.github.io/moviepy/getting_started/updating_to_v2.html"html_theme_options = {"use_edit_page_button": True,"icon_links": [@@ -124,7 +121,9 @@ html_theme_options = {"type": "fontawesome",}],- "announcement": '<p>MoviePy just released v2.0 introducing breaking changes, see <a href="{}">"Updating from v1.X to v2.X"</a> for more info.</p>'.format(v2_page),+ "announcement": '<p>MoviePy v2.0 have introduced breaking changes, see <a href="{}">"Updating from v1.X to v2.X"</a> for more info.</p>'.format(+ v2_page+ ),}html_context = {@@ -159,7 +158,7 @@ html_logo = "_static/medias/logo_small.jpeg"html_static_path = ["_static"]html_css_files = [- 'moviepy.css',+ "moviepy.css",]# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,diff --git a/docs/developer_guide/contribution_guidelines.rst b/docs/developer_guide/contribution_guidelines.rstnew file mode 100644index 00000000..1206e1c1--- /dev/null+++ b/docs/developer_guide/contribution_guidelines.rst@@ -0,0 +1,68 @@+.. _contribution_guidelines:++MoviePy's Contribution Guidelines+=================================++Communication on GitHub+-----------------------++- Keep messages on GitHub issues and pull requests on-topic and to the point. Be aware that each comment triggers a notification which gets sent out to a number of people.+ - Opinions are OK.+ - For longer or more in-depth discussions, use the `MoviePy Gitter <https://gitter.im/Movie-py>`_. If these discussions lead to a decision, like a merge/reject, please leave a message on the relevant MoviePy issue to document the outcome of the discussion/the reason for the decision.+- Do not push any commit that changes the API without prior discussion.++Preparing for development+-------------------------++- Fork the official MoviePy repository to your own GitHub account:+ Use the "Fork" button in the top right corner of the GitHub interface while viewing `the official MoviePy <https://github.com/Zulko/moviepy>`_ repository.+- Use your fork as the basis for cloning the repository to your local machine: ``$ git clone URL_TO_YOUR_FORK``+ You can get the appropriate URL (SSH- or HTTPS-based) by using the green "Code" button located at the top right of the repository view while looking at your fork. By default, Git refers to any remote you clone from – i.e. in this case your fork on GitHub – as ``origin``.+- Enter your local clone and add the official MoviePy repository as a second remote, with alias ``upstream``:+ ``$ git remote add upstream [email protected]:Zulko/moviepy.git`` (using SSL) _or_+ ``$ git remote add upstream https://github.com/Zulko/moviepy.git`` (using HTTPS).+- Install the library inside a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ with all dependencies included using ``$ pip install -e ".[optional,doc,test,lint]"``+- Configure pre-commit hooks running ``$ pre-commit install``++Coding conventions, code quality+--------------------------------++- Respect `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ conventions.+- Add just the "right" amount of comments. Try to write auto-documented code with very explicit variable names.+- If you introduce new functionality or fix a bug, document it in the docstring or with code comments.+- MoviePy's team adopted `pre-commit <https://pre-commit.com/>`_ to run code checks using black, flake8 and isort, so make sure that you've configured the pre-commit hooks with ``pre-commit install``.++Standard contribution workflow+------------------------------++Local development+~~~~~~~~~~~~~~~~~++- Keep your local ``master`` branch up-to-date with the official repo's master by periodically fetching/pulling it:+ ``$ git pull upstream master``+- Never make changes on ``master`` directly, but branch off into separate develop branches:+ ``$ git checkout --branch YOUR_DEVELOP_BRANCH``+ Ideally, these are given names which function as keywords for what you are working on, and are prefixed with ``fix_`` (for bug fixes), ``feature_`` or something similarly appropriate and descriptive.+- Base any changes you submit on the most recent ``master``.++More detailed explanation of the last point:++It is likely that the official repo's ``master`` branch will move on (get updated, have other PRs merged into it) while you are working on your changes. Before creating a pull request, you will have to make sure your changes are not based on outdated code. For this reason, it makes sense to avoid falling "too much behind" while developing by rebasing your local ``master`` branch at intervals. Make sure your ``master`` branch is in sync with the official ``master`` branch (as per the first point), then, while checked into your develop branch, run: ``$ git rebase master``++If you **haven't rebased before**, make sure to **familiarise yourself** with the concept.++Submitting Pull Requests+~~~~~~~~~~~~~~~~~~~~~~~~++You do not have to have finished your feature or bug fix before submitting a PR; just mention that it still is a work in progress.++Before submitting PRs:++- run the test suite over your code to expose any problems: ``$ pytest``+- push your local develop branch to your GitHub fork ``$ git push origin YOUR_DEVELOP_BRANCH``++When you now look at your forked repo on your GitHub account, you will see GitHub suggest branches for sending pull requests to the official ``Zulko/moviepy`` repository.++Once you open a PR, you will be presented with a template which you are asked to fill out. You are encouraged to add any additional information which helps provide further context to your changes, and to link to any issues or PRs which your pull request references or is informed by.++On submitting your PR, an automated test suite runs over your submission, which might take a few minutes to complete. In a next step, a MoviePy maintainer will review your code and, if necessary, help you to get it merge-ready.diff --git a/docs/developer_guide/developers_install.rst b/docs/developer_guide/developers_install.rstnew file mode 100644index 00000000..d16d88cb--- /dev/null+++ b/docs/developer_guide/developers_install.rst@@ -0,0 +1,51 @@+.. _developers_install:++Installation for MoviePy developers+======================================++.. warning::+ This part is only destined to people who want to build the MoviePy documentation by themself, or to contribute to MoviePy, normal user dont need it.++In addition to MoviePy main libraries, MoviePy developers will also need to install additional libraries to be able to run MoviePy tests and build the MoviePy documentation.++Libraries for documentation+-----------------------------++You can install the libraries required to build documentation with:++.. code:: bash++ $ (sudo) pip install moviepy[doc]++Once libraries installed you can build the documentation with:++.. code:: bash++ $ python setup.py build_docs+++Libraries for testing and linting+-------------------------------------++You can install the libraries required for testing and linting with:++.. code:: bash++ $ (sudo) pip install moviepy[test]+ $ (sudo) pip install moviepy[lint]++Once libraries installed you can test with:++.. code:: bash++ $ python -m pytest++And you can lint with :++.. code:: bash++ $ python -m black .++++diff --git a/docs/developer_guide/index.rst b/docs/developer_guide/index.rstindex 659d55af..774c2e44 100644--- a/docs/developer_guide/index.rst+++ b/docs/developer_guide/index.rst@@ -1,68 +1,13 @@.. _developer_guide:--MoviePy's Contribution Guidelines-=================================-Communication on GitHub-------------------------- Keep messages on GitHub issues and pull requests on-topic and to the point. Be aware that each comment triggers a notification which gets sent out to a number of people.- - Opinions are OK.- - For longer or more in-depth discussions, use the `MoviePy Gitter <https://gitter.im/Movie-py>`_. If these discussions lead to a decision, like a merge/reject, please leave a message on the relevant MoviePy issue to document the outcome of the discussion/the reason for the decision.-- Do not push any commit that changes the API without prior discussion.--Preparing for development----------------------------- Fork the official MoviePy repository to your own GitHub account:- Use the "Fork" button in the top right corner of the GitHub interface while viewing `the official MoviePy <https://github.com/Zulko/moviepy>`_ repository.-- Use your fork as the basis for cloning the repository to your local machine: ``$ git clone URL_TO_YOUR_FORK``- You can get the appropriate URL (SSH- or HTTPS-based) by using the green "Code" button located at the top right of the repository view while looking at your fork. By default, Git refers to any remote you clone from – i.e. in this case your fork on GitHub – as ``origin``.-- Enter your local clone and add the official MoviePy repository as a second remote, with alias ``upstream``:- ``$ git remote add upstream [email protected]:Zulko/moviepy.git`` (using SSL) _or_- ``$ git remote add upstream https://github.com/Zulko/moviepy.git`` (using HTTPS).-- Install the library inside a `virtual environment <https://docs.python.org/3/tutorial/venv.html>`_ with all dependencies included using ``$ pip install -e ".[optional,doc,test,lint]"``-- Configure pre-commit hooks running ``$ pre-commit install``--Coding conventions, code quality------------------------------------ Respect `PEP8 <https://www.python.org/dev/peps/pep-0008/>`_ conventions.-- Add just the "right" amount of comments. Try to write auto-documented code with very explicit variable names.-- If you introduce new functionality or fix a bug, document it in the docstring or with code comments.-- MoviePy's team adopted `pre-commit <https://pre-commit.com/>`_ to run code checks using black, flake8 and isort, so make sure that you've configured the pre-commit hooks with ``pre-commit install``.--Standard contribution workflow+The MoviePy Developers Guide-------------------------------Local development-~~~~~~~~~~~~~~~~~--- Keep your local ``master`` branch up-to-date with the official repo's master by periodically fetching/pulling it:- ``$ git pull upstream master``-- Never make changes on ``master`` directly, but branch off into separate develop branches:- ``$ git checkout --branch YOUR_DEVELOP_BRANCH``- Ideally, these are given names which function as keywords for what you are working on, and are prefixed with ``fix_`` (for bug fixes), ``feature_`` or something similarly appropriate and descriptive.-- Base any changes you submit on the most recent ``master``.--More detailed explanation of the last point:--It is likely that the official repo's ``master`` branch will move on (get updated, have other PRs merged into it) while you are working on your changes. Before creating a pull request, you will have to make sure your changes are not based on outdated code. For this reason, it makes sense to avoid falling "too much behind" while developing by rebasing your local ``master`` branch at intervals. Make sure your ``master`` branch is in sync with the official ``master`` branch (as per the first point), then, while checked into your develop branch, run: ``$ git rebase master``--If you **haven't rebased before**, make sure to **familiarise yourself** with the concept.--Submitting Pull Requests-~~~~~~~~~~~~~~~~~~~~~~~~--You do not have to have finished your feature or bug fix before submitting a PR; just mention that it still is a work in progress.--Before submitting PRs:--- run the test suite over your code to expose any problems: ``$ pytest``-- push your local develop branch to your GitHub fork ``$ git push origin YOUR_DEVELOP_BRANCH``--When you now look at your forked repo on your GitHub account, you will see GitHub suggest branches for sending pull requests to the official ``Zulko/moviepy`` repository.--Once you open a PR, you will be presented with a template which you are asked to fill out. You are encouraged to add any additional information which helps provide further context to your changes, and to link to any issues or PRs which your pull request references or is informed by.+The Developers Guide covers most of the things people wanting to participate to MoviePy development need to know.-On submitting your PR, an automated test suite runs over your submission, which might take a few minutes to complete. In a next step, a MoviePy maintainer will review your code and, if necessary, help you to get it merge-ready.+.. toctree::+ :maxdepth: 1++ developers_install+ contribution_guidelinesdiff --git a/docs/getting_started/install.rst b/docs/getting_started/install.rstindex 1da619fb..d4b03d31 100644--- a/docs/getting_started/install.rst+++ b/docs/getting_started/install.rst@@ -25,7 +25,6 @@ You do need to worry ``ffplay`` if you plan on using video/audio previewing thoumake sure it is accessible to Python, or look how to set a custom path (see below).-Define custom paths to binaries~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@@ -84,9 +83,6 @@ To test if FFmpeg and FFplay are found by MoviePy, in a Python console, you can>>> from moviepy.config import check>>> check()-.. _ffmpeg: https://www.ffmpeg.org/download.html-.. _imageio: https://imageio.github.io/--+.. _ffmpeg: https://www.ffmpeg.org/download.htmldiff --git a/docs/getting_started/moviepy_10_minutes.rst b/docs/getting_started/moviepy_10_minutes.rstindex e72a65a2..143f6912 100644--- a/docs/getting_started/moviepy_10_minutes.rst+++ b/docs/getting_started/moviepy_10_minutes.rst@@ -60,7 +60,7 @@ This is a very classic task, so lets turn our main clip into multiple subclips:.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 13-23+ :lines: 13-25Here, we use the ``with_subclip`` method to extract specific scenes from the main video. We provide the start and end times (in seconds or as text with format ``HH:MM:SS.µS``) for each scene.@@ -80,7 +80,7 @@ To do so using MoviePy, you can utilize the ``preview()`` function available for.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 26-36+ :lines: 28-38by using the preview, you may have noticed that our clips not only contain video, but also audio. This is because when loading a video, you not only load the image, but also the audio tracks that are turned into :py:class:`~moviepy.audio.AudioClip.AudioClip` andadded to your video clip.@@ -98,7 +98,7 @@ To do so, we are going to use the ``with_cutout`` method to remove a portion of.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 39-52+ :lines: 41-54In that particular case we have used the ``with_cutout``, but this is only one of the many clip manipulation method starting by ``with_*``, we will see a few othersin this tutorial, but we will miss a lot more, if you want an exhaustive list, go see :ref:`reference_manual`.@@ -119,7 +119,7 @@ We also want to create image clips, for the "Big Buck Bunny" logo and the "Made.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 54-68+ :lines: 56-82As you may see, ``ImageClip`` are quite simple, but ``TextClip`` are rather complicated objects, do not hesitate to go and have a deeper look at the arguments it accept.@@ -127,11 +127,6 @@ As you may see, ``ImageClip`` are quite simple, but ``TextClip`` are rather compIn our example we have used the ``resized()`` method to resize our image clips. This method works just like any ``with_*`` method, but because resizing is such a commontask, the name have been shortened to ``resized()``. The same is true for ``cropped()`` and ``rotated()``.-.. code-block:: python-- slow_motion_video = trimmed_video.fx(vfx.speedx, 0.5) # Slow down the video by 2x- final_video = slow_motion_video.crossfadein(1) # Add a crossfade transition-Feel free to experiment with different effects and transitions to achieve the desired trailer effect.@@ -145,7 +140,7 @@ To fix that, we need to say when a clip should start and stop in the final clip... literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 71-89+ :lines: 85-111.. note::By default all clips have a startpoint at ``0``, if a clip has no duration but you set the ``endtime``, then the duration will be calculated for you. The reciprocity is also true.@@ -165,7 +160,7 @@ So, MoviePy offer a special kind of :py:class:`~moviepy.video.VideoClip.VideoCli.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 92-99+ :lines: 114-136Step 8: Positionning our clips@@ -182,7 +177,7 @@ To fix this, we simply have to define the position of our clips in the compositi.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 102-122+ :lines: 139-174.. note::The position is a tuple with horizontal and vertical position. You can give them as pixels, as strings (``top``, ``left``, ``right``, ``bottom``, ``center``) and even as percentage by providing@@ -211,7 +206,7 @@ In our case, we will add simple fade-in/out and cross-fade-in/out transitions be.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 125-160+ :lines: 177-239Well, this is a lot nicer! For this tutorial we want to keep things simple, so we mostly used transitions, but you can find a lot a differents effects, and even create your own.For a deeper presentation, see :py:mod:`moviepy.video.fx`, :py:mod:`moviepy.audio.fx` and :ref:`create_effects`.@@ -245,7 +240,7 @@ The "apply to all frames" part is done by the ``image_transform`` method. This m.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 163-202+ :lines: 242-283Step 11: Rendering the final clip to a file@@ -259,7 +254,7 @@ Again, we will keep things simple and just do video rendering whithout much twea.. literalinclude:: /_static/code/getting_started/moviepy_10_minutes/trailer.py:language: python- :lines: 205-211+ :lines: 286-307Conclusiondiff --git a/moviepy/tools.py b/moviepy/tools.pyindex 14cb4c6d..97706c98 100644--- a/moviepy/tools.py+++ b/moviepy/tools.py@@ -220,12 +220,12 @@ def no_display_available() -> bool:It probably works for SunOS, AIX and CYGWIN"""system = platform.system()- if system in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS', 'AIX'] :- if not 'DISPLAY' in os.environ and not 'WAYLAND_DISPLAY' in os.environ :+ if system in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS", "AIX"]:+ if not "DISPLAY" in os.environ and not "WAYLAND_DISPLAY" in os.environ:return True-- if 'CYGWIN_NT' in system :- if not 'DISPLAY' in os.environ and not 'WAYLAND_DISPLAY' in os.environ :++ if "CYGWIN_NT" in system:+ if not "DISPLAY" in os.environ and not "WAYLAND_DISPLAY" in os.environ:return True- return False\ No newline at end of file+ return Falsediff --git a/setup.py b/setup.pyindex 222f285d..d18eab23 100644--- a/setup.py+++ b/setup.py@@ -4,6 +4,7 @@import sysfrom pathlib import Pathimport runpy+try:from setuptools import find_packages, setupfrom setuptools.command.test import test as TestCommand@@ -21,7 +22,8 @@ except ImportError:)-__version__=runpy.run_path('moviepy/version.py').get('__version__')+__version__ = runpy.run_path("moviepy/version.py").get("__version__")+class PyTest(TestCommand):"""Handle test execution from setup."""@@ -75,7 +77,7 @@ requires = ["numpy>=1.25.0","proglog<=1.0.0","python-dotenv>=0.10",- "pillow>=9.2.0,<11.0", # We are good at least up to v11+ "pillow>=9.2.0,<11.0", # We are good at least up to v11]doc_reqs = [diff --git a/tests/conftest.py b/tests/conftest.pyindex 5a0b937f..1b6a86af 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -178,4 +178,4 @@ def moviepy_modules():@pytest.fixturedef functions_with_decorator_defined():- return get_functions_with_decorator_defined\ No newline at end of file+ return get_functions_with_decorator_defineddiff --git a/tests/test_SubtitlesClip.py b/tests/test_SubtitlesClip.pyindex 37a97406..e124e0fa 100644--- a/tests/test_SubtitlesClip.py+++ b/tests/test_SubtitlesClip.py@@ -4,7 +4,10 @@ import osimport pytest-from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip, concatenate_videoclips+from moviepy.video.compositing.CompositeVideoClip import (+ CompositeVideoClip,+ concatenate_videoclips,+)from moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitlesfrom moviepy.video.VideoClip import ColorClip, TextClipdiff --git a/tests/test_TextClip.py b/tests/test_TextClip.pyindex e218e1ca..609f124c 100644--- a/tests/test_TextClip.py+++ b/tests/test_TextClip.py@@ -8,6 +8,7 @@ import pytestfrom moviepy import *+def test_duration(util):clip = TextClip(text="hello world", size=(1280, 720), color="white", font=util.FONT)clip = clip.with_duration(5)@@ -61,9 +62,7 @@ def test_text_filename_arguments_consistence(util):"method", ("caption", "label"), ids=("method=caption", "method=label"))def test_no_text_nor_filename_arguments(method, util):- expected_error_msg = (- "^No text nor filename provided$"- )+ expected_error_msg = "^No text nor filename provided$"with pytest.raises(ValueError, match=expected_error_msg):TextClip(size=(20, 20),diff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.pyindex ec56d894..d4189f7f 100644--- a/tests/test_VideoClip.py+++ b/tests/test_VideoClip.py@@ -250,7 +250,9 @@ def test_with_layer():reversed_composite_clip = CompositeVideoClip([top_clip, bottom_clip])# Make sure that the order of clips makes no difference to the composite clip- assert composite_clip.with_subclip(0, 2) == reversed_composite_clip.with_subclip(0, 2)+ assert composite_clip.with_subclip(0, 2) == reversed_composite_clip.with_subclip(+ 0, 2+ )# Make sure that only the 'top' clip is keptassert top_clip.with_subclip(0, 2) == composite_clip.with_subclip(0, 2)diff --git a/tests/test_compositing.py b/tests/test_compositing.pyindex 615689ff..b94aecb3 100644--- a/tests/test_compositing.py+++ b/tests/test_compositing.py@@ -140,7 +140,9 @@ def test_slide_in():).with_fps(fps)for side in ["left", "right"]:- new_clip = CompositeVideoClip([clip.with_effects([vfx.SlideIn(duration, side)])])+ new_clip = CompositeVideoClip(+ [clip.with_effects([vfx.SlideIn(duration, side)])]+ )for t in np.arange(0, duration, duration / fps):n_reds, n_reds_expected = (0, int(t * 100))@@ -165,7 +167,9 @@ def test_slide_in():).with_fps(fps)for side in ["top", "bottom"]:- new_clip = CompositeVideoClip([clip.with_effects([vfx.SlideIn(duration, side)])])+ new_clip = CompositeVideoClip(+ [clip.with_effects([vfx.SlideIn(duration, side)])]+ )for t in np.arange(0, duration, duration / fps):n_reds, n_reds_expected = (0, int(t * 100))@@ -198,7 +202,9 @@ def test_slide_out():).with_fps(fps)for side in ["left", "right"]:- new_clip = CompositeVideoClip([clip.with_effects([vfx.SlideOut(duration, side)])])+ new_clip = CompositeVideoClip(+ [clip.with_effects([vfx.SlideOut(duration, side)])]+ )for t in np.arange(0, duration, duration / fps):n_reds, n_reds_expected = (0, round(11 - t * 100, 6))@@ -220,7 +226,9 @@ def test_slide_out():).with_fps(fps)for side in ["top", "bottom"]:- new_clip = CompositeVideoClip([clip.with_effects([vfx.SlideOut(duration, side)])])+ new_clip = CompositeVideoClip(+ [clip.with_effects([vfx.SlideOut(duration, side)])]+ )for t in np.arange(0, duration, duration / fps):n_reds, n_reds_expected = (0, round(11 - t * 100, 6))diff --git a/tests/test_doc_examples.py b/tests/test_doc_examples.pyindex 40ebf5b2..d688ad29 100644--- a/tests/test_doc_examples.py+++ b/tests/test_doc_examples.py@@ -13,6 +13,7 @@ import osfrom moviepy.tools import no_display_available+@contextmanagerdef cwd(path):oldpwd = os.getcwd()@@ -22,32 +23,35 @@ def cwd(path):finally:os.chdir(oldpwd)+# Dir for doc code examples to runDOC_EXAMPLES_DIR = "docs/_static/code"# List of examples script to ignore, mostly scripts that are too long-DOC_EXAMPLES_IGNORE = ['trailer.py', 'display_in_notebook.py']+DOC_EXAMPLES_IGNORE = ["trailer.py", "display_in_notebook.py"]# If no display, also remove all examples using previewif no_display_available():- DOC_EXAMPLES_IGNORE.append('preview.py')+ DOC_EXAMPLES_IGNORE.append("preview.py")-scripts = list(pathlib.Path(DOC_EXAMPLES_DIR).resolve().rglob('*.py'))-scripts = dict(zip(map(str, scripts), scripts)) # This make test name more readable+scripts = list(pathlib.Path(DOC_EXAMPLES_DIR).resolve().rglob("*.py"))+scripts = dict(zip(map(str, scripts), scripts)) # This make test name more readable[email protected]('script', scripts)+[email protected]("script", scripts)def test_doc_examples(util, tmp_path, script):- print('Try script: ', script)+ print("Try script: ", script)- if os.path.basename(script) in DOC_EXAMPLES_IGNORE :+ if os.path.basename(script) in DOC_EXAMPLES_IGNORE:return# Lets build a test dir with all medias needed to run our test inshutil.copytree(util.DOC_EXAMPLES_MEDIAS_DIR, os.path.join(tmp_path, "doc_tests"))test_dir = os.path.join(tmp_path, "doc_tests")- with cwd(test_dir) :+ with cwd(test_dir):runpy.run_path(script)+if __name__ == "__main__":pytest.main()diff --git a/tests/test_examples.py b/tests/test_examples.pydeleted file mode 100644index 2c3fe228..00000000--- a/tests/test_examples.py+++ /dev/null@@ -1,43 +0,0 @@-"""MoviePy examples tests."""--import os--import numpy as np--import pytest--from moviepy.video.io.bindings import mplfig_to_npimage-from moviepy.video.VideoClip import VideoClip---try:- import matplotlib.pyplot-except ImportError:- matplotlib = None-else:- matplotlib = True--[email protected](not matplotlib, reason="no matplotlib")-def test_matplotlib_simple_example(util):- import matplotlib.pyplot as plt-- plt.switch_backend("Agg")-- x = np.linspace(-2, 2, 200)- duration = 0.5-- fig, ax = plt.subplots()-- def make_frame(t):- ax.clear()- ax.plot(x, np.sinc(x**2) + np.sin(x + 2 * np.pi / duration * t), lw=3)- ax.set_ylim(-1.5, 2.5)- return mplfig_to_npimage(fig)-- animation = VideoClip(make_frame, duration=duration)-- filename = os.path.join(util.TMP_DIR, "matplotlib.gif")- animation.write_gif(filename, fps=20)-- assert os.path.isfile(filename)diff --git a/tests/test_ffmpeg_writer.py b/tests/test_ffmpeg_writer.pyindex 57043c91..0985b61d 100644--- a/tests/test_ffmpeg_writer.py+++ b/tests/test_ffmpeg_writer.py@@ -213,13 +213,7 @@ def test_write_gif(util, clip_class, loop, with_mask):ColorClip((1, 1), color=1, is_mask=True).with_fps(fps).with_duration(0.3))- write_gif_with_imageio(- original_clip,- filename,- fps=fps,- logger=None,- loop=loop- )+ write_gif_with_imageio(original_clip, filename, fps=fps, logger=None, loop=loop)final_clip = VideoFileClip(filename)diff --git a/tests/test_fx.py b/tests/test_fx.pyindex 24815800..339e83fb 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -48,7 +48,9 @@ def test_blackwhite():# for each possible ``preserve_luminosity`` boolean argument valuefor preserve_luminosity in [True, False]:# default argument (``RGB=None``)- clip_bw = clip.with_effects([vfx.BlackAndWhite(preserve_luminosity=preserve_luminosity)])+ clip_bw = clip.with_effects(+ [vfx.BlackAndWhite(preserve_luminosity=preserve_luminosity)]+ )bitmap = clip_bw.to_bitmap()assert bitmap@@ -62,10 +64,14 @@ def test_blackwhite():assert char == row[0] # so are equal# custom random ``RGB`` argument- clip_bw_custom_rgb = clip.with_effects([vfx.BlackAndWhite(- RGB=(random.randint(0, 255), 0, 0),- preserve_luminosity=preserve_luminosity,- )])+ clip_bw_custom_rgb = clip.with_effects(+ [+ vfx.BlackAndWhite(+ RGB=(random.randint(0, 255), 0, 0),+ preserve_luminosity=preserve_luminosity,+ )+ ]+ )bitmap = clip_bw_custom_rgb.to_bitmap()for i, row in enumerate(bitmap[0]):for i2, char in enumerate(row):@@ -77,9 +83,13 @@ def test_blackwhite():assert char == row[1] and char == row[2]# ``RGB="CRT_phosphor"`` argument- clip_bw_crt_phosphor = clip.with_effects([vfx.BlackAndWhite(- RGB="CRT_phosphor", preserve_luminosity=preserve_luminosity- )])+ clip_bw_crt_phosphor = clip.with_effects(+ [+ vfx.BlackAndWhite(+ RGB="CRT_phosphor", preserve_luminosity=preserve_luminosity+ )+ ]+ )bitmap = clip_bw_crt_phosphor.to_bitmap()assert bitmapfor row in bitmap[0]:@@ -165,7 +175,9 @@ def test_fadein():target1 = BitmapClip([["I"], ["G"], ["B"]], color_dict=color_dict, fps=1)assert clip1 == target1- clip2 = clip.with_effects([vfx.FadeIn(1, initial_color=(255, 255, 255))]) # different initial color+ clip2 = clip.with_effects(+ [vfx.FadeIn(1, initial_color=(255, 255, 255))]+ ) # different initial colortarget2 = BitmapClip([["W"], ["G"], ["B"]], color_dict=color_dict, fps=1)assert clip2 == target2@@ -388,7 +400,9 @@ def test_make_loopable(util, video):clip1 = clip.with_effects([vfx.MakeLoopable(0.4)])# We need to set libvpx-vp9 because our test will produce transparency- clip1.write_videofile(os.path.join(util.TMP_DIR, "make_loopable1.webm"), codec="libvpx-vp9")+ clip1.write_videofile(+ os.path.join(util.TMP_DIR, "make_loopable1.webm"), codec="libvpx-vp9"+ )@pytest.mark.parametrize(@@ -492,14 +506,18 @@ def test_margin(ClipClass, margin_size, margins, color, expected_result):margins = [0, 0, 0, 0]left, right, top, bottom = margins- new_clip = clip.with_effects([vfx.Margin(- margin_size=margin_size,- left=left,- right=right,- top=top,- bottom=bottom,- color=color,- )])+ new_clip = clip.with_effects(+ [+ vfx.Margin(+ margin_size=margin_size,+ left=left,+ right=right,+ top=top,+ bottom=bottom,+ color=color,+ )+ ]+ )assert new_clip == BitmapClip(expected_result, fps=1)@@ -541,9 +559,13 @@ def test_mask_and(image_from, duration, color, mask_color, expected_color):# test ImageClip and np.ndarray types as mask argumentclip = ColorClip(color=color, size=clip_size).with_duration(duration)mask_clip = ColorClip(color=mask_color, size=clip.size)- masked_clip = clip.with_effects([vfx.MasksAnd(- mask_clip if image_from == "ImageClip" else mask_clip.get_frame(0)- )])+ masked_clip = clip.with_effects(+ [+ vfx.MasksAnd(+ mask_clip if image_from == "ImageClip" else mask_clip.get_frame(0)+ )+ ]+ )assert masked_clip.duration == clip.durationassert np.array_equal(masked_clip.get_frame(0)[0][0], np.array(expected_color))@@ -598,9 +620,13 @@ def test_mask_or(image_from, duration, color, mask_color, expected_color):# test ImageClip and np.ndarray types as mask argumentclip = ColorClip(color=color, size=clip_size).with_duration(duration)mask_clip = ColorClip(color=mask_color, size=clip.size)- masked_clip = clip.with_effects([vfx.MasksOr(- mask_clip if image_from == "ImageClip" else mask_clip.get_frame(0)- )])+ masked_clip = clip.with_effects(+ [+ vfx.MasksOr(+ mask_clip if image_from == "ImageClip" else mask_clip.get_frame(0)+ )+ ]+ )assert masked_clip.duration == clip.durationassert np.array_equal(masked_clip.get_frame(0)[0][0], np.array(expected_color))@@ -710,11 +736,8 @@ def test_painting():),),)-def test_resize(- apply_to_mask, size, duration, new_size, height, width-):- """Checks ``resize`` FX behaviours using all argument- """+def test_resize(apply_to_mask, size, duration, new_size, height, width):+ """Checks ``resize`` FX behaviours using all argument"""# build expected sizes (using `width` or `height` arguments will be proportional# to original size)if new_size:@@ -1168,11 +1191,15 @@ def test_multiply_volume_audioclip()clip_array = clip.to_soundarray()- clip_transformed = clip.with_effects([afx.MultiplyVolume(- factor,- start_time=start_time,- end_time=end_time,- )])+ clip_transformed = clip.with_effects(+ [+ afx.MultiplyVolume(+ factor,+ start_time=start_time,+ end_time=end_time,+ )+ ]+ )clip_transformed_array = clip_transformed.to_soundarray()assert len(clip_transformed_array)@@ -1255,11 +1282,19 @@ def test_multiply_volume_audioclip(def test_multiply_volume_videoclip():start_time, end_time = (0.1, 0.2)- clip = VideoFileClip("media/chaplin.mp4").with_subclip(0, 0.3).with_effects([afx.MultiplyVolume(- 0,- start_time=start_time,- end_time=end_time,- )])+ clip = (+ VideoFileClip("media/chaplin.mp4")+ .with_subclip(0, 0.3)+ .with_effects(+ [+ afx.MultiplyVolume(+ 0,+ start_time=start_time,+ end_time=end_time,+ )+ ]+ )+ )clip_soundarray = clip.audio.to_soundarray()assert len(clip_soundarray)@@ -1279,7 +1314,9 @@ def test_multiply_stereo_volume():# stereo muteclip_left_channel_muted = clip.with_effects([afx.MultiplyStereoVolume(left=0)])- clip_right_channel_muted = clip.with_effects([afx.MultiplyStereoVolume(right=0, left=2)])+ clip_right_channel_muted = clip.with_effects(+ [afx.MultiplyStereoVolume(right=0, left=2)]+ )left_channel_muted = clip_left_channel_muted.to_soundarray()[:, 0]right_channel_muted = clip_right_channel_muted.to_soundarray()[:, 1]@@ -1305,7 +1342,9 @@ def test_multiply_stereo_volume():# mono doubledmono_clip = AudioClip(sinus_wave, duration=1, fps=22050)- doubled_mono_clip = mono_clip.with_effects([afx.MultiplyStereoVolume(left=None, right=2)]) # using right+ doubled_mono_clip = mono_clip.with_effects(+ [afx.MultiplyStereoVolume(left=None, right=2)]+ ) # using rightmono_channel_doubled = doubled_mono_clip.to_soundarray()d_channel = mono_clip.to_soundarray() * 2assert np.array_equal(mono_channel_doubled, d_channel)@@ -1344,7 +1383,9 @@ def test_audio_delay(stereo_wave, duration, offset, n_repeats, decay):clip_array = clip.to_soundarray()# stereo delayed clip- delayed_clip = clip.with_effects([afx.AudioDelay(offset=offset, n_repeats=n_repeats, decay=decay)])+ delayed_clip = clip.with_effects(+ [afx.AudioDelay(offset=offset, n_repeats=n_repeats, decay=decay)]+ )delayed_clip_array = delayed_clip.to_soundarray()# size of chunks with audiosdiff --git a/tests/test_issues.py b/tests/test_issues.pyindex 5bbee443..5665480e 100644--- a/tests/test_issues.py+++ b/tests/test_issues.py@@ -232,7 +232,9 @@ def test_issue_334(util):tt = VideoFileClip("media/big_buck_bunny_0_30.webm").with_subclip(0, 3)# TODO: Setting mask here does not work:# .with_mask(maskclip).resize(size)])- final = CompositeVideoClip([tt, concatenated.with_position(posi).with_effects([vfx.Resize(size)])])+ final = CompositeVideoClip(+ [tt, concatenated.with_position(posi).with_effects([vfx.Resize(size)])]+ )final.duration = tt.durationfinal.write_videofile(os.path.join(util.TMP_DIR, "issue_334.mp4"), fps=10)@@ -242,16 +244,16 @@ def test_issue_354():clip.duration = 10crosstime = 1- fadecaption = clip.with_effects([vfx.CrossFadeIn(crosstime), vfx.CrossFadeOut(crosstime)])+ fadecaption = clip.with_effects(+ [vfx.CrossFadeIn(crosstime), vfx.CrossFadeOut(crosstime)]+ )CompositeVideoClip([clip, fadecaption]).close()def test_issue_359(util):with ColorClip((800, 600), color=(255, 0, 0)).with_duration(0.2) as video:video.fps = 30- video.write_gif(- filename=os.path.join(util.TMP_DIR, "issue_359.gif")- )+ video.write_gif(filename=os.path.join(util.TMP_DIR, "issue_359.gif"))def test_issue_407():diff --git a/tests/test_preview.py b/tests/test_preview.pydeleted file mode 100644index 98bf5e76..00000000--- a/tests/test_preview.py+++ /dev/null@@ -1,74 +0,0 @@-"""MoviePy editor tests."""--import importlib-import io-import sys-from contextlib import redirect_stdout--import pytest--from moviepy.audio.AudioClip import AudioClip-from moviepy.video.VideoClip import VideoClip---def test_preview_methods():- stdout = io.StringIO()- with redirect_stdout(stdout):- try:- preview_module = importlib.import_module("moviepy.video.io.preview")- assert preview_module.preview.__hash__() != VideoClip.preview.__hash__()- except ImportError:- editor_module = importlib.import_module("moviepy.editor")- with pytest.raises(ImportError) as exc:- VideoClip.preview(True)- assert str(exc.value) == "clip.preview requires Pygame installed"-- with pytest.raises(ImportError) as exc:- VideoClip.show(True)- assert str(exc.value) == "clip.show requires Pygame installed"-- with pytest.raises(ImportError) as exc:- AudioClip.preview(True)- assert str(exc.value) == "clip.preview requires Pygame installed"- else:- editor_module = importlib.import_module("moviepy.editor")- assert (- editor_module.VideoClip.preview.__hash__()- == preview_module.preview.__hash__()- )- finally:- if "moviepy.editor" in sys.modules:- del sys.modules["moviepy.editor"]-- try:- importlib.import_module("matplotlib.pyplot")- except ImportError:- editor_module = importlib.import_module("moviepy.editor")- with pytest.raises(ImportError) as exc:- editor_module.sliders()-- assert str(exc.value) == "sliders requires matplotlib installed"-- del sys.modules["moviepy.editor"]- else:- del sys.modules["matplotlib.pyplot"]-- del sys.modules["moviepy"]---def test__init__preview_methods():- moviepy_module = importlib.import_module("moviepy")-- with pytest.raises(ImportError) as exc:- moviepy_module.VideoClip.preview(True)- assert str(exc.value) == "clip.preview requires importing from moviepy.editor"-- with pytest.raises(ImportError) as exc:- moviepy_module.VideoClip.show(True)- assert str(exc.value) == "clip.show requires importing from moviepy.editor"-- del sys.modules["moviepy"]---if __name__ == "__main__":- pytest.main()diff --git a/tests/test_tools.py b/tests/test_tools.pyindex 27ded4d2..07aaad28 100644--- a/tests/test_tools.py+++ b/tests/test_tools.py@@ -109,7 +109,6 @@ def test_deprecated_version_of(old_name):),),)-def test_config(util,ffmpeg_binary,@@ -123,7 +122,6 @@ def test_config(prev_ffmpeg_binary = os.environ.get("FFMPEG_BINARY")os.environ["FFMPEG_BINARY"] = ffmpeg_binary-if ffmpeg_binary_error is not None:with pytest.raises(ffmpeg_binary_error[0]) as exc:importlib.import_module("moviepy.config")diff --git a/tests/test_videotools.py b/tests/test_videotools.pyindex 0fa5ee5e..f6515eff 100644--- a/tests/test_videotools.py+++ b/tests/test_videotools.py@@ -77,7 +77,11 @@ def test_detect_scenes():def test_find_video_period():- clip = VideoFileClip("media/chaplin.mp4").with_subclip(0, 0.5).with_effects([vfx.Loop(2)]) # fps=25+ clip = (+ VideoFileClip("media/chaplin.mp4")+ .with_subclip(0, 0.5)+ .with_effects([vfx.Loop(2)])+ ) # fps=25# you need to increase the fps to get correct resultsassert round(find_video_period(clip, fps=70), 6) == 0.5@@ -300,7 +304,9 @@ def test_FramesMatches_select_scenes(video_clip = VideoFileClip(filename)if subclip is not None:video_clip = video_clip.with_subclip(subclip[0], subclip[1])- clip = concatenate_videoclips([video_clip.with_effects([vfx.TimeMirror()]), video_clip])+ clip = concatenate_videoclips(+ [video_clip.with_effects([vfx.TimeMirror()]), video_clip]+ )result = FramesMatches.from_clip(clip, 10, 3, logger=None).select_scenes(match_threshold,min_time_span,@@ -313,7 +319,9 @@ def test_FramesMatches_select_scenes(def test_FramesMatches_write_gifs(util):video_clip = VideoFileClip("media/chaplin.mp4").with_subclip(0, 0.2)- clip = concatenate_videoclips([video_clip.with_effects([vfx.TimeMirror()]), video_clip])+ clip = concatenate_videoclips(+ [video_clip.with_effects([vfx.TimeMirror()]), video_clip]+ )# add matching frame starting at start < clip.start which should be ignoredmatching_frames = FramesMatches.from_clip(clip, 10, 3, logger=None)@@ -1081,9 +1089,9 @@ def test_find_audio_period(mono_wave, stereo_wave, wave_type):clip = CompositeAudioClip([AudioClip(make_frame=wave1, duration=0.3, fps=22050),- AudioClip(make_frame=wave2, duration=0.3, fps=22050).with_effects([- afx.MultiplyVolume(0, end_time=0.1)- ]),+ AudioClip(make_frame=wave2, duration=0.3, fps=22050).with_effects(+ [afx.MultiplyVolume(0, end_time=0.1)]+ ),])