Video editing with Python
simplified ipython_display, corrected bug in VideoClip codec defaults.
Zulko5804eaeb6555
diff --git a/moviepy/tools.py b/moviepy/tools.pyindex 9d88ff3a..b8a0096d 100644--- a/moviepy/tools.py+++ b/moviepy/tools.py@@ -135,7 +135,7 @@ extensions_dict = { "mp4": {'type':'video', 'codec':['libx264','libmpeg4']},'m4a': {'type':'audio', 'codec':['libfdk_aac']}}-for ext in ["jpg", "jpeg", "png" "bmp", "tiff"]:+for ext in ["jpg", "jpeg", "png", "bmp", "tiff"]:extensions_dict[ext] = {'type':'image'}def find_extension(codec):diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 1ad695c8..27fc014e 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -262,7 +262,7 @@ class VideoClip(Clip):if (ext in ['ogv', 'webm']):audio_codec = 'libvorbis'else:- audio_codec=='libmp3lame'+ audio_codec = 'libmp3lame'if audio_codec == 'raw16':audio_codec = 'pcm_s16le'@@ -276,7 +276,7 @@ class VideoClip(Clip):if make_audio:# The audio will be the clip's audioif temp_audiofile is not None:- audiofile = temp_audiofile+ audiofile = temp_audiofileelse:diff --git a/moviepy/video/io/ipython_display.py b/moviepy/video/io/ipython_display.pyindex 883adfd4..39a59dfb 100644--- a/moviepy/video/io/ipython_display.py+++ b/moviepy/video/io/ipython_display.py@@ -12,7 +12,6 @@ A function to embed images/videos/audio in the IPython Notebookimport osfrom base64 import b64encodefrom moviepy.tools import extensions_dict-from itertools import counttry:from IPython.display import HTML@@ -33,11 +32,16 @@ templates = {"audio":("<center><audio controls>"+sorry+"</video></center>")}-def ipython_display(filename, filetype=None, maxduration=60, **kwargs):+def ipython_display(filename=None, clip=None, filetype=None, maxduration=60, **kwargs):""" Displays a video, picture, or sound in IPython.- filename:- Either the name of a file, or the link to a web document.+ 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@@ -68,6 +72,25 @@ def ipython_display(filename, filetype=None, maxduration=60, **kwargs):>>> 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)