Skip to content

Video editing with Python

Added Github ribbon, added OpenCV intalling notice in README.

Zulkod49b7670442d
diff --git a/README.rst b/README.rst
index 176e7eb4..8657fef8 100644
--- a/README.rst
+++ b/README.rst
@@ -1,7 +1,7 @@
MoviePy
========
-MoviePy is Python module for script-based movie editing, which enables
+MoviePy is a Python module for script-based movie editing, which enables
basic operations (cuts, concatenations, title insertions) to be done
in a few lines. It can also be used for advanced compositing.
@@ -24,15 +24,20 @@ A typical MoviePy script looks like that: ::
# write the result to a file in any format
video.write("myHolidays_edited.avi",fps=25, codec='DIVX')
-
-Download And Installation
---------------------------
-You can `download MoviePy`_ on Github. Just unzip everything in one folder, open a terminal and type ::
+
+Download and Installation
+----------------------------
+
+You can `download MoviePy`_ on its Github repository.
+
+
+Just unzip everything in one folder, open a terminal and type ::
sudo python setup.py install
-** This should install the python packages listed below, but NOT OpenCV, which you will have to download manually for the moment. **
+
+This should install the python packages listed below, **but NOT OpenCV**, which you will have to download and install manually (see below).
MoviePy is a very small program but it relies on many existing Python packages:
@@ -42,15 +47,46 @@ MoviePy is a very small program but it relies on many existing Python packages:
- `Scikit Image`_ for advanced image manipulation
- The Decorator_ module for better code readability
-
-
-MoviePy also needs some external software:
+MoviePy also needs some external software that you will need to install:
- ffmpeg_, for writing movies and many other useful operations.
- imageMagick_ for text generation, GIF support, and much more in the future.
All these are normally easy to install (on linux, they will certainly be in your repos).
+Installing OpenCV 2.4.6
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+That will depend on your system. It seems easy for Windows. On linux, here is what I found on the Internet:
+
+- Remove any other version of OpenCV if you installed it through a package manager.
+- Unzip the source code of `OpenCV 2.4.6`_ in some folder. open a terminal in this folder.
+- Make a new directory and go into this directory: ::
+
+ mkdir release
+ cd release
+
+- Run ``cmake``. Here is the line I used: ::
+
+ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
+
+- Run ``make``. This may take a few minutes (15 minutes on my computer). ::
+
+ make
+
+- Finally, install. ::
+
+ sudo make install
+
+And voilà !
+
+You can check if it worked by opeing a Python console and typing ::
+
+ import cv2
+ print cv2.__version__
+
+
+
.. _here: http://zulko.github.io/moviepy/
.. _`download MoviePy`: https://github.com/Zulko/moviepy
.. _`OpenCV 2.4.6`: http://sourceforge.net/projects/opencvlibrary/files/
diff --git a/docs/cookbook/blurred_face.rst b/docs/cookbook/blurred_face.rst
index 50aa3bce..5e6cf5e1 100644
--- a/docs/cookbook/blurred_face.rst
+++ b/docs/cookbook/blurred_face.rst
@@ -60,9 +60,18 @@ And the coming function makes a filter that blurs the regions around ``(fx(t),fy
x1,x2 = max(0,x-r_zone),min(x+r_zone,w)
y1,y2 = max(0,y-r_zone),min(y+r_zone,h)
reg_res = y2-y1,x2-x1
- mask = cv2.circle(np.zeros(reg_res),
- (r_zone,r_zone),r_zone,1,-1, lineType=cv2.LINE_AA)
- mask = np.dstack(3*[mask])
+
+ # We will now make a circled mask.
+ # IN older OpenCV, instead of the next two lines, write
+ # mask = cv2.circle(np.zeros(reg_res).astype('uint8'),
+ # (r_zone,r_zone),r_zone,255,-1, lineType=cv2.LINE_AA)
+ mask = np.zeros(reg_res).astype('uint8')
+ cv2.circle(mask, (r_zone,r_zone),r_zone,255,-1,
+ lineType=cv2.CV_AA)
+ #-----
+
+ mask = np.dstack(3*[(1.0/255)*mask])
+
orig = im[y1:y2,x1:x2]
blurred = cv2.blur(orig,(r_blur,r_blur))
im[y1:y2,x1:x2] = mask*blurred + (1-mask)*orig
@@ -72,6 +81,9 @@ And the coming function makes a filter that blurs the regions around ``(fx(t),fy
Finally, here is the script: ::
+ from moviepy import *
+ import pickle
+
# Because we will work with sound and we do not want to carry around
# the sound of the whole original movie, we first extract the
# interesting part of the movie (run this line only once):
diff --git a/docs/first_steps/crash_course.rst b/docs/first_steps/crash_course.rst
index 95a9e8d0..593dc92e 100644
--- a/docs/first_steps/crash_course.rst
+++ b/docs/first_steps/crash_course.rst
@@ -11,8 +11,10 @@ What is a video clip ?
A video clip is basically an object with a ``get_frame`` attribute. ``get_frame`` is a function which for a given time ``t`` returns a picture of the clip at time ``t`` (more precisely, an array of numbers representing a picture). As an example, to play a clip frame by frame, you can (but you won't have to) write something like that: ::
while t < clip.duration:
- display( clip.get_frame(t) )
- t = t + 1.0/24 # for 24 frames/second
+ picture = clip.get_frame(t) # gets the picture at time ``t``
+ imdisplay( picture ) # display the picture
+ t = t + 1.0/24 # increment time
+ time.sleep( 1.0/24 ) # wait for 1/24 seconds
A video clip has some fundamental attributes:
diff --git a/docs/first_steps/good_practice.rst b/docs/first_steps/good_practice.rst
index 21ef8ff4..ec9d8f2d 100644
--- a/docs/first_steps/good_practice.rst
+++ b/docs/first_steps/good_practice.rst
@@ -8,7 +8,13 @@ MoviePy works fine on my 1.5 petaflops supercomputer, but like for any other vid
- Use an interactive shell, like IPython or, better, the IPython notebook. If you don't know these, you don't know what you are missing !
- Prefer the clip.show() option, and use it a lot. Only use clip.preview() when really necessary.
-- If some part of your video is particularly complex and long to render, save this part as either a raw video or in directory of pictures (better, because it enables to also save the mask), then use this video instead of this part's script.
+- For the moment the audio is generated for each preview and before the preview. So if you want to preview a lengthy clip with sound, it may take a few seconds before the preview actually launches, and the sound may take lots of place in memory. Therefore, it is advised to only preview small bits of a movie with audio. Reducing the audio fps when previewing reduces the problem.
+- If some part of your video is particularly complex and long to render, save this part as either a raw video (enables to save the sound) or in a directory of pictures (enables to save the mask), then use this video instead of this part's script. ::
+
+ myVideo.to_movie('save.avi',fps=24,codec='raw', audio=True)
+ # or
+ myVideo.to_directory('./mySaveDirectory',fps=24)
+
- If you are going to use extracts of big movies with sound, do NOT write ::
# "Charade" is a 2h00 long movie
diff --git a/docs/index.rst b/docs/index.rst
index de97a92a..e37619cf 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -53,6 +53,13 @@ Indices and tables
* :ref:`search`
+.. raw:: html
+
+ <a href="https://github.com/Zulko/moviepy">
+ <img style="position: absolute; top: 0; right: 0; border: 0;"
+ src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"
+ alt="Fork me on GitHub"></a>
+
.. _Zulko: https://github.com/Zulko/
.. _Stackoverflow: http://stackoverflow.com/
diff --git a/docs/install.rst b/docs/install.rst
index d7a48501..c57539d5 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -1,12 +1,15 @@
-Download And Installation
---------------------------
+Download and Installation
+----------------------------
-You can `download MoviePy`_ on Github. Just unzip everything in one folder, open a terminal and type ::
+You can `download MoviePy`_ on its Github repository.
+
+
+Just unzip everything in one folder, open a terminal and type ::
sudo python setup.py install
-**This should install the python packages listed below, but NOT OpenCV, which you will have to download manually for the moment.**
+This should install the python packages listed below, **but NOT OpenCV**, which you will have to download and install manually (see below).
MoviePy is a very small program but it relies on many existing Python packages:
@@ -16,15 +19,50 @@ MoviePy is a very small program but it relies on many existing Python packages:
- `Scikit Image`_ for advanced image manipulation
- The Decorator_ module for better code readability
-
-
-MoviePy also needs some external software:
+MoviePy also needs some external software that you will need to install:
- ffmpeg_, for writing movies and many other useful operations.
- imageMagick_ for text generation, GIF support, and much more in the future.
All these are normally easy to install (on linux, they will certainly be in your repos).
+Installing OpenCV 2.4.6
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+That will depend on your system. It seems easy for Windows. On linux, here is what I found on the Internet:
+
+- Remove any other version of OpenCV if you installed it through a package manager.
+- Unzip the source code of `OpenCV 2.4.6`_ in some folder. open a terminal in this folder.
+- Make a new directory and go into this directory: ::
+
+ mkdir release
+ cd release
+
+- Run ``cmake``. Here is the line I used: ::
+
+ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..
+
+- Run ``make``. This may take a few minutes (15 minutes on my computer). ::
+
+ make
+
+- Finally, install. ::
+
+ sudo make install
+
+And voilà !
+
+You can check if it worked by opeing a Python console and typing ::
+
+ import cv2
+ print cv2.__version__
+
+
+
+
+
+
+
.. _`download MoviePy`: https://github.com/Zulko/moviepy
.. _`OpenCV 2.4.6`: http://sourceforge.net/projects/opencvlibrary/files/