Skip to content

Video editing with Python

improved docs, added knights example

Zulko0d5d462b24da
diff --git a/docs/getting_started/advanced_tools.py b/docs/advanced_tools/advanced_tools.py
similarity index 100%
rename from docs/getting_started/advanced_tools.py
rename to docs/advanced_tools/advanced_tools.py
diff --git a/docs/getting_started/advanced_tools.rst b/docs/advanced_tools/advanced_tools.rst
similarity index 100%
rename from docs/getting_started/advanced_tools.rst
rename to docs/advanced_tools/advanced_tools.rst
diff --git a/docs/examples/dancing_knights.rst b/docs/examples/dancing_knights.rst
new file mode 100644
index 00000000..f18c6ec2
--- /dev/null
+++ b/docs/examples/dancing_knights.rst
@@ -0,0 +1,18 @@
+==========================================
+A reconstitution of 15th century dancing
+==========================================
+
+And now for something very silly...
+
+.. raw:: html
+
+ <div style="position: relative; padding-bottom: 56.25%; padding-top: 30px; margin-bottom:30px; height: 0; overflow: hidden;
+ margin-left: 5%;">
+ <iframe src="http://youtube.com/v/Qu7HJrsEYFg?rel=0" frameborder="0" allowfullscreen
+ style="position: absolute; top: 0; bottom: 10; width: 90%; height: 100%;">
+ </iframe>
+ </div>
+
+.. literalinclude:: ../../examples/dancing_knights.py
+
+
diff --git a/docs/examples/examples.rst b/docs/examples/examples.rst
index e78b0275..9ae71d3d 100644
--- a/docs/examples/examples.rst
+++ b/docs/examples/examples.rst
@@ -3,13 +3,14 @@
Example Scripts
===============
-Here are a few example scripts to get you started. There are quite old now and will be soon replaced.
+Here are a few example scripts to get you started. Most are quite old now and will be soon replaced.
.. toctree::
:maxdepth: 1
moving_letters
+ dancing_knights
ukulele_concerto
example_with_sound
star_worms
diff --git a/docs/getting_started/audio.rst b/docs/getting_started/audio.rst
new file mode 100644
index 00000000..1dffa3ea
--- /dev/null
+++ b/docs/getting_started/audio.rst
@@ -0,0 +1,24 @@
+.. _audio:
+
+Audio in MoviePy
+-----------------
+
+This section shows how to use MoviePy to create and edit audio clips.
+
+Note that when you cut, mix or concatenate video clips in MoviePy the audio is automatically handled and you need to worry about it. This section is of interest if you just want to edit audiofiles or you want custom audio clips for your videos.
+
+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 *
+ audioclip = AudioFileClip("some_audiofile.mp3")
+ audioclip = AudioFileClip("some_video.avi")
+
+Alternatively you can get the audio track of an already created video clip:
+
+ videoclip = VideoFileClip("some_video.avi")
+ audioclip = videoclip.audio
+
+You can also
\ No newline at end of file
diff --git a/docs/getting_started/audioclips.rst b/docs/getting_started/audioclips.rst
new file mode 100644
index 00000000..3614ad4b
--- /dev/null
+++ b/docs/getting_started/audioclips.rst
@@ -0,0 +1,49 @@
+.. _audio:
+
+
+
+Audio in MoviePy
+-----------------
+
+This section shows how to use MoviePy to create and edit audio clips.
+
+Note that when you cut, mix or concatenate video clips in MoviePy the audio is automatically handled and you need to worry about it. This section is of interest if you just want to edit audiofiles 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 be composed
+``audioclip.get_frame(t)``
+
+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 *
+ audioclip = AudioFileClip("some_audiofile.mp3")
+ audioclip = AudioFileClip("some_video.avi")
+
+Alternatively you can get the audio track of an already created video clip:
+
+ videoclip = VideoFileClip("some_video.avi")
+ audioclip = videoclip.audio
+
+You can also
+
+Compositing audio clips
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+Exporting and previewing audio clips
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can export
+
+You can
+
+You can also export assign an audio clip as the soundtrack of a video clip with::
+
+ videoclip2 = videoclip.set_audio(my_audioclip)
+
diff --git a/docs/getting_started/effects.rst b/docs/getting_started/effects.rst
index a8bca366..3b1606e1 100644
--- a/docs/getting_started/effects.rst
+++ b/docs/getting_started/effects.rst
@@ -11,18 +11,18 @@ There are several categories of clip modifications in MoviePy:
- The already-implemented effects. Core effects like ``clip.subclip(t1, t2)`` (keep only the cut between t1 and t2), which are very important, are implemented as class methods. More advanced and less common effects like ``loop`` (makes the clip play in a loop) or ``time_mirror`` (makes the clip play backwards) are placed in the special modules ``moviepy.video.fx`` and ``moviepy.audio.fx`` and are applied with the ``clip.fx`` method, for instance ``clip.fx(time_mirror)`` (makes the clip play backwards), ``clip.fx(black_white)`` (turns the clip black and white), etc.
- The effects that you can create yourself. using
-Importantly, all these effects have in common that they are **not inplace**: none of these effects modifies the original clip, they all create a new clip that is a version of the former with the changes applied. For instance: ::
+All these effects have in common that they are **not inplace**: they do NOT modify the original clip, instead they create a new clip that is a version of the former with the changes applied. For instance: ::
my_clip = VideoFileClip("some_file.mp4")
- my_clip.set_start(t=5) # does nothing, changes nothing !
- my_new_clip = my_clip.set_duration(t=5) # good !
+ my_clip.set_start(t=5) # does nothing, changes are lost
+ my_new_clip = my_clip.set_start(t=5) # good !
-Also, when you apply an effect like ``clip.resize(width=640)``, only the first frame of the clip is computed, all the other frames will be computed only when they are required (so when you write the clip to a file of when you preview it). Said otherwise, creating a new clip is neither time nor memory hungry, it's at the final rendering that all the computations happen.
+Also, when you write ``clip.resize(width=640)``, it does not immediately applies the effect to all the frames of the clip, but only to the first frame: all the other frames will be resized only when required (that is, when you will write the whole clip to a file of when you will preview it). Said otherwise, creating a new clip is neither time nor memory hungry, all the computations happen during the final rendering.
Time representations in MoviePy
---------------------------------
-Many methods that we will see accept times as arguments. For instance ``clip.subclip(t_start,t_end)`` which cuts the clip between two times. The times can be represented either in seconds (``t_start=230.54``), as a couple (minutes, seconds) (``t_start=(3,50.54)``), as a triplet (hour, min, sec) (``t_start=(0,3,50.54)``) or as a string (``t_start='00:03:50.54')``).
+Many methods that we will see accept times as arguments. For instance ``clip.subclip(t_start,t_end)`` which cuts the clip between two times. For these methods, times can be represented either in seconds (``t_start=230.54``), as a couple (minutes, seconds) (``t_start=(3,50.54)``), as a triplet (hour, min, sec) (``t_start=(0,3,50.54)``) or as a string (``t_start='00:03:50.54')``).
Most of the time when the times are not provided they are guessed, for instance in ``clip.subclip(t_start=50)`` it is implied that ``t_end`` corresponds to the end of the clip, in ``clip.subclip(t_end=20)`` it is implied that t_start=0. If the time is negative it is considered as the time before the end of the clip: ``clip.subclip(-20, -10)`` cuts the clip between 20s before the end and 10s before the end.
@@ -30,19 +30,13 @@ Most of the time when the times are not provided they are guessed, for instance
Methods to change the clip attributes
---------------------------------------
-Already-implemented effects
-------------------------------
-See :ref:`refvideofx` for a complete list and documentation of these
-Methods to create custom effects
-----------------------------------
-
clip.fx
-""""""""
+----------
-Suppose that you have some functions implementing effects on clips: ::
+Suppose that you have some functions implementing effects on clips, i.e. functions which, given a clip and some arguments, return a new clip: ::
effect_1(clip, args1) -> new clip
effect_2(clip, args2) -> new clip
@@ -63,12 +57,15 @@ Much better ! There are already many effects implemented in the modules ``moviep
from moviepy.editor import *
clip = (VideoFileClip("myvideo.avi")
.fx( vfx.resize, width=460) # resize (keep aspect ratio)
- .fx( vfx.speedx, 2) # double speed
+ .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, ...)``
+Methods to create custom effects
+----------------------------------
+
clip.fl
""""""""
diff --git a/docs/getting_started/quick_presentation.rst b/docs/getting_started/quick_presentation.rst
index 871a1219..d40e8919 100644
--- a/docs/getting_started/quick_presentation.rst
+++ b/docs/getting_started/quick_presentation.rst
@@ -17,6 +17,7 @@ Here are a few reasons why you may want to edit videos in Python:
- You want to create animations from images generated by another python library (Matplotlib, Mayavi, Gizeh, scikit-images...)
And here are a few uses for which MoviePy is NOT the best solution:
+
- You only need to do frame-by-frame video analysis (with face detection or other fancy stuff). This could be done with MoviePy in association with other libraries, but really, just use OpenCV or SimpleCV, these are libraries that specialize in these tasks.
- You only want to convert a video, or convert a series of images to a movie. In this case it is better to directly call ``ffmpeg`` (or ``avconv`` or ``mencoder``...) it will be faster more memory-efficient than going through MoviePy.
diff --git a/docs/getting_started/videoclips.rst b/docs/getting_started/videoclips.rst
new file mode 100644
index 00000000..f016f8e2
--- /dev/null
+++ b/docs/getting_started/videoclips.rst
@@ -0,0 +1,134 @@
+.. _clips:
+
+Creating and exporting video clips
+===================================
+
+Video au audio clips are the central objects of MoviePy. In this section we present the different sorts of clips, how to create them, and how to write them to a file. For informations on modifying a clip (cuts, effects, etc.), see :ref:`effects`. For how to put clips together see :ref:`CompositeVideoClips` and to see how to preview clips before writing a file, refer to :ref:`efficient`.
+
+The following code summarizes the base clips that you can create with moviepy: ::
+
+ # VIDEO CLIPS
+ clip = VideoClip(make_frame, duration=4) # for custom animations (see below)
+ clip = VideoFileClip("my_video_file.mp4") # or .avi, .webm, .gif ...
+ clip = ImageClip("my_picture.png") # or .jpeg, .tiff, ...
+ clip = TextClip("Hello !", font="Amiri-Bold", fontsize=70, color="black")
+ clip = ColorClip(size=(460,380), color=[R,G,B])
+
+ # AUDIO CLIPS
+ clip = AudioFileClip("my_audiofile.mp3") # or .ogg, .wav... or a video !
+ clip = AudioArrayClip(numpy_array, fps=44100) # from a numerical array
+ clip = AudioClip(make_frame, duration=3) # uses a function make_frame(t)
+
+
+
+The best to understand these clips is to read the full documentation for each in the :ref:`reference_manual`. The next sections
+In this section we see how to create clips, (for instance from video or audio files), how to mix them together, and how to write them to a file.
+
+
+
+Categories of video clips
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Video clips are the building blocks of longer videos. Technically, they are clips with a ``clip.get_frame(t)`` method which outputs a HxWx3 numpy array representing the frame of the clip at time *t*. There are two main categories: animated clips (made with ``VideoFileClip`` and ``VideoClip``) and unanimated clips which show the same picture for an a-priori infinite duration (``ImageClip``, ``TextClip``,``ColorClip``). There are also special video clips call masks, which belong to the categories above but output greyscale frames indicating which parts of another clip are visible or not. A video clip can carry around an audio clip (``clip.audio``) which is its *soundtrack*, and a mask clip.
+
+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
+
+ def make_frame(t):
+ surface = gizeh.Surface(128,128) # width, height
+ radius = W*(1+ (t*(2-t))**2 )/6 # the radius varies over time
+ circle = gizeh.circle(radius, xy = (64,64), fill=(1,0,0))
+ circle.draw(surface)
+ return surface.get_npimage() # returns a 8-bit RGB array
+
+ clip = mpy.VideoClip(make_frame, duration=2) # 2 seconds
+ clip.write_gif("circle.gif",fps=15)
+
+.. image:: circle.gif
+ :width: 128 px
+ :align: center
+
+Note: three next sections are in construction
+
+VideoFileClip
+"""""""""""""""
+See :py:class:`~moviepy.video.io.VideoFileClip.VideoFileClip`.
+
+ImageClip
+""""""""""
+See :py:class:`~moviepy.video.VideoClip.ImageClip`.
+
+TextClip
+"""""""""""""""
+See :py:class:`~moviepy.video.VideoClip.TextClip`.
+
+
+Mask clips
+~~~~~~~~~~~~~~
+
+A mask is a special video clip which indicates which pixels will be visible when a video clip carrying this mask will be composed with other video clips (see :ref:`CompositeVideoClips`).
+
+The fundamental difference between masks and standard clips is that standard clips output frames with 3 components (R-G-B) per pixel, comprised between 0 and 255, while a mask has just one composant per pixel, between 0 and 1 (1 indicating a fully visible pixel and 0 a transparent pixel). Seen otherwise, a mask is always in greyscale.
+
+When you create or load a clip that you will use as a mask you need to declare it: ::
+
+ mclip = VideoClip(makeframe, duration=4, ismask=True)
+ mclip = ImageClip("my_mask.jpeg", ismask=True)
+ mclip = VideoClip("myvideo.mp4", ismask=True)
+
+In the case of video and image files, if these are not already black and white they will be converted automatically.
+
+Any video clip can be turned into a mask with ``clip.to_mask()``, and a mask can be turned to a standard RGB video clip with ``my_mask_clip.to_RGB()``.
+
+
+Masks are treated differently by many methods (because their frames are different) but you can do with a mask pretty much everything you can do with a standard clip: you can cut it, edit it, preview it, write it to a video file, make snapshots, etc.
+
+.. _renderingAClip:
+
+Exporting video clips
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Video files (.mp4, .webm, .ogv...)
+""""""""""""""""""""""""""""""""""""
+
+To write a clip as a video file, use ::
+
+ my_clip.write_videofile("movie.mp4") # default codec: 'libx264', 24 fps
+ my_clip.write_videofile("movie.mp4",fps=15)
+ my_clip.write_videofile("movie.webm") # webm format
+ my_clip.write_videofile("movie.webm",audio=False) # don't render audio.
+
+MoviePy has default codec names for the most common file extensions. If you want to use exotic formats or if you are not happy with the defaults you can provide the codec with ``codec='mpeg4'`` for instance. There are many many options when you are writing a video (bitrate, parameters of the audio writing, file size optimization, number of processors to use, etc.). Please refer to :py:meth:`~moviepy.video.VideoClip.VideoClip.write_videofile` for more.
+
+
+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``: ::
+
+ # Make a video showing a flower for 5 seconds
+ my_clip = Image("flower.jpeg") # has infinite duration
+ my_clip.write_videofile("flower.mp4") # Will fail ! NO DURATION !
+ my_clip.set_duration(5).write_videofile("flower.mp4") # works !
+
+
+Animated GIFs
+""""""""""""""
+
+To write your video as an animated GIF, use ::
+
+ my_clip.write_gif('test.gif', fps=12)
+
+Note that this requires ImageMagick installed. Otherwise you can also create the GIF with ffmpeg by adding the option ``program='ffmpeg'``, it will be much faster but won't look as nice and won't be optimized.
+
+There are many options to optimize the quality and size of a gif. Please refer to :py:meth:`~moviepy.video.VideoClip.VideoClip.write_gif`.
+
+Note that for editing gifs the best way is to preview them in the notebook as explained here: :ref:`ipython_display`
+
+See `this blog post <http://zulko.github.io/blog/2014/01/23/making-animated-gifs-from-video-files-with-python>`_ for informations on making GIFs from video files, and `this other post <http://zulko.github.io/blog/2014/09/20/vector-animations-with-python/>`_ for GIF animations with vector graphics.
+
+.. _CCaudioClips:
+
+
diff --git a/examples/README.rst b/examples/README.rst
index 87ecf8cb..8c42c312 100644
--- a/examples/README.rst
+++ b/examples/README.rst
@@ -1 +1 @@
-This folder contains curated example scripts for editing movies with MoviePy.
+This folder contains curated examples for MoviePy.
diff --git a/examples/clips_array.py b/examples/clips_array.py
deleted file mode 100644
index 7be07ba9..00000000
--- a/examples/clips_array.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from moviepy.editor import *
-
-
diff --git a/examples/dancing_knights.py b/examples/dancing_knights.py
new file mode 100644
index 00000000..3a081a75
--- /dev/null
+++ b/examples/dancing_knights.py
@@ -0,0 +1,119 @@
+# -*- coding: utf-8 -*-
+
+"""
+Result: https://www.youtube.com/watch?v=Qu7HJrsEYFg
+
+This is how we can imagine knights dancing at the 15th century, based on a very
+serious historical study here: https://www.youtube.com/watch?v=zvCvOC2VwDc
+
+Here is what we do:
+
+0- Get the video of a dancing knight, and a (Creative Commons) audio music file.
+1- load the audio file and automatically find the tempo
+2- load the video and automatically find a segment that loops well
+3- extract this segment, slow it down so that it matches the audio tempo,
+ and make it loop forever.
+4- Symmetrize this segment so that we will get two knights instead of one
+5- Add a title screen and some credits, write to a file.
+
+
+This example has been originally edited in an IPython Notebook, which makes it
+easy to preview and fine-tune each part of the editing.
+"""
+
+from moviepy.editor import *
+from moviepy.video.tools.cuts import find_video_period
+from moviepy.audio.tools.cuts import find_audio_period
+
+
+# Next lines are for downloading the required videos from Youtube.
+# To do this you must have youtube-dl installed, otherwise you will need to
+# download the videos by hand and rename them, as follows:
+# https://www.youtube.com/watch?v=zvCvOC2VwDc => knights.mp4
+# https://www.youtube.com/watch?v=lkY3Ek9VPtg => frontier.mp4
+
+import os
+if not os.path.exists("knights.mp4"):
+ os.system("youtube-dl zvCvOC2VwDc -o knights.mp4")
+ os.system("youtube-dl lkY3Ek9VPtg -o frontier.mp4")
+#==========
+
+
+# LOAD, EDIT, ANALYZE THE AUDIO
+
+
+audio = (AudioFileClip("frontier.mp4")
+ .subclip((4,7), (4,18))
+ .audio_fadein(1)
+ .audio_fadeout(1))
+
+audio_period = find_audio_period(audio)
+print ('Analyzed the audio, found a period of %.02f seconds'%audio_period)
+
+
+# LOAD, EDIT, ANALYZE THE VIDEO
+
+
+clip = (VideoFileClip("./knights.mp4", audio=False)
+ .subclip((1,24.15),(1,26))
+ .crop(x1=332, x2=910, y2=686))
+
+video_period = find_video_period(clip, tmin=.3)
+print ('Analyzed the video, found a period of %.02f seconds'%video_period)
+
+edited_right = (clip.subclip(0,video_period)
+ .speedx(final_duration=2*audio_period)
+ .fx(vfx.loop, duration=audio.duration)
+ .subclip(.25))
+
+edited_left = edited_right.fx(vfx.mirror_x)
+
+dancing_knights = (clips_array([[edited_left, edited_right]])
+ .fadein(1).fadeout(1).set_audio(audio).subclip(.3))
+
+# MAKE THE TITLE SCREEN
+
+
+txt_title = (TextClip("15th century dancing\n(hypothetical)", fontsize=70,
+ font="Century-Schoolbook-Roman", color="white")
+ .margin(top=15, opacity=0)
+ .set_position(("center","top")))
+
+title = (CompositeVideoClip([dancing_knights.to_ImageClip(), txt_title])
+ .fadein(.5)
+ .set_duration(3.5))
+
+
+# MAKE THE CREDITS SCREEN
+
+
+txt_credits = """
+CREDITS
+
+Video excerpt: Le combat en armure au XVe siècle
+By J. Donzé, D. Jaquet, T. Schmuziger,
+Université de Genève, Musée National de Moyen Age
+
+Music: "Frontier", by DOCTOR VOX
+Under licence Creative Commons
+https://www.youtube.com/user/DOCTORVOXofficial
+
+Video editing © Zulko 2014
+ Licence Creative Commons (CC BY 4.0)
+Edited with MoviePy: http://zulko.github.io/moviepy/
+"""
+
+credits = (TextClip(txt_credits, color='white',
+ font="Century-Schoolbook-Roman", fontsize=35, kerning=-2,
+ interline=-1, bg_color='black', size=title.size)
+ .set_duration(2.5)
+ .fadein(.5)
+ .fadeout(.5))
+
+
+# ASSEMBLE EVERYTHING, WRITE TO FILE
+
+final = concatenate_videoclips([title, dancing_knights, credits])
+
+final.write_videofile("dancing_knights.mp4", fps=clip.fps,
+ audio_bitrate="1000k", bitrate="4000k")
\ No newline at end of file
diff --git a/moviepy/Clip.py b/moviepy/Clip.py
index ff081ef2..1190437b 100644
--- a/moviepy/Clip.py
+++ b/moviepy/Clip.py
@@ -50,6 +50,12 @@ class Clip:
self.start = 0
self.end = None
self.duration = None
+
+ self.memoize = False
+ self.memoized_t = None
+ self.memoize_frame = None
+
+
def copy(self):
""" Shallow copy of the clip.
@@ -77,7 +83,16 @@ class Clip:
or (mono or stereo) value for a sound clip
"""
# Coming soon: smart error handling for debugging at this point
- return self.make_frame(t)
+ if self.memoize:
+ if t == self.memoized_t:
+ return self.memoized_frame
+ else:
+ frame = self.make_frame(t)
+ self.memoized_t = t
+ self.memoized_frame = frame
+ return frame
+ else:
+ return self.make_frame(t)
def fl(self, fun, apply_to=[] , keep_duration=True):
""" General processing of a clip.
@@ -291,8 +306,17 @@ class Clip:
""" Returns a copy of the clip with a new default fps for functions like
write_videofile, iterframe, etc. """
self.fps = fps
-
-
+
+
+ @outplace
+ def set_ismask(self, ismask):
+ """ Says wheter the clip is a mask or not (ismask is a boolean)"""
+ self.ismask = ismask
+
+ @outplace
+ def set_memoize(self, memoize):
+ """ Sets wheter the clip should keep the last frame read in memory """
+ self.memoize = memoize
@convert_to_seconds(['t'])
def is_playing(self, t):
diff --git a/moviepy/editor.py b/moviepy/editor.py
index b33c3e65..815f1975 100644
--- a/moviepy/editor.py
+++ b/moviepy/editor.py
@@ -79,6 +79,9 @@ for method in ["afx.audio_fadein",
exec("AudioClip.%s = %s"%( method.split('.')[1], method))
+# 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
diff --git a/moviepy/video/fx/mask_color.py b/moviepy/video/fx/mask_color.py
new file mode 100644
index 00000000..8cd30236
--- /dev/null
+++ b/moviepy/video/fx/mask_color.py
@@ -0,0 +1,23 @@
+import numpy as np
+
+def mask_color(clip, color=[0,0,0], thr=0, s=1):
+ """ Returns a new clip with a mask for transparency where the original
+ clip is of the given color.
+
+ You can also have a "progressive" mask by specifying a non-nul distance
+ threshold thr. In this case, if the distance between a pixel and the given
+ color is d, the transparency will be
+
+ d**s / (thr**s + d**s)
+ which is 1 when d>>thr and 0 for d<<thr, the stiffness of the effect being
+ parametrized by s
+ """
+
+ # code a little sloppy, it just works.
+ hill = lambda x: (1.0*(x!=0) if (thr==0) else (x**s/ (thr**s+x**s)))
+ color = np.array(color)
+ flim = lambda im: hill(np.sqrt(((im-color)**2).sum(axis=2)))
+ mask = clip.fl_image(flim)
+ mask.ismask= True
+ newclip = clip.set_mask(mask)
+ return newclip
\ No newline at end of file
diff --git a/moviepy/video/io/bindings.py b/moviepy/video/io/bindings.py
new file mode 100644
index 00000000..ac6ffa95
--- /dev/null
+++ b/moviepy/video/io/bindings.py
@@ -0,0 +1,21 @@
+"""
+This module implements all the functions to communicate with other Python
+modules (PIL, matplotlib, mayavi, etc.)
+"""
+
+import numpy as np
+
+def PIL_to_npimage(im):
+ """ Transforms a PIL/Pillow image into a numpy RGB(A) image. """
+ w,h = im.size
+ d = (4 if im.mode=="RGBA" else 3)
+ return +np.frombuffer(im.tobytes(), dtype='uint8').reshape((h,w,d))
+
+
+def mplfig_to_npimage(fig):
+ """ Updates the canvas and returns the RGB image (np array) """
+ fig.canvas.draw() # update/draw the elements
+ w,h = fig.canvas.get_width_height()
+ buf = fig.canvas.tostring_rgb()
+ image= +np.fromstring(buf,dtype=np.uint8)
+ return image.reshape(h,w,3)
\ No newline at end of file