Video editing with Python
bug fixes in fadein, scroll, editor, docs update (crashcourse)
Zulkoa4198baa79ad
diff --git a/docs/crash_course/crash_course.rst b/docs/crash_course/crash_course.rstindex b1e684a4..622d8825 100644--- a/docs/crash_course/crash_course.rst+++ b/docs/crash_course/crash_course.rst@@ -54,15 +54,21 @@ Now ``video`` is a clip that plays the clips 1, 2, and 3 one after the other. YoNext, you have the `~moviepy.video.compositing.CompositeVideoClip.CompositeVideoClip`: ::- video = CompositeVideoClip(clip1.size, [clip1,clip2,clip3])+ video = CompositeVideoClip([clip1,clip2,clip3])-Now ``video`` is a clip that has the size of ``clip1``, and plays ``clip1``, and ``clip2`` *on top of* ``clip1``, and ``clip3`` on top of-``clip1``, and ``clip2``. Of course, if ``clip2`` and ``clip3`` have the same size as ``clip1``, then only ``clip3``, which is on top, will be-visible in the video... unless ``clip3`` and ``clip2`` have masks which hide parts of them.+Now ``video`` plays ``clip1``, and ``clip2`` *on top of* ``clip1``, and ``clip3`` on top of ``clip1``, and ``clip2``. For instance, if ``clip2`` and ``clip3`` have the same size as ``clip1``, then only ``clip3``, which is on top, will be visible in the video... unless ``clip3`` and ``clip2`` have masks which hide parts of them. Note that by default the composition has the size of its first clip (as it is generally a *background*). But sometimes you will want to make your clips *float* in a bigger composition, so you will specify the size of the final composition as follows ::-You can set the starting time of each clip as follows: ::+ video = CompositeVideoClip([clip1,clip2,clip3], size=(720,460))- video = CompositeVideoClip(clip.size, [clip1,clip2,clip3])+In a CompositionClip, all the clips start to play at a time that is specified by the ``clip.start`` attribute. You can set this starting time as follows: ::++ clip2 = clip1.set_start(5) # start after 5 seconds++So for instance your composition will look like ::++ video = CompositeVideoClip([clip1, # starts at t=0+ clip2.set_start(5), # start at t=5s+ clip3.set_start(9)]) # start at t=9sBecause the three clips overlap, we can make them appear with a fading-in effect. Here we go for fadein effects that last 1.5 seconds: ::@@ -70,18 +76,12 @@ Because the three clips overlap, we can make them appear with a fading-in effectclip2.set_start(50).fadein(1.5),clip3.set_start(90).fadein(1.5)])-Finally, if ``clip2`` and ``clip3`` are smaller than ``clip1``, you can decide where they will appear: ::+Finally, if ``clip2`` and ``clip3`` are smaller than ``clip1``, you can decide where they will appear in the composition: ::video = CompositeVideoClip([clip1,clip2.set_pos((45,150)),clip3.set_pos((90,100))])-The size of the final clip is by default the size of the first clip in the list. If you want all your clips to appear in a composition of arbitrary size use argument ``size``: ::-- video = CompositeVideoClip([clip1.set_pos((45,150)),- clip2.set_pos((45,150))],- size = (720,460))-Note that there are many ways to specify the position: ::clip2.set_pos((45,150)) # x=45, y=150@@ -125,9 +125,10 @@ To write a clip as a video file, use ::myClip.to_videofile("myEditedMovie.avi",audio=False) # don't render the audio.-Sometimes it is impossible for MoviePy to guess the ``duration`` attribute of the clip (keep in mind that some clips, like clips displaying a picture, have *a priori* an infinite duration). Then, the ``duration`` must be set manually with ``clip.set_duration``: ::+Sometimes it is impossible for MoviePy to guess the ``duration`` attribute of the clip (keep in mind that some clips, like ImageClips displaying a picture, have *a priori* an infinite duration). Then, the ``duration`` must be set manually with ``clip.set_duration``: ::- myClip = Image("floawer.jpeg") # has infinite duration+ myClip = Image("flower.jpeg") # has infinite duration+ Image("flower.jpeg").preview() # Will fail ! NO DURATION !myClip.set_duration(5).preview() # will show flowers for 5 seconds.. _CCaudioClips:diff --git a/moviepy/editor.py b/moviepy/editor.pyindex 76295c66..f3056dac 100644--- a/moviepy/editor.py+++ b/moviepy/editor.py@@ -12,6 +12,8 @@ from moviepy.video.io.VideoFileClip import VideoFileClipfrom moviepy.video.VideoClip import VideoClip, ImageClip, ColorClip, TextClipfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.compositing.concatenate import concatenate++from moviepy.audio.AudioClip import AudioClipfrom moviepy.audio.io.AudioFileClip import AudioFileClip# FX@@ -46,7 +48,13 @@ for method in ["vfx.crop","transfx.crossfadein","transfx.crossfadeout"]:exec("VideoClip.%s = %s"%( method.split('.')[1], method))-+++for method in ["afx.audio_fadein",+ "afx.audio_fadeout"]:+ exec("AudioClip.%s = %s"%( method.split('.')[1], method))++VideoClip.crop = vfx.cropVideoClip.resize = vfx.resizediff --git a/moviepy/video/fx/fadein.py b/moviepy/video/fx/fadein.pyindex 4bb204a0..09139f84 100644--- a/moviepy/video/fx/fadein.py+++ b/moviepy/video/fx/fadein.py@@ -1,8 +1,7 @@-+def fadein(clip, duration):- """- Makes the clip fade to black progressively, over ``duration`` seconds.- For more advanced fading, see ``composition.crossfade``- """+ """ Makes the clip fade to black progressively, over ``duration``+ seconds. For more advanced fading, see+ ``moviepy.video.composition.crossfadein`` """- return clip.fl(lambda gf, t: min(1.0 * t / duration, 1) * gf(t))+ return clip.fl(lambda gf, t: min(1.0 * t / duration, 1) * gf(t))diff --git a/moviepy/video/fx/scroll.py b/moviepy/video/fx/scroll.pyindex d99b5167..e7ff18c6 100644--- a/moviepy/video/fx/scroll.py+++ b/moviepy/video/fx/scroll.py@@ -1,11 +1,12 @@-def scroll(clip, h=None, w=None, x_speed=0, y_speed=0, apply_to="mask"):+def scroll(clip, h=None, w=None, x_speed=0, y_speed=0,+ x_start=0, y_start=0, applyto="mask"):""" Scrolls horizontally or vertically a clip, e.g. to make endcredits """if h is None: h = clip.hif w is None: w = clip.wdef f(gf,t):- x = int(x_speed*t)- y = int(y_speed*t)+ x = x_start+int(x_speed*t)+ y = y_start+ int(y_speed*t)return gf(t)[y:y+h, x:x+w]- return clip.fl(fl, apply_to = apply_to)+ return clip.fl(f, applyto = applyto)diff --git a/setup.py b/setup.pyindex 34023cd6..85d909ef 100644--- a/setup.py+++ b/setup.py@@ -6,7 +6,7 @@ ez_setup.use_setuptools()from setuptools import setup, find_packagessetup(name='moviepy',- version='0.2.1.6.91',+ version='0.2.1.6.92',author='Zulko 2013',description='Module for script-based video editing',long_description=open('README.rst').read(),