Skip to content

Video editing with Python

New configuration management. made FFMPEG_BINARY etc. modifiable at runtime.

Zulko7c1b0372e60a
diff --git a/README.rst b/README.rst
index 021ed89c..b0cc694d 100644
--- a/README.rst
+++ b/README.rst
@@ -53,14 +53,14 @@ MoviePy requires a **recent version** of the software ffmpeg_ preferably downloa
**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.
+**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
~~~~~~~~~~~~~~~~~~~~~~~~
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 ::
+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"
diff --git a/docs/install.rst b/docs/install.rst
index 74b91da3..d8e6feff 100644
--- a/docs/install.rst
+++ b/docs/install.rst
@@ -22,14 +22,14 @@ MoviePy requires a **recent version** of the software ffmpeg_ preferably downloa
**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.
+**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
~~~~~~~~~~~~~~~~~~~~~~~~
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 ::
+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"
diff --git a/moviepy/audio/io/ffmpeg_audiowriter.py b/moviepy/audio/io/ffmpeg_audiowriter.py
index a05dc182..45bbb477 100644
--- a/moviepy/audio/io/ffmpeg_audiowriter.py
+++ b/moviepy/audio/io/ffmpeg_audiowriter.py
@@ -9,7 +9,7 @@ except ImportError:
DEVNULL = open(os.devnull, 'wb')
from tqdm import tqdm
-from moviepy.conf import FFMPEG_BINARY
+from moviepy.config import get_setting
from moviepy.decorators import requires_duration
from moviepy.tools import verbose_print
@@ -54,7 +54,7 @@ class FFMPEG_AudioWriter:
if logfile is None:
logfile = sp.PIPE
- cmd = ([ FFMPEG_BINARY, '-y',
+ cmd = ([ get_setting("FFMPEG_BINARY"), '-y',
"-loglevel", "error" if logfile==sp.PIPE else "info",
"-f", 's%dle'%(8*nbytes),
"-acodec",'pcm_s%dle'%(8*nbytes),
diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.py
index 896860ba..0cad5aac 100644
--- a/moviepy/audio/io/readers.py
+++ b/moviepy/audio/io/readers.py
@@ -5,7 +5,7 @@ import numpy as np
from moviepy.tools import cvsecs
from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
-from moviepy.conf import FFMPEG_BINARY
+from moviepy.config import get_setting
import os
try:
@@ -85,7 +85,7 @@ class FFMPEG_AudioReader:
i_arg = [ '-i', self.filename, '-vn']
- cmd = ([FFMPEG_BINARY] + i_arg +
+ cmd = ([get_setting("FFMPEG_BINARY")] + i_arg +
[ '-loglevel', 'error',
'-f', self.f,
'-acodec', self.acodec,
diff --git a/moviepy/conf.py b/moviepy/conf.py
deleted file mode 100644
index 796828bb..00000000
--- a/moviepy/conf.py
+++ /dev/null
@@ -1,82 +0,0 @@
-"""
-Configuration MoviePy
-
-
-This file enables you to specify a configuration for MoviePy. In
-particular you can enter the path to the FFMPEG and ImageMagick
-binaries.
-
-Instructions
---------------
-
-
-FFMPEG_BINARY
- Normally you can leave this one to its default (None) 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:
-
- FFMPEG_BINARY = r"path/to/ffmpeg(.exe)"
-
- Warning: the 'r' before the path is important, especially on Windows.
-
-
-IMAGEMAGICK_BINARY
- For linux users, 'convert' should be fine.
- For Windows users, you must specify the path to the ImageMagick
- 'convert' binary. For instance:
-
- IMAGEMAGICK_BINARY = r"C:\Program Files\ImageMagick-6.8.8-Q16\convert.exe"
-
-You can run this file to check that FFMPEG has been detected.
-"""
-
-FFMPEG_BINARY = None
-IMAGEMAGICK_BINARY = 'convert'
-
-import os
-try:
- from subprocess import DEVNULL # py3k
-except ImportError:
- DEVNULL = open(os.devnull, 'wb')
-
-# =====================================================================
-# CODE. Don't write anything below this line !
-
-import subprocess as sp
-
-def try_cmd(cmd):
- try:
- popen_params = {"stdout": sp.PIPE,
- "stderr": sp.PIPE,
- "stdin": DEVNULL}
-
- if os.name == "nt":
- popen_params["creationflags"] = 0x08000000
-
- proc = sp.Popen(cmd, **popen_params)
- proc.communicate()
- except:
- return False
- else:
- return True
-
-
-if FFMPEG_BINARY is None:
-
- if try_cmd(['ffmpeg']):
- FFMPEG_BINARY = 'ffmpeg'
- elif try_cmd(['ffmpeg.exe']):
- FFMPEG_BINARY = 'ffmpeg.exe'
- else:
- print ("FFMPEG binary not found. Try installing MoviePy"
- " manually and specify the path to the binary in"
- " the file conf.py")
-
-if __name__ == "__main__":
- if try_cmd([FFMPEG_BINARY]):
- print( "MoviePy : ffmpeg successfully found." )
- else:
- print( "MoviePy : can't find ffmpeg." )
-
-
diff --git a/moviepy/config.py b/moviepy/config.py
new file mode 100644
index 00000000..6dcd46de
--- /dev/null
+++ b/moviepy/config.py
@@ -0,0 +1,82 @@
+import os
+import subprocess as sp
+try:
+ from subprocess import DEVNULL # py3k
+except ImportError:
+ DEVNULL = open(os.devnull, 'wb')
+
+from config_defaults import (FFMPEG_BINARY, IMAGEMAGICK_BINARY)
+
+def try_cmd(cmd):
+ try:
+ popen_params = {"stdout": sp.PIPE,
+ "stderr": sp.PIPE,
+ "stdin": DEVNULL}
+
+ # This was added so that no extra unwanted window opens on windows
+ # when the child process is created
+ if os.name == "nt":
+ popen_params["creationflags"] = 0x08000000
+
+ proc = sp.Popen(cmd, **popen_params)
+ proc.communicate()
+ except Exception as err:
+ return False, err
+ else:
+ return True, None
+
+
+if FFMPEG_BINARY=='auto-detect':
+
+ if try_cmd(['ffmpeg'])[0]:
+ FFMPEG_BINARY = 'ffmpeg'
+ elif try_cmd(['ffmpeg.exe'])[0]:
+ FFMPEG_BINARY = 'ffmpeg.exe'
+ else:
+ FFMPEG_BINARY = 'unset'
+else:
+ success, err = try_cmd(cmd)
+ if not success:
+ raise err
+
+if IMAGEMAGICK_BINARY=='auto-detect':
+
+ if try_cmd(['convert'])[0]:
+ IMAGEMAGICK_BINARY = 'convert'
+ else:
+ IMAGEMAGICK_BINARY = 'unset'
+
+
+
+def get_setting(varname):
+ """ Returns the value of a configuration variable. """
+ gl = globals()
+ if varname not in gl.keys():
+ raise ValueError("Unknown setting %s"%varname)
+ # Here, possibly add some code to raise exceptions if some
+ # parameter isn't set set properly, explaining on how to set it.
+ return gl[varname]
+
+
+def change_settings(new_settings={}, file=None):
+ """ Changes the value of configuration variables."""
+ gl = globals()
+ if file is not None:
+ execfile(file)
+ gl.update(locals())
+ gl.update(new_settings)
+ # Here you can add some code to check that the new configuration
+ # values are valid.
+
+if __name__ == "__main__":
+ if try_cmd([FFMPEG_BINARY])[0]:
+ print( "MoviePy : ffmpeg successfully found." )
+ else:
+ print( "MoviePy : can't find or access ffmpeg." )
+
+ if try_cmd([IMAGEMAGICK_BINARY])[0]:
+ print( "MoviePy : ImageMagick successfully found." )
+ else:
+ print( "MoviePy : can't find or access ImageMagick." )
+
+
diff --git a/moviepy/config_defaults.py b/moviepy/config_defaults.py
new file mode 100644
index 00000000..06226057
--- /dev/null
+++ b/moviepy/config_defaults.py
@@ -0,0 +1,42 @@
+"""
+Configuration MoviePy
+
+
+This file enables you to specify a configuration for MoviePy. In
+particular you can enter the path to the FFMPEG and ImageMagick
+binaries.
+
+Note that at any time in a script you can change the value of these
+variables as follows:
+
+>>> import moviepy.config as cf
+>>> cf.change_setting({"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:
+
+ FFMPEG_BINARY = r"path/to/ffmpeg" # on linux
+ FFMPEG_BINARY = r"path\to\ffmpeg.exe" # on windows
+
+ Warning: the 'r' before the path is important, especially on Windows.
+
+
+IMAGEMAGICK_BINARY
+ For linux users, 'convert' should be fine.
+ For Windows users, you must specify the path to the ImageMagick
+ 'convert' binary. For instance:
+
+ IMAGEMAGICK_BINARY = r"C:\Program Files\ImageMagick-6.8.8-Q16\convert.exe"
+
+"""
+
+FFMPEG_BINARY = 'auto-detect'
+IMAGEMAGICK_BINARY = 'convert'
\ No newline at end of file
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 7ff3e977..c5af1558 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -26,7 +26,7 @@ from .io.gif_writers import write_gif, write_gif_with_tempfiles
from .tools.drawing import blit
from ..Clip import Clip
-from ..conf import FFMPEG_BINARY, IMAGEMAGICK_BINARY
+from ..config import get_setting
from ..tools import (subprocess_call,
verbose_print,
@@ -1040,7 +1040,7 @@ class TextClip(ImageClip):
size = ('' if size[0] is None else str(size[0]),
'' if size[1] is None else str(size[1]))
- cmd = ( [IMAGEMAGICK_BINARY,
+ cmd = ( [get_setting("IMAGEMAGICK_BINARY"),
"-background", bg_color,
"-fill", color,
"-font", font])
@@ -1068,8 +1068,18 @@ class TextClip(ImageClip):
if print_cmd:
print( " ".join(cmd) )
-
- subprocess_call(cmd, verbose=False )
+
+ try:
+ subprocess_call(cmd, verbose=False )
+ except (IOError,OSError) as err:
+ error = ("MoviePy Error: creation of %s failed because "
+ "of the following error:\n\n%s.\n\n."%(filename, str(err))
+ + ("This error can be due to the fact that "
+ "ImageMagick is not installed on your computer, or "
+ "(for Windows users) that you didn't specify the "
+ "path to the ImageMagick binary in file conf.py, or."
+ "that the path you specified is incorrect" ))
+ raise IOError(error)
ImageClip.__init__(self, tempfilename, transparent=transparent)
self.txt = txt
@@ -1096,7 +1106,8 @@ class TextClip(ImageClip):
if os.name == "nt":
popen_params["creationflags"] = 0x08000000
- process = sp.Popen([IMAGEMAGICK_BINARY, '-list', arg], **popen_params)
+ process = sp.Popen([get_setting("IMAGEMAGICK_BINARY"),
+ '-list', arg], **popen_params)
result = process.communicate()[0]
lines = result.splitlines()
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index 160aba50..3f830f11 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -9,7 +9,7 @@ import subprocess as sp
import re
import numpy as np
-from moviepy.conf import FFMPEG_BINARY # ffmpeg, ffmpeg.exe, etc...
+from moviepy.config import get_setting # ffmpeg, ffmpeg.exe, etc...
from moviepy.tools import cvsecs
import os
@@ -66,7 +66,7 @@ class FFMPEG_VideoReader:
i_arg = [ '-i', self.filename]
- cmd = ([FFMPEG_BINARY]+ i_arg +
+ cmd = ([get_setting("FFMPEG_BINARY")]+ i_arg +
['-loglevel', 'error',
'-f', 'image2pipe',
"-pix_fmt", self.pix_fmt,
@@ -211,7 +211,7 @@ def ffmpeg_parse_infos(filename, print_infos=False, check_duration=True):
# open the file in a pipe, provoke an error, read output
is_GIF = filename.endswith('.gif')
- cmd = [FFMPEG_BINARY, "-i", filename]
+ cmd = [get_setting("FFMPEG_BINARY"), "-i", filename]
if is_GIF:
cmd += ["-f", "null", "/dev/null"]
diff --git a/moviepy/video/io/ffmpeg_tools.py b/moviepy/video/io/ffmpeg_tools.py
index 09ac330b..b3a7c2ae 100644
--- a/moviepy/video/io/ffmpeg_tools.py
+++ b/moviepy/video/io/ffmpeg_tools.py
@@ -5,7 +5,7 @@ import sys
import subprocess as sp
from moviepy.tools import subprocess_call
-from moviepy.conf import FFMPEG_BINARY
+from moviepy.config import get_setting
def ffmpeg_movie_from_frames(filename, folder, fps, digits=6):
@@ -14,7 +14,7 @@ def ffmpeg_movie_from_frames(filename, folder, fps, digits=6):
Almost deprecated.
"""
s = "%" + "%02d" % digits + "d.png"
- cmd = [FFMPEG_BINARY, "-y", "-f","image2",
+ cmd = [get_setting("FFMPEG_BINARY"), "-y", "-f","image2",
"-r", "%d"%fps,
"-i", os.path.join(folder,folder) + '/' + s,
"-b", "%dk"%bitrate,
@@ -32,7 +32,7 @@ def ffmpeg_extract_subclip(filename, t1, t2, targetname=None):
T1, T2 = [int(1000*t) for t in [t1, t2]]
targetname = name+ "%sSUB%d_%d.%s"(name, T1, T2, ext)
- cmd = [FFMPEG_BINARY,"-y",
+ cmd = [get_setting("FFMPEG_BINARY"),"-y",
"-i", filename,
"-ss", "%0.2f"%t1,
"-t", "%0.2f"%(t2-t1),
@@ -46,7 +46,7 @@ def ffmpeg_merge_video_audio(video,audio,output, vcodec='copy',
verbose = True):
""" merges video file ``video`` and audio file ``audio`` into one
movie file ``output``. """
- cmd = [FFMPEG_BINARY, "-y", "-i", audio,"-i", video,
+ cmd = [get_setting("FFMPEG_BINARY"), "-y", "-i", audio,"-i", video,
"-vcodec", vcodec, "-acodec", acodec, output]
subprocess_call(cmd, verbose = verbose)
@@ -54,7 +54,7 @@ def ffmpeg_merge_video_audio(video,audio,output, vcodec='copy',
def ffmpeg_extract_audio(inputfile,output,bitrate=3000,fps=44100):
""" extract the sound from a video file and save it in ``output`` """
- cmd = [FFMPEG_BINARY, "-y", "-i", inputfile, "-ab", "%dk"%bitrate,
+ cmd = [get_setting("FFMPEG_BINARY"), "-y", "-i", inputfile, "-ab", "%dk"%bitrate,
"-ar", "%d"%fps, output]
subprocess_call(cmd)
@@ -62,7 +62,7 @@ def ffmpeg_extract_audio(inputfile,output,bitrate=3000,fps=44100):
def ffmpeg_resize(video,output,size):
""" resizes ``video`` to new size ``size`` and write the result
in file ``output``. """
- cmd= [FFMPEG_BINARY, "-i", video, "-vf", "scale=%d:%d"%(res[0], res[1]),
+ cmd= [get_setting("FFMPEG_BINARY"), "-i", video, "-vf", "scale=%d:%d"%(res[0], res[1]),
output]
subprocess_call(cmd)
diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.py
index 8a07ee69..85f5e725 100644
--- a/moviepy/video/io/ffmpeg_writer.py
+++ b/moviepy/video/io/ffmpeg_writer.py
@@ -16,7 +16,7 @@ except ImportError:
from tqdm import tqdm
-from moviepy.conf import FFMPEG_BINARY
+from moviepy.config import get_setting
from moviepy.tools import verbose_print
@@ -86,7 +86,7 @@ class FFMPEG_VideoWriter:
self.ext = self.filename.split(".")[-1]
cmd = (
- [ FFMPEG_BINARY, '-y']
+ [ get_setting("FFMPEG_BINARY"), '-y']
+["-loglevel", "error" if logfile==sp.PIPE else "info",
"-f", 'rawvideo',
"-vcodec","rawvideo",
@@ -97,7 +97,7 @@ class FFMPEG_VideoWriter:
+ (["-i", audiofile, "-acodec", "copy"] if (audiofile is not None) else [])
+['-vcodec', codec,
'-preset', preset]
- + (['-b:v', bitrate] if (bitrate!=None) else [])
+ + (['-b:v', bitrate] if (bitrate is not None) else [])
+ (["-threads", str(threads)] if threads is not None else [])
# http://trac.ffmpeg.org/ticket/658
+ (['-pix_fmt', 'yuv420p']
@@ -107,13 +107,14 @@ class FFMPEG_VideoWriter:
else [])
+ [ '-r', "%.02f"%fps, filename ]
- #+ (["-acodec", "copy"] if (audiofile is not None) else [])
)
popen_params = {"stdout": DEVNULL,
"stderr": logfile,
"stdin": sp.PIPE}
-
+
+ # This was added so that no extra unwanted window opens on windows
+ # when the child process is created
if os.name == "nt":
popen_params["creationflags"] = 0x08000000
@@ -207,7 +208,7 @@ def ffmpeg_write_image(filename, image, logfile=False):
ffmpeg. """
- cmd = [ FFMPEG_BINARY, '-y',
+ cmd = [ get_setting("FFMPEG_BINARY"), '-y',
'-s', "%dx%d"%(image.shape[:2][::-1]),
"-f", 'rawvideo',
'-pix_fmt', "rgba" if (image.shape[2] == 4) else "rgb24",
diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.py
index 727f86ad..f2dc0120 100644
--- a/moviepy/video/io/gif_writers.py
+++ b/moviepy/video/io/gif_writers.py
@@ -1,7 +1,7 @@
import os
import subprocess as sp
from tqdm import tqdm
-from moviepy.conf import FFMPEG_BINARY, IMAGEMAGICK_BINARY
+from moviepy.config import get_setting
from moviepy.decorators import requires_duration
from moviepy.tools import verbose_print, subprocess_call
import numpy as np
@@ -52,7 +52,7 @@ def write_gif_with_tempfiles(clip, filename, fps=None, program= 'ImageMagick',
if program == "ImageMagick":
- cmd = [IMAGEMAGICK_BINARY,
+ cmd = [get_setting("IMAGEMAGICK_BINARY"),
'-delay' , '%d'%delay,
"-dispose" ,"%d"%(2 if dispose else 1),
"-loop" , "%d"%loop,
@@ -65,7 +65,7 @@ def write_gif_with_tempfiles(clip, filename, fps=None, program= 'ImageMagick',
elif program == "ffmpeg":
- cmd = [FFMPEG_BINARY, '-y',
+ cmd = [get_setting("FFMPEG_BINARY"), '-y',
'-f', 'image2', '-r',str(fps),
'-i', fileName+'_GIFTEMP%04d.png',
'-r',str(fps),
@@ -74,13 +74,13 @@ def write_gif_with_tempfiles(clip, filename, fps=None, program= 'ImageMagick',
try:
subprocess_call( cmd, verbose = verbose )
- except IOError as err:
+ except (IOError,OSError) as err:
error = ("MoviePy Error: creation of %s failed because "
"of the following error:\n\n%s.\n\n."%(filename, str(err)))
if program == "ImageMagick":
- error = error + ("This can be due to the fact that "
+ error = error + ("This error can be due to the fact that "
"ImageMagick is not installed on your computer, or "
"(for Windows users) that you didn't specify the "
"path to the ImageMagick binary in file conf.py." )
@@ -157,7 +157,7 @@ def write_gif(clip, filename, fps=None, program= 'ImageMagick',
fps=clip.fps
delay= 100.0/fps
- cmd1 = [FFMPEG_BINARY, '-y', '-loglevel', 'error',
+ cmd1 = [get_setting("FFMPEG_BINARY"), '-y', '-loglevel', 'error',
'-f', 'rawvideo',
'-vcodec','rawvideo', '-r', "%.02f"%fps,
'-s', "%dx%d"%(clip.w, clip.h), '-pix_fmt', 'rgb24',
@@ -186,7 +186,7 @@ def write_gif(clip, filename, fps=None, program= 'ImageMagick',
if program == 'ImageMagick':
- cmd2 = [IMAGEMAGICK_BINARY, '-delay', "%.02f"%(delay),
+ cmd2 = [get_setting("IMAGEMAGICK_BINARY"), '-delay', "%.02f"%(delay),
"-dispose" ,"%d"%(2 if dispose else 1),
'-loop', '%d'%loop, '-', '-coalesce']
@@ -202,7 +202,7 @@ def write_gif(clip, filename, fps=None, program= 'ImageMagick',
if opt:
- cmd3 = [IMAGEMAGICK_BINARY, '-', '-layers', opt,
+ cmd3 = [get_setting("IMAGEMAGICK_BINARY"), '-', '-layers', opt,
'-fuzz', '%d'%fuzz+'%'
]+(["-colors", "%d"%colors] if colors is not None else [])+[
filename]
diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.py
index 5a91c4c0..f1d5d433 100644
--- a/moviepy/video/io/html_tools.py
+++ b/moviepy/video/io/html_tools.py
@@ -144,6 +144,7 @@ def html_embed(clip, filetype=None, maxduration=60, rd_kwargs=None,
return template%{'data':data, 'options':options, 'ext':ext}
+
def ipython_display(clip, filetype=None, maxduration=60, rd_kwargs=None,
**html_kwargs):
"""
diff --git a/moviepy/video/io/imageMagick_tools.py b/moviepy/video/io/imageMagick_tools.py
deleted file mode 100644
index e4273d72..00000000
--- a/moviepy/video/io/imageMagick_tools.py
+++ /dev/null
@@ -1,35 +0,0 @@
-""" Operations with ImageMagick. Still in the making."""
-
-import os
-import subprocess
-from moviepy.tools import subprocess_call
-
-def gif_to_directory(gif_file,dirName=None):
- """
-
- POSSIBLY VERY DEPRECATED AND BUGGY
-
- Stores all the frames of the given .gif file
- into the directory ``dirName``. If ``dirName``
- is not provided, the directory has the same name
- as the .gif file. Supports transparency.
- Returns the directory name.
-
- Example:
-
- >>> d = gif_to_directory("animated-earth.gif")
- >>> clip = DirectoryClip(d,fps=3)
-
- """
-
- if dirName is None:
- name, ext = os.path.splitext(gif_file)
- dirName = name
-
- try:
- os.mkdir(dirName)
- except:
- pass
-
- subprocess_call(["convert", "-coalesce", gif_file,
- os.path.join(dirName,"%04d.png")])
diff --git a/moviepy/video/io/ipython_display.py b/moviepy/video/io/ipython_display.py
deleted file mode 100644
index 39a59dfb..00000000
--- a/moviepy/video/io/ipython_display.py
+++ /dev/null
@@ -1,135 +0,0 @@
-"""
-This module implements ipython_display
-A function to embed images/videos/audio in the IPython Notebook
-"""
-
-# Notes:
-# All media are physically embedded in the IPython Notebook
-# (instead of simple links to the original files)
-# That is because most browsers use a cache system and they won't
-# properly refresh the media when the original files are changed.
-
-import os
-from base64 import b64encode
-from moviepy.tools import extensions_dict
-
-try:
- from IPython.display import HTML
- ipython_available = True
-except ImportError:
- ipython_available = False
-
-from .ffmpeg_reader import ffmpeg_parse_infos
-
-sorry = "Sorry, seems like your browser doesn't support HTML5 audio/video"
-templates = {"audio":("<center><audio controls>"
- "<source %(options)s src='data:audio/%(ext)s;base64,%(data)s'>"
- +sorry+"</audio></center>"),
- "image":"<center><img %(options)s "
- "src='data:image/%(ext)s;base64,%(data)s'></center>",
- "video":("<center><video %(options)s"
- "src='data:video/%(ext)s;base64,%(data)s' controls>"
- +sorry+"</video></center>")}
-
-
-def ipython_display(filename=None, clip=None, filetype=None, maxduration=60, **kwargs):
- """ Displays a video, picture, or sound in IPython.
-
- filename
- Name of a file: optional if a clip is provided instead
-
- clip
- The clip to preview. It will actually be written to a file and embedded
- as if 'filename' had been provided.
-
-
- filetype:
- One of 'video','image','audio'. If None is given, it is determined
- based on the extension of ``filename``, but this can bug.
-
- **kwargs:
- Allow you to give some options, like width=260, etc.
-
- Remarks: If your browser doesn't support HTML5, this should warn you.
- If nothing is displayed, maybe your file or filename is wrong.
- The media will be physically embedded in the notebook.
-
- Examples
- =========
-
- >>> import moviepy.editor as mpy
- >>> # later ...
- >>> clip.write_videofile("test.mp4")
- >>> mpy.ipython_display("test.mp4", width=360)
-
- >>> clip.audio.write_audiofile('test.ogg') # Sound !
- >>> mpy.ipython_display('test.ogg')
-
- >>> clip.write_gif("test.gif")
- >>> mpy.ipython_display('test.gif')
-
- >>> clip.save_frame("first_frame.jpeg")
- >>> mpy.ipython_display("first_frame.jpeg")
-
- """
-
-
- if clip is not None:
- TEMP_PREFIX = "__temp__"
- # QUICK AND VERY DIRTY: next step is use isinstance with classes.
- # But cross-dependencies in modules... aie aie aie
- if "ImageClip" in str(clip.__class__):
- filename = TEMP_PREFIX+".png"
- clip.save_frame(filename)
- elif "Video" in str(clip.__class__):
- filename = TEMP_PREFIX+".mp4"
- clip.write_videofile(filename, verbose=False, preset="ultrafast")
- elif "AudioClip" in str(clip.__class__):
- filename = TEMP_PREFIX+".mp3"
- clip.write_audiofile(filename, verbose=False)
- else:
- raise ValueError("Unknown class for the clip. Cannot embed and preview.")
-
- return ipython_display(filename=filename, maxduration=maxduration, **kwargs)
-
- options = " ".join(["%s='%s'"%(str(k), str(v)) for k,v in kwargs.items()])
- name, ext = os.path.splitext(filename)
- ext = ext[1:]
-
- if filetype is None:
- ext = filename.split('.')[-1].lower()
- if ext == "gif":
- filetype = 'image'
- elif ext in extensions_dict:
- filetype = extensions_dict[ext]['type']
- else:
- raise ValueError("No file type is known for the provided file. Please provide "
- "argument `filetype` (one of 'image', 'video', 'sound') to the "
- "ipython display function.")
-
-
- if filetype== 'video':
- # The next lines set the HTML5-cvompatible extension and check that the
- # extension is HTML5-valid
- exts_htmltype = {'mp4': 'mp4', 'webm':'webm', 'ogv':'ogg'}
- allowed_exts = " ".join(exts_htmltype.keys())
- try:
- ext = exts_htmltype[ext]
- except:
- raise ValueError("This video extension cannot be displayed in the "
- "IPython Notebook. Allowed extensions: "+allowed_exts)
-
- if filetype in ['audio', 'video']:
-
- duration = ffmpeg_parse_infos(filename)['duration']
- if duration > maxduration:
- raise ValueError("The duration of video %s exceeds the 'max_duration' "%filename+
- "attribute in ipython_display. You can increase 'max_duration', "
- "but note that embedding large videos may take all the memory away !")
-
- with open(filename, "rb") as f:
- data= b64encode(f.read())
-
- template = templates[filetype]
-
- return HTML(template%{'data':data, 'options':options, 'ext':ext})
\ No newline at end of file