Video editing with Python
MoviePy now uses imageio for FFMPEG downloads and GIF writing.
Zulko5b8b686bf593
diff --git a/CHANGES.txt b/CHANGES.txtdeleted file mode 100644index d5aa3c02..00000000--- a/CHANGES.txt+++ /dev/null@@ -1 +0,0 @@-v0.1.0, 08/2013 -- Initial release.diff --git a/README.rst b/README.rstindex 2bf28948..0c059b9c 100644--- a/README.rst+++ b/README.rst@@ -55,30 +55,20 @@ If you have neither ``setuptools`` nor ``ez_setup`` installed the command above(sudo) python setup.py install-MoviePy depends on the Python modules Numpy_, Decorator_, and tqdm_, which will be automatically installed during MoviePy's installation. It should work on Windows/Mac/Linux, with Python 2.7+ and 3 ; if you have trouble installing MoviePy or one of its dependencies, please provide feedback !--Linking to ffmpeg-~~~~~~~~~~~~~~~~~~--MoviePy requires a **recent version** of the software ffmpeg_ preferably downloaded **directly from the ffmpeg website**.+MoviePy depends on the Python modules Numpy_, imageio_, Decorator_, and tqdm_, which will be automatically installed during MoviePy's installation. It should work on Windows/Mac/Linux, with Python 2.7+ and 3 ; if you have trouble installing MoviePy or one of its dependencies, please provide feedback !-**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.+MoviePy depends on the software FFMPEG for video reading and writing, but you don't need to worry about that, as FFMPEG should be automatically downloaded/installed by ImageIO during your first use of MoviePy (it takes a few seconds). If you want to use a specific version of FFMPEG, follow the instructions in file ``config_defaults.py``.-**Non-installed ffmpeg:** you can also simply place the ffmpeg binary somewhere on your computer and specify its path in the file `moviepy/config_defaults.py` before installing MoviePy by hand.-Linking to ImageMagick-~~~~~~~~~~~~~~~~~~~~~~~~+Other optional but useful dependencies+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-ImageMagick_ is not strictly required, but some important features of MoviePy, like the creation of texts or animated GIFs, depend on it.+ImageMagick_ is not strictly required, only if you want to write texts. It can also be used as a backend for GIFs but you can do GIFs with MoviePy without ImageMagick.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/config_defaults.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"--Other optional but useful dependencies-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-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.@@ -86,7 +76,7 @@ For advanced image processing you will need one or several of these packages. Fo- 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.+- `OpenCV 2.4.6`_ or more recent (provides the package ``cv2``) or more recent may be needed for some advanced image manipulation... _gallery: http://zulko.github.io/moviepy/gallery.html@@ -101,6 +91,7 @@ For advanced image processing you will need one or several of these packages. Fo.. _`OpenCV 2.4.6`: http://sourceforge.net/projects/opencvlibrary/files/.. _Pygame: http://www.pygame.org/download.shtml.. _Numpy: http://www.scipy.org/install.html+.. _imageio: http://imageio.github.io/.. _`Scikit Image`: http://scikit-image.org/download.html.. _Decorator: https://pypi.python.org/pypi/decorator.. _tqdm: https://github.com/noamraph/tqdmdiff --git a/docs/install.rst b/docs/install.rstindex 131b39de..c72be198 100644--- a/docs/install.rst+++ b/docs/install.rst@@ -3,10 +3,11 @@Download and Installation==========================+Installation---------------**Method with pip:** if you have ``pip`` installed, just type this in a terminal (sudo is optional on some systems) ::+**Method with pip:** if you have ``pip`` installed, just type this in a terminal (it will install ez_setup if you don't already have it) ::(sudo) pip install moviepy@@ -18,39 +19,28 @@ If you have neither ``setuptools`` nor ``ez_setup`` installed the command above(sudo) python setup.py install-MoviePy depends on the Python modules Numpy_, Decorator_, and tqdm_, which will be automatically installed during MoviePy's installation.---Linking to ffmpeg-~~~~~~~~~~~~~~~~~~+MoviePy depends on the Python modules Numpy_, imageio_, Decorator_, and tqdm_, which will be automatically installed during MoviePy's installation. It should work on Windows/Mac/Linux, with Python 2.7+ and 3 ; if you have trouble installing MoviePy or one of its dependencies, please provide feedback !-MoviePy requires a **recent version** of the software ffmpeg_ preferably downloaded **directly from the ffmpeg website**.+MoviePy depends on the software FFMPEG for video reading and writing. You don't need to worry about that, as FFMPEG should be automatically downloaded/installed by ImageIO during your first use of MoviePy (it takes a few seconds). If you want to use a specific version of FFMPEG, follow the instructions in file ``config_defaults.py``.-**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/config_defaults.py` before installing MoviePy by hand.--Linking to ImageMagick-~~~~~~~~~~~~~~~~~~~~~~~~+Other optional but useful dependencies+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-ImageMagick_ is not strictly required, but some important features of MoviePy, like the creation of texts or animated GIFs, depend on it.+ImageMagick_ is not strictly required, only if you want to write texts. It can also be used as a backend for GIFs but you can do GIFs with MoviePy without ImageMagick.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/config_defaults.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"--Other optional but useful dependencies------------------------------------------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 ``clip.resize`` requires that at least one of Scipy, PIL, Pillow or OpenCV are installed.+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. See :ref:`opencv`.+- `OpenCV 2.4.6`_ or more recent (provides the package ``cv2``) or more recent may be needed for some advanced image manipulation.If you are on linux, these softwares will surely be in your repos.@@ -63,7 +53,7 @@ If you are on linux, these softwares will surely be in your repos... _imageMagick: http://www.imagemagick.org/script/index.php.. _Pygame: http://www.pygame.org/download.shtml-+.. _imageio: http://imageio.github.io/.. _Pillow: http://pillow.readthedocs.org/en/latest/.. _Scipy: http://www.scipy.org/diff --git a/moviepy/config.py b/moviepy/config.pyindex 81bd5424..403b2fdc 100644--- a/moviepy/config.py+++ b/moviepy/config.py@@ -27,8 +27,11 @@ def try_cmd(cmd):else:return True, None+if FFMPEG_BINARY=='ffmpeg-imageio':+ from imageio.plugins.ffmpeg import get_exe+ FFMPEG_BINARY = get_exe()-if FFMPEG_BINARY=='auto-detect':+elif FFMPEG_BINARY=='auto-detect':if try_cmd(['ffmpeg'])[0]:FFMPEG_BINARY = 'ffmpeg'@@ -42,6 +45,8 @@ else:raise IOError(err.message +"The path specified for the ffmpeg binary might be wrong")++if IMAGEMAGICK_BINARY=='auto-detect':if try_cmd(['convert'])[0]:diff --git a/moviepy/config_defaults.py b/moviepy/config_defaults.pyindex aedc058b..8ab73cb4 100644--- a/moviepy/config_defaults.py+++ b/moviepy/config_defaults.py@@ -1,27 +1,36 @@"""-Configuration MoviePy+Configuration of MoviePyThis file enables you to specify a configuration for MoviePy. Inparticular you can enter the path to the FFMPEG and ImageMagickbinaries.-Note that at any time in a script you can change the value of these-variables as follows:+These changes must be done BEFORE installing MoviePy: first make the changes,+then install MoviePy with++ [sudo] python setup.py install++Note that you can also change the path to the binaries AFTER installation, but+only for one script at a time, as follows:>>> import moviepy.config as cf>>> cf.change_settings({"FFMPEG_BINARY": "some/new/path/to/ffmpeg"})>>> print( cf.get_setting("FFMPEG_BINARY") ) # prints the current setting+Instructions---------------FFMPEG_BINARY- Normally you can leave this one to its default ('auto-detect') and MoviePy- will detect automatically the right name, which will be either- 'ffmpeg' (on linux) or 'ffmpeg.exe' (on windows). If you want to- use a binary at a special location on you disk, enter it like that:+ Normally you can leave this one to its default ('ffmpeg-imageio') at which+ case image-io will download the right ffmpeg binary (at first use) and then+ always use that binary.+ The second option is 'auto-detect', in this case ffmpeg will be whatever+ binary is found on the computer generally 'ffmpeg' (on linux) or 'ffmpeg.exe'+ (on windows).+ Third option: If you want to use a binary at a special location on you disk,+ enter it like that:FFMPEG_BINARY = r"path/to/ffmpeg" # on linuxFFMPEG_BINARY = r"path\to\ffmpeg.exe" # on windows@@ -38,5 +47,5 @@ IMAGEMAGICK_BINARY"""-FFMPEG_BINARY = 'auto-detect'+FFMPEG_BINARY = 'ffmpeg-imageio'IMAGEMAGICK_BINARY = 'convert'\ No newline at end of filediff --git a/moviepy/decorators.py b/moviepy/decorators.pyindex d343fb93..e73756a2 100644--- a/moviepy/decorators.py+++ b/moviepy/decorators.py@@ -9,13 +9,14 @@ from moviepy.tools import cvsecs@decorator.decoratordef outplace(f, clip, *a, **k):- """ Enables to make operations outplace """+ """ Applies f(clip.copy(), *a, **k) and returns clip.copy()"""newclip = clip.copy()f(newclip, *a, **k)return newclip-+@decorator.decoratordef convert_masks_to_RGB(f, clip, *a, **k):+ """ If the clip is a mask, convert it to RGB before running the function """if clip.ismask:clip = clip.to_RGB()return f(clip, *a, **k)@@ -72,8 +73,9 @@ def audio_video_fx(f, clip, *a, **k):return f(clip, *a, **k)def preprocess_args(fun,varnames):+ """ Applies fun to variables in varnames before launching the function """- def warper(f, *a, **kw):+ def wrapper(f, *a, **kw):if hasattr(f, "func_code"):func_code = f.func_code # Python 2else:@@ -85,7 +87,7 @@ def preprocess_args(fun,varnames):new_kw = {k: fun(v) if k in varnames else vfor (k,v) in kw.items()}return f(*new_a, **new_kw)- return decorator.decorator(warper)+ return decorator.decorator(wrapper)def convert_to_seconds(varnames):@@ -105,6 +107,7 @@ def add_mask_if_none(f, clip, *a, **k):@decorator.decoratordef use_clip_fps_by_default(f, clip, *a, **k):+ """ Will use clip.fps if no fps=... is provided in **k """def fun(fps):if fps is not None:diff --git a/moviepy/version.py b/moviepy/version.pyindex b5fdc753..e0f354da 100644--- a/moviepy/version.py+++ b/moviepy/version.py@@ -1 +1 @@-__version__ = "0.2.2"+__version__ = "0.2.2.01"diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 412d0816..ea4b6822 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -404,8 +404,8 @@ class VideoClip(Clip):@requires_duration@convert_masks_to_RGB- def write_gif(self, filename, fps=None, program='ImageMagick',- opt="OptimizeTransparency", fuzz=1, verbose=True,+ def write_gif(self, filename, fps=None, program='imageio',+ opt='wu', fuzz=1, verbose=True,loop=0, dispose=False, colors=None, tempfiles=False):""" Write the VideoClip to a GIF file.@@ -425,12 +425,13 @@ class VideoClip(Clip):``fps`` attribute (VideoFileClip, for instance, have one).program- Software to use for the conversion, either 'ImageMagick' or- 'ffmpeg'.+ Software to use for the conversion, either 'imageio' (this will use+ the library FreeImage through ImageIO), or 'ImageMagick', or 'ffmpeg'.opt- (ImageMagick only) optimalization to apply, either- 'optimizeplus' or 'OptimizeTransparency'.+ Optimalization to apply. If program='imageio', opt must be either 'wu'+ (Wu) or 'nq' (Neuquant). If program='ImageMagick',+ either 'optimizeplus' or 'OptimizeTransparency'.fuzz(ImageMagick only) Compresses the GIF by considering that@@ -449,6 +450,10 @@ class VideoClip(Clip):>>> myClip.speedx(0.5).to_gif('myClip.gif')"""++ # A little sketchy at the moment, maybe move all that in write_gif,+ # refactor a little... we will see.+if program == 'imageio':write_gif_with_image_io(self, filename, fps=fps, opt=opt, loop=loop,verbose=verbose, colors=colors)diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.pyindex 1dcd2220..a973471c 100644--- a/moviepy/video/io/ffmpeg_writer.py+++ b/moviepy/video/io/ffmpeg_writer.py@@ -184,7 +184,9 @@ class FFMPEG_VideoWriter:def ffmpeg_write_video(clip, filename, fps, codec="libx264", bitrate=None,preset="medium", withmask=False, write_logfile=False,audiofile=None, verbose=True, threads=None, ffmpeg_params=None):-+ """ Write the clip to a videofile. See VideoClip.write_videofile for details+ on the parameters.+ """if write_logfile:logfile = open(filename + ".log", 'w+')else:diff --git a/setup.py b/setup.pyindex cb700a0d..81ba551e 100644--- a/setup.py+++ b/setup.py@@ -15,8 +15,6 @@ except ImportError:from setuptools import setup, find_packages-from setuptools import setup, find_packages-exec(open('moviepy/version.py').read()) # loads __version__setup(name='moviepy',@@ -27,4 +25,4 @@ setup(name='moviepy',license='see LICENSE.txt',keywords="video editing audio compositing numpy ffmpeg ",packages= find_packages(exclude='docs'),- install_requires= ['numpy', 'decorator', 'tqdm'])+ install_requires= ['numpy', 'decorator', 'imageio', 'tqdm'])