MoviePy (full documentation here) is a Python module for script-based movie editing.
It can read and write to many formats, including animated GIFs, and enables basic operations (cuts, concatenations, title insertions) to be done in a few lines. It can also be used for advanced compositing.
A typical MoviePy script looks like that:
from moviepy.editor import * # Load myHolidays.mp4 and select the subclip 00:00:50 - 00:00:60 clip = VideoFileClip("myHolidays.mp4").subclip(50,60) # Generate a text clip (many options available ! ) txt_clip = TextClip("My Holidays 2013",fontsize=70,color='white') txt_clip = txt_clip.set_pos('center').set_duration(10) # Overlay the text clip above the first clip final_clip = CompositeVideoClip([clip, txt_clip]) # write the result to a file in any format final_clip.to_videofile("myHolidays_edited.avi",fps=25, codec='mpeg4')
MoviePy is an open-source software originally written by Zulko and released under the MIT licence. The project is hosted on Github , where everyone is welcome to contribute, ask for help or simply give feedback.
Method with pip: if you have pip
installed, just type this in a terminal (sudo is optional on some systems)
(sudo) pip install moviepy
Method by hand: download the sources, either on PyPI or (if you want the development version) on Github, unzip everything in one folder, open a terminal and type
(sudo) python setup.py install
MoviePy depends on the Python modules Numpy, Decorator, and tqdm, which will be automatically installed during MoviePy's installation.
MoviePy requires a recent version of the software ffmpeg preferably downloaded directly from the ffmpeg website.
Installed ffmpeg: when you have installed ffmpeg, or (for linux users) when you have a ffmpeg binary in the /usr/bin
folder, it will be detected automatically by MoviePy.
Non-installed ffmpeg: you can also simply place the ffmpeg binary somewhere on your computer and specify its path in the file moviepy/conf.py before installing MoviePy by hand.
ImageMagick is not strictly required, but some important features of MoviePy, like the creation of texts or animated GIFs, depend on it.
Once you have installed it, ImageMagick will be automatically detected by MoviePy, except on Windows !. Windows user, before installing MoviePy by hand, go into the moviepy/conf.py
file and provide the path to the ImageMagick binary called convert. It should look like this
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\convert.exe"
PyGame is needed for video and sound previews (useless if you intend to work with MoviePy on a server but really essential for advanced video editing by hand).
For advanced image processing you will need one or several of these packages. For instance using the method clip.resize
requires that at least one of Scipy, PIL, Pillow or OpenCV are installed.
- The Python Imaging Library (PIL) or, better, its branch Pillow .
- Scipy (for tracking, segmenting, etc.), and can be used for resizing video clips if PIL and OpenCV aren't installed on your computer.
- Scikit Image may be needed for some advanced image manipulation.
- OpenCV 2.4.6 (provides the package
cv2
) or more recent may be needed for some advanced image manipulation.