Video editing with Python
modernized ipython_display, updated docs
Zulkob6802dae9e70
diff --git a/docs/getting_started/clips.rst b/docs/getting_started/clips.rstindex de72e8b0..cd7d70c1 100644--- a/docs/getting_started/clips.rst+++ b/docs/getting_started/clips.rst@@ -216,12 +216,12 @@ This section shows how to use MoviePy to create and edit audio clips.Note that when you import, cut, mix or concatenate video clips in MoviePy, their audio tracks are automatically handled and you don't need to worry about it. This section is of interest if you just want to edit audio files, or you want custom audio clips for your videos.What audioclips are made of-~~~~~~~~~~~~~~~~~~~~~~~~~~~~+""""""""""""""""""""""""""""""AudioClips are very similar to video clips in moviepy: they have a length, can be cut and composed the same way, etc. A notable difference is that their method ``myclip.get_frame(t)``, instead of returning a RGB picture array like for video clips, returns just a couple of values between -1 and 1 (e.g.``[-0.4, 0.2]``) representing the left-right stereo sound at time ``t`` (for mono sounds, only one value is returned)Creating a new audio clip-~~~~~~~~~~~~~~~~~~~~~~~~~~~+""""""""""""""""""""""""""""""Audio clips can be created from an audio file or from the soundtrack of a video file::@@ -236,6 +236,6 @@ Alternatively you can get the audio track of an already created video clip:videoclip = VideoFileClip("some_video.avi")audioclip = videoclip.audio-You can also create an audio clip from a numpy array or a custom function (to be written)+.. (next paragraphs still to be written)-For more, see :py:class:`~moviepy.audio.AudioClip.AudioClip`\ No newline at end of file+.. You can also create an audio clip from a numpy array. For more, see :py:class:`~moviepy.audio.AudioClip.AudioArrayClip`\ No newline at end of filediff --git a/docs/getting_started/compositing.rst b/docs/getting_started/compositing.rstindex 3d7fae55..feb2c319 100644--- a/docs/getting_started/compositing.rst+++ b/docs/getting_started/compositing.rst@@ -1,7 +1,7 @@.. _CompositeVideoClips:-Mixing clips together-=======================+Mixing clips+=============Video composition, also known as non-linear editing, is the fact of playing several clips together in a new clip. This video is a good example of what compositing you can do with MoviePy:@@ -52,7 +52,7 @@ You obtain a clip which looks like this:CompositeVideoClips~~~~~~~~~~~~~~~~~~~~~-The `CompositeVideoClip` class provides a very flexible way to compose clips, but is more complex than ``concatenate`` and ``clips_array`` ::+The `CompositeVideoClip` class provides a very flexible way to compose clips, but is more complex than ``concatenate_videoclips`` and ``clips_array`` ::video = CompositeVideoClip([clip1,clip2,clip3])@@ -76,8 +76,8 @@ So for instance your composition will look like ::In the example above, maybe ``clip2`` will start before ``clip1`` is over. In this case you can make ``clip2`` appear with a *fade-in* effect of one second: ::video = CompositeVideoClip([clip1, # starts at t=0- clip2.set_start(5).fadein(1),- clip3.set_start(9)])+ clip2.set_start(5).crossfadein(1),+ clip3.set_start(9).crossfadein(1.5)])Positioning clips""""""""""""""""""@@ -110,20 +110,25 @@ When indicating the position keep in mind that the ``y`` coordinate has its zero.. figure:: videoWH.jpeg-Transitions-------------+.. Transitions+.. -------------Everyone loves transitions between clips: fade-ins, fade-out, clips that slide in front of the previous one... everything is good to impress your grandparents.+.. Everyone loves transitions between clips: fade-ins, fade-out, clips that slide in front of the previous one... everything is good to impress your grandparents.++.. In MoviePy, transitions are effects (see :ref:`effects`_) from the module moviepy.video.compositing.Compositing audio clips--------------------------Audio clips can be mixed together with ``CompositeAudioClip`` and ``concatenate_audioclips``: ::+When you mix video clips together, MoviePy will automatically compose their respective audio tracks to form the audio track of the final clip, so you don't need to worry about compositing these tracks yourself.++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 *- # ... make some clips+ # ... make some audio clips aclip1, aclip2, aclip3concat = concatenate_audioclips([aclip1, aclip2, aclip3])compo = CompositeAudioClip([aclip1.volumex(1.2),- aclip2.set_start(5),- aclip3.set_start(9)])\ No newline at end of file+ aclip2.set_start(5), # start at t=5s+ aclip3.set_start(9)])+diff --git a/docs/getting_started/efficient_moviepy.rst b/docs/getting_started/efficient_moviepy.rstindex 9cdc9c5f..89a23a40 100644--- a/docs/getting_started/efficient_moviepy.rst+++ b/docs/getting_started/efficient_moviepy.rst@@ -74,7 +74,7 @@ Note that if the clip is complex and your computer not fast enough, the previewipython_display""""""""""""""""-Displaying the clips in a IPython Notebook can be very practical, especially if you can't use ``clip.show()`` and ``clip.preview()``. Here is what it will look like:+Displaying the clips in a IPython Notebook can be very practical, especially if don't want to use ``clip.show()`` and ``clip.preview()``. Here is what it will look like:.. image:: ../demo_preview.jpeg:width: 500px@@ -90,18 +90,22 @@ With ``ipython_display`` you can embed videos, images and sounds, either from aipython_display("my_video.mp4") # embeds a videoipython_display("my_sound.mp3") # embeds a sound+This will only work if ``ipython_display`` is on the last line a the notebook cell. You can also call ``ipython_display`` as a clip method: ::++ my_video_clip.ipython_display()++If the rendering of your clip requires to provide a frame rate, you can specify ``fps=25`` in ``ipython_display``.+If you only need to display a snapshot of a video clip at some time `t` you can write ::- ipython_display(video_clip.to_ImageClip(t=15)) # snapshot at t=15s+ my_video_clip.ipython_display(t=15) # will display a snapshot at t=15sYou can also provide any valid HTML5 option as keyword argument. For instance, if the clip is too big, you will write ::ipython_display(my_clip, width=400) # HTML5 will resize to 400 pixels-When you are creating a gif and want to check that it loops well, you can ask the video to start automatically and to loop (i.e. replay indefinitely) : ::+For instance, when you are editing an animated GIF and want to check that it loops well, you can ask the video to start automatically and to loop (i.e. replay indefinitely) : ::ipython_display(my_clip, autoplay=1, loop=1)-Importantly, ``ipython_display`` actually embeds the clips physically in your notebook. The advantage is that you can move the notebook or put it online and the videos will work. The drawback is that the file size of the notebook can become very large.--Finally, note that ``ipython_display`` only works when it is the last command of a cell of the notebook.\ No newline at end of file+Importantly, ``ipython_display`` actually embeds the clips physically in your notebook. The advantage is that you can move the notebook or put it online and the videos will work. The drawback is that the file size of the notebook can become very large. Depending on your browser, re-computing and displaying at video many times can take some place in the cache and the RAM (it will only be a problem for intensive uses). Restarting your browser solves the problem.\ No newline at end of filediff --git a/docs/ref/videofx.rst b/docs/ref/videofx.rstindex f0da7fa2..1d41d95f 100644--- a/docs/ref/videofx.rst+++ b/docs/ref/videofx.rst@@ -40,8 +40,7 @@ the module ``video.fx`` is loaded as ``vfx`` and you can use ``vfx.colorx``, ``vcropfadeinfadeout- freeze_at_end- freeze_at_start+ freezegamma_corrheadblurloopdiff --git a/moviepy/version.py b/moviepy/version.pyindex a16bc02d..d1b21f88 100644--- a/moviepy/version.py+++ b/moviepy/version.py@@ -1 +1 @@-__version__ = "0.2.1.9.02"+__version__ = "0.2.1.9.04"diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.pyindex 67f55100..6295c2c9 100644--- a/moviepy/video/io/html_tools.py+++ b/moviepy/video/io/html_tools.py@@ -147,20 +147,32 @@ def html_embed(clip, filetype=None, maxduration=60, rd_kwargs=None,-def ipython_display(clip, filetype=None, maxduration=60, rd_kwargs=None,- **html_kwargs):+def ipython_display(clip, filetype=None, maxduration=60, t=None, fps=None,+ rd_kwargs=None, **html_kwargs):"""clipEither the name of a file, or a clip to preview. The clip will- actually be written to a file and embedded as if a filename was provided.-+ actually be written to a file and embedded as if a filename was+ provided.filetype:One of 'video','image','audio'. If None is given, it is determinedbased on the extension of ``filename``, but this can bug.++ maxduration+ An error will be raised if the clip's duration is more than the indicated+ value (in seconds), to avoid spoiling the browser's cache and the RAM.++ t+ If not None, only the frame at time t will be displayed in the notebook,+ instead of a video of the clip++ fps+ Enables to specify an fps, as required for clips whose fps is unknown.**kwargs:- Allow you to give some options, like width=260, etc.+ Allow you to give some options, like width=260, etc. When editing+ looping gifs, a good choice is loop=1, autoplay=1.Remarks: If your browser doesn't support HTML5, this should warn you.If nothing is displayed, maybe your file or filename is wrong.@@ -183,7 +195,14 @@ def ipython_display(clip, filetype=None, maxduration=60, rd_kwargs=None,>>> clip.save_frame("first_frame.jpeg")>>> mpy.ipython_display("first_frame.jpeg")"""+if not ipython_available:raise ImportError("Only works inside an IPython Notebook")++ if fps is not None:+ rd_kwargs['fps'] = fps++ if t is not None:+ clip = clip.to_ImageClip(t)return HTML(html_embed(clip, filetype=filetype, maxduration=maxduration,rd_kwargs=rd_kwargs, **html_kwargs))\ No newline at end of file