diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 6df545e52..771759503 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -11,7 +11,7 @@ assignees: '' You can format code by putting ``` (that's 3 backticks) on a line by itself at the beginning and end of each code block. For example: ``` -from moviepy.editor import * +from moviepy import * clip = ColorClip((600, 400), color=(255, 100, 0), duration=2) ``` --> diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 309d7f77f..19eb1e4bd 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -15,7 +15,7 @@ Hello! If you think that it is a simple problem, then consider asking instead on You can format code by putting ``` (that's 3 backticks) on a line by itself at the beginning and end of each code block. For example: ``` -from moviepy.editor import * +from moviepy import * clip = ColorClip((600, 400), color=(255, 100, 0), duration=2) ``` --> diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 3a8c49152..f4b2a1040 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -39,6 +39,6 @@ jobs: # W503: line break before binary operator flake8 moviepy --ignore=E203,E302,E402,W291,W293,W503 --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero # Check examples and tests with slightly relaxed rules to allow 'star' imports - # F403 'from moviepy.editor import *' used; unable to detect undefined names - # F405 'name' may be undefined, or defined from star imports: moviepy.editor + # F403 'from moviepy import *' used; unable to detect undefined names + # F405 'name' may be undefined, or defined from star imports: moviepy flake8 . --ignore=E203,E302,E402,W291,W293,W503,F403,F405 --exclude moviepy/ --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero diff --git a/CHANGELOG.md b/CHANGELOG.md index b99628c63..0961960ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `VideoFileClip.coreader()` that creates a new clip created from the same source file as the original (to complement the existing `AudioFileClip.coreader()`) [\#1332](https://github.com/Zulko/moviepy/pull/1332) ### Changed -Lots of method and parameter names have been changed. This will be explained better in the documentation soon. See https://github.com/Zulko/moviepy/pull/1170 for more information. [\#1170](https://github.com/Zulko/moviepy/pull/1170) +- Lots of method and parameter names have been changed. This will be explained better in the documentation soon. See https://github.com/Zulko/moviepy/pull/1170 for more information. [\#1170](https://github.com/Zulko/moviepy/pull/1170) +- Changed recommended import from `import moviepy.editor` to `import moviepy`. This change is fully backwards compatible [\#1340](https://github.com/Zulko/moviepy/pull/1340) ### Deprecated - `moviepy.video.fx.all` and `moviepy.audio.fx.all`. Use the fx method directly from the clip instance or import the fx function from `moviepy.video.fx` and `moviepy.audio.fx`. [\#1105](https://github.com/Zulko/moviepy/pull/1105) diff --git a/README.rst b/README.rst index 7866e43a6..73cf9551f 100644 --- a/README.rst +++ b/README.rst @@ -32,7 +32,7 @@ In this example we open a video file, select the subclip between t=50s and t=60s .. code:: python - from moviepy.editor import * + from moviepy import * video = VideoFileClip("myHolidays.mp4").subclip(50,60) diff --git a/docs/examples/quick_recipes.rst b/docs/examples/quick_recipes.rst index 364d38d81..b7eabbb66 100644 --- a/docs/examples/quick_recipes.rst +++ b/docs/examples/quick_recipes.rst @@ -12,7 +12,7 @@ Blurring all frames of a video :: from skimage.filters import gaussian - from moviepy.editor import VideoFileClip + from moviepy import VideoFileClip def blur(image): """ Returns a blurred (radius=2 pixels) version of the image """ @@ -56,7 +56,7 @@ Getting the average frame of a video """"""""""""""""""""""""""""""""""""" :: - from moviepy.editor import VideoFileClip, ImageClip + from moviepy import VideoFileClip, ImageClip clip = VideoFileClip("video.mp4") fps= 1.0 # take one frame per second nframes = clip.duration*fps # total number of frames used diff --git a/docs/getting_started/audioclips.rst b/docs/getting_started/audioclips.rst index f80891597..4727149e6 100644 --- a/docs/getting_started/audioclips.rst +++ b/docs/getting_started/audioclips.rst @@ -18,7 +18,7 @@ Creating a new audio clip Audio clips can be created from an audio file or from the soundtrack of a video file :: - from moviepy.editor import * + from moviepy import * audioclip = AudioFileClip("some_audiofile.mp3") audioclip = AudioFileClip("some_video.avi") diff --git a/docs/getting_started/compositing.rst b/docs/getting_started/compositing.rst index fa6466c98..0612a4a56 100644 --- a/docs/getting_started/compositing.rst +++ b/docs/getting_started/compositing.rst @@ -22,7 +22,7 @@ Two simple ways of putting clips together is to concatenate them (to play them o Concatenation is done with the function ``concatenate_videoclips``: :: - from moviepy.editor import VideoFileClip, concatenate_videoclips + from moviepy import VideoFileClip, concatenate_videoclips clip1 = VideoFileClip("myvideo.mp4") clip2 = VideoFileClip("myvideo2.mp4").subclip(50,60) clip3 = VideoFileClip("myvideo3.mp4") @@ -34,7 +34,7 @@ The ``final_clip`` is a clip that plays the clips 1, 2, and 3 one after the othe Stacking is done with ``clip_array``: :: - from moviepy.editor import VideoFileClip, clips_array, vfx + from moviepy import VideoFileClip, clips_array, vfx clip1 = VideoFileClip("myvideo.mp4").margin(10) # add 10px contour clip2 = clip1.fx( vfx.mirror_x) clip3 = clip1.fx( vfx.mirror_y) @@ -125,7 +125,7 @@ When you mix video clips together, MoviePy will automatically compose their resp If you want to make a custom audiotrack from several audio sources: audioc clips can be mixed together with ``CompositeAudioClip`` and ``concatenate_audioclips``: :: - from moviepy.editor import * + from moviepy import * # ... make some audio clips aclip1, aclip2, aclip3 concat = concatenate_audioclips([aclip1, aclip2, aclip3]) compo = CompositeAudioClip([aclip1.volumex(1.2), diff --git a/docs/getting_started/effects.rst b/docs/getting_started/effects.rst index 37c473406..2d4b22988 100644 --- a/docs/getting_started/effects.rst +++ b/docs/getting_started/effects.rst @@ -47,15 +47,15 @@ but this is not easy to read. To have a clearer syntax you can use ``clip.fx``: .fx( effect_2, args2) .fx( effect_3, args3)) -Much better! There are already many effects implemented in the modules ``moviepy.video.fx`` and ``moviepy.audio.fx``. The fx methods in these modules are automatically applied to the sound and the mask of the clip if it is relevant, so that you don't have to worry about modifying these. For practicality, when you use ``from moviepy.editor import *``, these two modules are loaded as ``vfx`` and ``afx``, so you may write something like :: +Much better! There are already many effects implemented in the modules ``moviepy.video.fx`` and ``moviepy.audio.fx``. The fx methods in these modules are automatically applied to the sound and the mask of the clip if it is relevant, so that you don't have to worry about modifying these. For practicality, these two modules are loaded as ``vfx`` and ``afx``, so you may write something like :: - from moviepy.editor import * + from moviepy import * clip = (VideoFileClip("myvideo.avi") .fx( vfx.resize, width=460) # resize (keep aspect ratio) .fx( vfx.speedx, 2) # double the speed .fx( vfx.colorx, 0.5)) # darken the picture -For convenience, when you use ``moviepy.editor``, frequently used methods such as ``resize`` can be called in a simpler way: ``clip.resize(...)`` instead of ``clip.fx( vfx.resize, ...)`` +For convenience, fx methods such as ``resize`` can be called in a simpler way: ``clip.resize(...)`` instead of ``clip.fx( vfx.resize, ...)`` Methods to create custom effects diff --git a/docs/getting_started/efficient_moviepy.rst b/docs/getting_started/efficient_moviepy.rst index af7a70074..5642ee016 100644 --- a/docs/getting_started/efficient_moviepy.rst +++ b/docs/getting_started/efficient_moviepy.rst @@ -12,20 +12,11 @@ The best way to start with MoviePy is to use it with the IPython Notebook: it ma Should I use ``moviepy.editor``? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Most examples in this documentation use the submodule ``moviepy.editor``, but this submodule is not adapted to all needs so should *you* use it? Short answer: if you use MoviePy to edit videos *by hand*, use it, but if you use MoviePy inside a larger library or program or webserver, it is better to avoid it and just load the functions that you need. - -The module ``moviepy.editor`` can be loaded using one of the three following methods: :: - - - from moviepy.editor import * # imports everything, quick and dirty - import moviepy.editor as mpy # Clean. Then use mpy.VideoClip, etc. - from moviepy.editor import VideoFileClip # just import what you need - -With any of these lines, the ``moviepy.editor`` module will actually do a lot of work behind the curtain: it will fetch all the most common classes, functions and subpackages of MoviePy, initialize a PyGame session (if PyGame is installed) to be able to preview video clips, and implement some shortcuts, like adding the ``resize`` transformation to the clips. This way you can use ``clip.resize(width=240)`` instead of the longer ``clip.fx( resize, width=240)``. In short, ``moviepy.editor`` -provides all you need to play around and edit your videos, but it will take time to load (circa one second). So if all you need is one or two features inside another library, it is better to import directly what you need, as follows: :: - - from moviepy.video.io.VideoFileClip import VideoFileClip - from moviepy.video.fx.resize import resize +Older versions of MoviePy always recommended importing from ``moviepy.editor``. In v2.0 and above this is no longer recommended and you should generally import directly from ``moviepy`` (for example, ``from moviepy import VideoFileClip``). +The module ``moviepy.editor`` should now only be loaded if you are using MoviePy to edit videos *by hand*. Importing it will: +- Start a pygame session to enable ``clip.show()`` and ``clip.preview()`` if pygame is installed +- Enable ``clip.ipython_display()`` if in an IPython Notebook +- Enable ``sliders()`` if Matplotlib is installed .. _previewing: diff --git a/docs/getting_started/quick_presentation.rst b/docs/getting_started/quick_presentation.rst index 290032c52..efe79371b 100644 --- a/docs/getting_started/quick_presentation.rst +++ b/docs/getting_started/quick_presentation.rst @@ -39,7 +39,7 @@ Example code In a typical MoviePy script, you load video or audio files, modify them, put them together, and write the final result to a new video file. As an example, let us load a video of my last holidays, lower the volume, add a title in the center of the video for the first ten seconds, and write the result in a file: :: # Import everything needed to edit video clips - from moviepy.editor import * + from moviepy import * # Load myHolidays.mp4 and select the subclip 00:00:50 - 00:00:60 clip = VideoFileClip("myHolidays.mp4").subclip(50,60) diff --git a/docs/getting_started/videoclips.rst b/docs/getting_started/videoclips.rst index e66f3d8e4..8b7938a91 100644 --- a/docs/getting_started/videoclips.rst +++ b/docs/getting_started/videoclips.rst @@ -38,7 +38,7 @@ VideoClip ``VideoClip`` is the base class for all the other video clips in MoviePy. If all you want is to edit video files, you will never need it. This class is practical when you want to make animations from frames that are generated by another library. All you need is to define a function ``make_frame(t)`` which returns a HxWx3 numpy array (of 8-bits integers) representing the frame at time t. Here is an example with the graphics library Gizeh: :: import gizeh - import moviepy.editor as mpy + import moviepy as mpy WIDTH, HEIGHT = (128, 128) diff --git a/docs/getting_started/working_with_matplotlib.rst b/docs/getting_started/working_with_matplotlib.rst index fbd17897c..c9dc684da 100644 --- a/docs/getting_started/working_with_matplotlib.rst +++ b/docs/getting_started/working_with_matplotlib.rst @@ -9,7 +9,7 @@ MoviePy allows you to produce custom animations by defining a function that retu An example of this workflow is below: :: - from moviepy.editor import VideoClip + from moviepy import VideoClip def make_frame(t): """Returns an image of the frame for time t.""" @@ -32,7 +32,7 @@ An example of an animation using `matplotlib` can then be as follows: :: import matplotlib.pyplot as plt import numpy as np - from moviepy.editor import VideoClip + from moviepy import VideoClip from moviepy.video.io.bindings import mplfig_to_npimage x = np.linspace(-2, 2, 200) diff --git a/docs/ref/audiofx.rst b/docs/ref/audiofx.rst index a9a214493..9282cc5c5 100644 --- a/docs/ref/audiofx.rst +++ b/docs/ref/audiofx.rst @@ -28,7 +28,7 @@ Or import everything: :: When you type :: - from moviepy.editor import * + from moviepy import * the module ``audio.fx`` is loaded as ``afx`` and you can use ``afx.volumex``, etc. diff --git a/docs/ref/videofx.rst b/docs/ref/videofx.rst index 2bdf10c90..fd3b802fe 100644 --- a/docs/ref/videofx.rst +++ b/docs/ref/videofx.rst @@ -22,7 +22,7 @@ Or import everything: :: When you type: :: - from moviepy.editor import * + from moviepy import * the module ``video.fx`` is loaded as ``vfx`` and you can use ``vfx.colorx``, ``vfx.resize`` etc. diff --git a/examples/compo_from_image.py b/examples/compo_from_image.py index 122f50380..5acb4544f 100644 --- a/examples/compo_from_image.py +++ b/examples/compo_from_image.py @@ -1,4 +1,4 @@ -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.segmenting import find_objects # Load the image specifying the regions. diff --git a/examples/dancing_knights.py b/examples/dancing_knights.py index 037249d71..0bf9e68dd 100644 --- a/examples/dancing_knights.py +++ b/examples/dancing_knights.py @@ -24,7 +24,7 @@ import os import sys -from moviepy.editor import * +from moviepy import * from moviepy.audio.tools.cuts import find_audio_period from moviepy.video.tools.cuts import find_video_period diff --git a/examples/example_with_sound.py b/examples/example_with_sound.py index e0ee33411..907a6b6c8 100644 --- a/examples/example_with_sound.py +++ b/examples/example_with_sound.py @@ -5,7 +5,7 @@ movie put together. """ -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.drawing import color_split duration = 6 # duration of the final clip diff --git a/examples/headblur.py b/examples/headblur.py index 142ccb9d1..16ea17b60 100644 --- a/examples/headblur.py +++ b/examples/headblur.py @@ -1,4 +1,4 @@ -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.tracking import manual_tracking from moviepy.video.tools.interpolators import Trajectory diff --git a/examples/logo.py b/examples/logo.py index 829744e71..93b46cf9f 100644 --- a/examples/logo.py +++ b/examples/logo.py @@ -1,6 +1,6 @@ import numpy as np -from moviepy.editor import * +from moviepy import * w, h = moviesize = (720, 380) diff --git a/examples/masked_credits.py b/examples/masked_credits.py index 8d2989bfd..963572037 100644 --- a/examples/masked_credits.py +++ b/examples/masked_credits.py @@ -1,4 +1,4 @@ -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.credits import credits1 # Load the mountains clip, cut it, slow it down, make it look darker diff --git a/examples/moving_letters.py b/examples/moving_letters.py index f9ce53278..fc7b0d7d5 100644 --- a/examples/moving_letters.py +++ b/examples/moving_letters.py @@ -1,6 +1,6 @@ import numpy as np -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.segmenting import find_objects # WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT. diff --git a/examples/painting_effect.py b/examples/painting_effect.py index b61d52e7d..90d260cc3 100644 --- a/examples/painting_effect.py +++ b/examples/painting_effect.py @@ -1,6 +1,6 @@ """ requires scikit-image installed (for vfx.painting) """ -from moviepy.editor import * +from moviepy import * # WE TAKE THE SUBCLIPS WHICH ARE 2 SECONDS BEFORE & AFTER THE FREEZE diff --git a/examples/soundtrack.py b/examples/soundtrack.py index 057b996c0..9a1a6f637 100644 --- a/examples/soundtrack.py +++ b/examples/soundtrack.py @@ -1,5 +1,5 @@ """ A simple test script on how to put a soundtrack to a movie """ -from moviepy.editor import * +from moviepy import * # We load a movie and replace the sound with some music: diff --git a/examples/star_worms.py b/examples/star_worms.py index ae18db18e..8094adccf 100644 --- a/examples/star_worms.py +++ b/examples/star_worms.py @@ -8,7 +8,7 @@ import numpy as np -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.drawing import color_gradient from skimage import transform as tf diff --git a/examples/the_end.py b/examples/the_end.py index 8c38ee72d..237bafda9 100644 --- a/examples/the_end.py +++ b/examples/the_end.py @@ -1,4 +1,4 @@ -from moviepy.editor import * +from moviepy import * from moviepy.video.tools.drawing import circle clip = ( diff --git a/examples/ukulele_concerto.py b/examples/ukulele_concerto.py index e4c6da896..ddae9cd3d 100644 --- a/examples/ukulele_concerto.py +++ b/examples/ukulele_concerto.py @@ -1,4 +1,4 @@ -from moviepy.editor import * +from moviepy import * # UKULELE CLIP, OBTAINED BY CUTTING AND CROPPING # RAW FOOTAGE diff --git a/moviepy/Clip.py b/moviepy/Clip.py index 5e4bbc6c4..fc5efba33 100644 --- a/moviepy/Clip.py +++ b/moviepy/Clip.py @@ -475,7 +475,7 @@ def iter_frames(self, fps=None, with_times=False, logger=None, dtype=None): >>> # prints the maximum of red that is contained >>> # on the first line of each frame of the clip. - >>> from moviepy.editor import VideoFileClip + >>> from moviepy import VideoFileClip >>> myclip = VideoFileClip('myvideo.mp4') >>> print ( [frame[0,:,0].max() for frame in myclip.iter_frames()]) diff --git a/moviepy/__init__.py b/moviepy/__init__.py index 58f3ace6c..dfbde6449 100644 --- a/moviepy/__init__.py +++ b/moviepy/__init__.py @@ -1 +1,108 @@ -from .version import __version__ +""" +Imports everything that you need from the MoviePy submodules so that every thing +can be directly imported like `from moviepy import VideoFileClip`. + +In particular it loads all effects from the video.fx and audio.fx folders +and turns them into VideoClip and AudioClip methods, so that instead of +``clip.fx(vfx.resize, 2)`` or ``vfx.resize(clip, 2)`` +you can write ``clip.resize(2)``. + +""" + +import inspect + +from moviepy.version import __version__ + +# Clips +from moviepy.video.VideoClip import ( + VideoClip, + ImageClip, + ColorClip, + TextClip, + BitmapClip, +) +from moviepy.video.io.VideoFileClip import VideoFileClip +from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip, clips_array +from moviepy.video.io.ImageSequenceClip import ImageSequenceClip + +from moviepy.video.compositing.concatenate import concatenate_videoclips + +from moviepy.video.io.downloader import download_webfile + +from moviepy.audio.AudioClip import ( + AudioClip, + CompositeAudioClip, + concatenate_audioclips, +) +from moviepy.audio.io.AudioFileClip import AudioFileClip + +# FX +from moviepy.video import fx as vfx +from moviepy.audio import fx as afx +from moviepy.video.compositing import transitions as transfx + +# Tools +from moviepy.video import tools as videotools +from moviepy.video.io import ffmpeg_tools +from moviepy.tools import convert_to_seconds + +# Transforms the effects into Clip methods so that +# they can be called with clip.resize(width=500) instead of +# clip.fx(vfx.resize, width=500) +audio_fxs = inspect.getmembers(afx, inspect.isfunction) +video_fxs = ( + inspect.getmembers(vfx, inspect.isfunction) + + inspect.getmembers(transfx, inspect.isfunction) + + audio_fxs +) + +for name, function in video_fxs: + setattr(VideoClip, name, function) + +for name, function in audio_fxs: + setattr(AudioClip, name, function) + + +def preview(self, *args, **kwargs): + """NOT AVAILABLE: clip.preview requires importing from moviepy.editor""" + raise ImportError("clip.preview requires importing from moviepy.editor") + + +def show(self, *args, **kwargs): + """NOT AVAILABLE: clip.show requires importing from moviepy.editor""" + raise ImportError("clip.show requires importing from moviepy.editor") + + +VideoClip.preview = preview +VideoClip.show = show +AudioClip.preview = preview + +# Cleanup namespace +del audio_fxs, video_fxs, name, function, preview, show +del inspect + +# Importing with `from moviepy import *` will only import these names +__all__ = [ + "__version__", + "VideoClip", + "ImageClip", + "ColorClip", + "TextClip", + "BitmapClip", + "VideoFileClip", + "CompositeVideoClip", + "clips_array", + "ImageSequenceClip", + "concatenate_videoclips", + "download_webfile", + "AudioClip", + "CompositeAudioClip", + "concatenate_audioclips", + "AudioFileClip", + "vfx", + "afx", + "transfx", + "videotools", + "ffmpeg_tools", + "convert_to_seconds", +] diff --git a/moviepy/audio/fx/audio_loop.py b/moviepy/audio/fx/audio_loop.py index e8a3785ff..375c95a10 100644 --- a/moviepy/audio/fx/audio_loop.py +++ b/moviepy/audio/fx/audio_loop.py @@ -12,7 +12,7 @@ def audio_loop(clip, n_loops=None, duration=None): Examples ======== - >>> from moviepy.editor import * + >>> from moviepy import * >>> videoclip = VideoFileClip('myvideo.mp4') >>> music = AudioFileClip('music.ogg') >>> audio = afx.audio_loop( music, duration=videoclip.duration) diff --git a/moviepy/audio/fx/audio_normalize.py b/moviepy/audio/fx/audio_normalize.py index 8d088134b..4076346cb 100644 --- a/moviepy/audio/fx/audio_normalize.py +++ b/moviepy/audio/fx/audio_normalize.py @@ -13,7 +13,7 @@ def audio_normalize(clip): Examples ======== - >>> from moviepy.editor import * + >>> from moviepy import * >>> videoclip = VideoFileClip('myvideo.mp4').fx(afx.audio_normalize) """ diff --git a/moviepy/audio/fx/volumex.py b/moviepy/audio/fx/volumex.py index f00c1c468..846433553 100644 --- a/moviepy/audio/fx/volumex.py +++ b/moviepy/audio/fx/volumex.py @@ -6,15 +6,14 @@ def volumex(clip, factor): """Returns a clip with audio volume multiplied by the value `factor`. Can be applied to both audio and video clips. - This effect is loaded as a clip method when you use moviepy.editor, - so you can just write ``clip.volumex(2)`` + This effect is loaded as a clip method so you can just write ``clip.volumex(2)`` Examples --------- >>> new_clip = volumex(clip, 2.0) # doubles audio volume >>> new_clip = clip.fx( volumex, 0.5) # half audio, use with fx - >>> new_clip = clip.volumex(2) # only if you used "moviepy.editor" + >>> new_clip = clip.volumex(2) """ return clip.transform( lambda get_frame, t: factor * get_frame(t), keep_duration=True diff --git a/moviepy/editor.py b/moviepy/editor.py index c7ec4a9e8..041b7bf66 100644 --- a/moviepy/editor.py +++ b/moviepy/editor.py @@ -1,121 +1,51 @@ """ -This file is meant to make it easy to load the main features of -MoviePy by simply typing: +This file is meant to make it easy to load the features of +MoviePy that you will use for live editing by simply typing: >>> from moviepy.editor import * -In particular it will load many effects from the video.fx and audio.fx -folders and turn them into VideoClip methods, so that instead of ->>> clip.fx( vfx.resize, 2 ) or equivalently vfx.resize(clip, 2) -we can write ->>> clip.resize(2) - -It also starts a PyGame session (if PyGame is installed) and enables -clip.preview(). +- Starts a pygame session to enable ``clip.show()`` and ``clip.preview()`` if pygame is installed +- Enables ``clip.ipython_display()`` if in an IPython Notebook +- Allows the use of ``sliders`` if Matplotlib is installed """ -__all__ = [ - "afx", - "AudioClip", - "AudioFileClip", - "BitmapClip", - "clips_array", - "ColorClip", - "CompositeAudioClip", - "CompositeVideoClip", - "concatenate_audioclips", - "concatenate_videoclips", - "convert_to_seconds", - "download_webfile", - "ffmpeg_tools", - "ImageClip", - "ImageSequenceClip", - "ipython_display", - "TextClip", - "transfx", - "vfx", - "VideoClip", - "VideoFileClip", - "videotools", -] - -# Note that these imports could have been performed in the __init__.py -# file, but this would make the loading of moviepy slower. - import os -import inspect - - -# Hide the welcome message from pygame: https://github.com/pygame/pygame/issues/542 -os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1" - -# Clips -from .video.io.VideoFileClip import VideoFileClip -from .video.io.ImageSequenceClip import ImageSequenceClip -from .video.io.downloader import download_webfile -from .video.VideoClip import VideoClip, ImageClip, ColorClip, TextClip, BitmapClip -from .video.compositing.CompositeVideoClip import CompositeVideoClip, clips_array -from .video.compositing.concatenate import concatenate_videoclips - -from .audio.AudioClip import AudioClip, CompositeAudioClip, concatenate_audioclips -from .audio.io.AudioFileClip import AudioFileClip - -# FX - -import moviepy.video.fx as vfx -import moviepy.audio.fx as afx -import moviepy.video.compositing.transitions as transfx -# Tools - -import moviepy.video.tools as videotools -import moviepy.video.io.ffmpeg_tools as ffmpeg_tools +from . import * from .video.io.html_tools import ipython_display -from .tools import convert_to_seconds try: from .video.io.sliders import sliders - - __all__.append("sliders") except ImportError: - pass - -# Transforms the effects into Clip methods so that -# they can be called with clip.resize(width=500) instead of -# clip.fx(vfx.resize, width=500) -audio_fxs = inspect.getmembers(afx, inspect.isfunction) -video_fxs = ( - inspect.getmembers(vfx, inspect.isfunction) - + inspect.getmembers(transfx, inspect.isfunction) - + audio_fxs -) -for name, function in video_fxs: - setattr(VideoClip, name, function) - -for name, function in audio_fxs: - setattr(AudioClip, name, function) + def sliders(*args, **kwargs): + """NOT AVAILABLE : sliders requires matplotlib installed.""" + raise ImportError("sliders requires matplotlib installed") # adds easy ipython integration VideoClip.ipython_display = ipython_display AudioClip.ipython_display = ipython_display + + # ----------------------------------------------------------------- # Previews: try to import pygame, else make methods which raise # exceptions saying to install PyGame +# Hide the welcome message from pygame: https://github.com/pygame/pygame/issues/542 +os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1" # Add methods preview and show (only if pygame installed) try: - from moviepy.video.io.preview import show, preview + from .video.io.preview import show, preview except ImportError: def preview(self, *args, **kwargs): - """NOT AVAILABLE : clip.preview requires Pygame installed.""" + """NOT AVAILABLE: clip.preview requires Pygame installed""" raise ImportError("clip.preview requires Pygame installed") def show(self, *args, **kwargs): - """NOT AVAILABLE : clip.show requires Pygame installed.""" + """NOT AVAILABLE: clip.show requires Pygame installed""" raise ImportError("clip.show requires Pygame installed") @@ -123,12 +53,14 @@ def show(self, *args, **kwargs): VideoClip.show = show try: - from moviepy.audio.io.preview import preview + from .audio.io.preview import preview except ImportError: def preview(self, *args, **kwargs): - """ NOT AVAILABLE : clip.preview requires Pygame installed.""" + """ NOT AVAILABLE: clip.preview requires Pygame installed""" raise ImportError("clip.preview requires Pygame installed") AudioClip.preview = preview + +__all__ = ["ipython_display", "sliders"] diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py index 62d907fe6..cb9b3e8bd 100644 --- a/moviepy/video/VideoClip.py +++ b/moviepy/video/VideoClip.py @@ -278,7 +278,7 @@ def write_videofile( Examples ======== - >>> from moviepy.editor import VideoFileClip + >>> from moviepy import VideoFileClip >>> clip = VideoFileClip("myvideo.mp4").subclip(100,120) >>> clip.write_videofile("my_new_video.mp4") >>> clip.close() diff --git a/moviepy/video/compositing/transitions.py b/moviepy/video/compositing/transitions.py index 4d1ff6d38..0f5083a2a 100644 --- a/moviepy/video/compositing/transitions.py +++ b/moviepy/video/compositing/transitions.py @@ -1,7 +1,6 @@ """ Here is the current catalogue. These are meant to be used with clip.fx. There are available as transfx.crossfadein etc. -if you load them with ``from moviepy.editor import *`` """ from moviepy.decorators import add_mask_if_none, requires_duration @@ -60,7 +59,7 @@ def slide_in(clip, duration, side): Examples ========= - >>> from moviepy.editor import * + >>> from moviepy import * >>> clips = [... make a list of clips] >>> slided_clips = [CompositeVideoClip([ clip.fx(transfx.slide_in, duration=1, side='left')]) @@ -102,7 +101,7 @@ def slide_out(clip, duration, side): Examples ========= - >>> from moviepy.editor import * + >>> from moviepy import * >>> clips = [... make a list of clips] >>> slided_clips = [CompositeVideoClip([ clip.fx(transfx.slide_out, duration=1, side='left')]) diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.py index dff90f598..bc6e2bbe4 100644 --- a/moviepy/video/io/html_tools.py +++ b/moviepy/video/io/html_tools.py @@ -73,21 +73,7 @@ def html_embed( Examples ========= - - >>> import moviepy.editor as mpy - >>> # later ... - >>> clip.write_videofile("test.mp4") - >>> mpy.ipython_display("test.mp4", width=360) - - >>> clip.audio.write_audiofile('test.ogg') # Sound ! - >>> mpy.ipython_display('test.ogg') - - >>> clip.write_gif("test.gif") - >>> mpy.ipython_display('test.gif') - - >>> clip.save_frame("first_frame.jpeg") - >>> mpy.ipython_display("first_frame.jpeg") - + TODO Create example based on ipython_display examples """ if rd_kwargs is None: @@ -218,19 +204,16 @@ def ipython_display( Examples ========= - >>> import moviepy.editor as mpy + >>> from moviepy.editor import * >>> # later ... - >>> clip.write_videofile("test.mp4") - >>> mpy.ipython_display("test.mp4", width=360) - - >>> clip.audio.write_audiofile('test.ogg') # Sound ! - >>> mpy.ipython_display('test.ogg') + >>> clip.ipython_display(width=360) + >>> clip.audio.ipython_display() >>> clip.write_gif("test.gif") - >>> mpy.ipython_display('test.gif') + >>> ipython_display('test.gif') >>> clip.save_frame("first_frame.jpeg") - >>> mpy.ipython_display("first_frame.jpeg") + >>> ipython_display("first_frame.jpeg") """ if not ipython_available: diff --git a/moviepy/video/tools/cuts.py b/moviepy/video/tools/cuts.py index d9796bd8b..336837974 100644 --- a/moviepy/video/tools/cuts.py +++ b/moviepy/video/tools/cuts.py @@ -126,7 +126,7 @@ def from_clip(clip, distance_threshold, max_duration, fps=None): We find all matching frames in a given video and turn the best match with a duration of 1.5s or more into a GIF: - >>> from moviepy.editor import VideoFileClip + >>> from moviepy import VideoFileClip >>> from moviepy.video.tools.cuts import FramesMatches >>> clip = VideoFileClip("foo.mp4").resize(width=200) >>> matches = FramesMatches.from_clip(clip, distance_threshold=10, max_duration=3) # will take time diff --git a/moviepy/video/tools/tracking.py b/moviepy/video/tools/tracking.py index da3a82856..313f28744 100644 --- a/moviepy/video/tools/tracking.py +++ b/moviepy/video/tools/tracking.py @@ -63,7 +63,7 @@ def manual_tracking(clip, t1=None, t2=None, fps=None, n_objects=1, savefile=None Examples --------- - >>> from moviepy.editor import VideoFileClip + >>> from moviepy import VideoFileClip >>> from moviepy.video.tools.tracking import manual_tracking >>> clip = VideoFileClip("myvideo.mp4") >>> # manually indicate 3 trajectories, save them to a file diff --git a/tests/test_compositing.py b/tests/test_compositing.py index 0d0b21e0a..f46c361df 100644 --- a/tests/test_compositing.py +++ b/tests/test_compositing.py @@ -4,7 +4,7 @@ import pytest -from moviepy.editor import * +from moviepy import * from moviepy.utils import close_all_clips from tests.test_helper import TMP_DIR diff --git a/tests/test_fx.py b/tests/test_fx.py index 96ee6e670..40f6fd53f 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -3,35 +3,32 @@ import numpy as np import pytest -from moviepy.audio.AudioClip import AudioClip -from moviepy.audio.fx.audio_normalize import audio_normalize -from moviepy.audio.io.AudioFileClip import AudioFileClip +from moviepy import AudioClip, AudioFileClip, BitmapClip, ColorClip, VideoFileClip +from moviepy.audio.fx import audio_normalize from moviepy.utils import close_all_clips -from moviepy.video.VideoClip import BitmapClip, ColorClip -from moviepy.video.fx.blackwhite import blackwhite -from moviepy.video.fx.blink import blink -from moviepy.video.fx.colorx import colorx -from moviepy.video.fx.crop import crop -from moviepy.video.fx.even_size import even_size -from moviepy.video.fx.fadein import fadein -from moviepy.video.fx.fadeout import fadeout -from moviepy.video.fx.freeze import freeze -from moviepy.video.fx.freeze_region import freeze_region -from moviepy.video.fx.invert_colors import invert_colors -from moviepy.video.fx.loop import loop -from moviepy.video.fx.lum_contrast import lum_contrast -from moviepy.video.fx.make_loopable import make_loopable -from moviepy.video.fx.margin import margin -from moviepy.video.fx.mirror_x import mirror_x -from moviepy.video.fx.mirror_y import mirror_y -from moviepy.video.fx.resize import resize -from moviepy.video.fx.rotate import rotate -from moviepy.video.fx.speedx import speedx -from moviepy.video.fx.time_mirror import time_mirror -from moviepy.video.fx.time_symmetrize import time_symmetrize -from moviepy.video.io.VideoFileClip import VideoFileClip -from moviepy.video.VideoClip import ColorClip -from moviepy.video.fx.supersample import supersample +from moviepy.video.fx import ( + blackwhite, + blink, + colorx, + crop, + even_size, + fadein, + fadeout, + freeze, + freeze_region, + invert_colors, + loop, + lum_contrast, + make_loopable, + margin, + mirror_x, + mirror_y, + resize, + rotate, + speedx, + time_mirror, + time_symmetrize, +) from tests.test_helper import TMP_DIR diff --git a/tests/test_issues.py b/tests/test_issues.py index 81380ffa9..44b21a865 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -3,7 +3,7 @@ import pytest import os -from moviepy.editor import * +from moviepy import * from moviepy.utils import close_all_clips from moviepy.video.fx.blink import blink from moviepy.video.fx.resize import resize