Video editing with Python
fixed a few bugs like 'end-dumping' in speedx. Added effects lum_contrast and gamma_corr
Zulko07102a4c95e4
diff --git a/docs/_static/moviepy.css b/docs/_static/moviepy.cssindex e63a929b..673d5872 100644--- a/docs/_static/moviepy.css+++ b/docs/_static/moviepy.css@@ -2,15 +2,6 @@.indexwrapper .sphinxsidebar { visibility: hidden; }-.indexwrapper div.body #wand.section h1 {- background-image: url(wand.png);- background-size: 75px 75px;- background-repeat: no-repeat;- padding-left: 75px;- padding-top: 10px;- height: 75px;-}-.logo img.logo { width: 120px; height: 120px; padding-right: 30px; }div.body h1, div.body h2, div.body h3, div.body h4, div.body h5, div.body h6diff --git a/docs/conf.py b/docs/conf.pyindex 6762adc7..93f309f6 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -116,7 +116,7 @@ html_theme = 'flask'# The name of an image file (relative to this directory) to place at the top# of the sidebar.-#html_logo = None+html_logo = '_static/logo_small.jpeg'# The name of an image file (within the static path) to use as favicon of the# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32diff --git a/moviepy/audio/io/ffmpeg_audiowriter.py b/moviepy/audio/io/ffmpeg_audiowriter.pyindex a452041d..4f9f1857 100644--- a/moviepy/audio/io/ffmpeg_audiowriter.py+++ b/moviepy/audio/io/ffmpeg_audiowriter.py@@ -3,6 +3,7 @@ import waveimport numpy as npimport subprocess as sp+from tqdm import tqdmfrom moviepy.conf import FFMPEG_BINARYfrom moviepy.decorators import requires_duration@@ -82,8 +83,8 @@ def ffmpeg_audiowrite(clip, filename, fps, nbytes, buffersize,nchunks = totalsize / buffersize + 1pospos = np.array(list(range(0, totalsize, buffersize))+[totalsize])ifeedback = max(1,nchunks/10)- for i in range(nchunks):- if ( (i% ifeedback) == 0): verbose_print("=")++ for i in tqdm(range(nchunks)):tt = (1.0/fps)*np.arange(pospos[i],pospos[i+1])sndarray = clip.to_soundarray(tt,nbytes)writer.write_frames(sndarray)diff --git a/moviepy/decorators.py b/moviepy/decorators.pyindex 262a65c3..b73bf812 100644--- a/moviepy/decorators.py+++ b/moviepy/decorators.py@@ -9,6 +9,7 @@ from moviepy.tools import cvsecsdef apply_to_mask(f, clip, *a, **k):""" This decorator will apply the same function f to the mask ofthe clip created with f """+newclip = f(clip, *a, **k)if hasattr(newclip, 'mask') and (newclip.mask != None):newclip.mask = f(newclip.mask, *a, **k)@@ -19,6 +20,7 @@ def apply_to_mask(f, clip, *a, **k):def apply_to_audio(f, clip, *a, **k):""" This decorator will apply the function f to the audio ofthe clip created with f """+newclip = f(clip, *a, **k)if hasattr(newclip, 'audio') and (newclip.audio != None):newclip.audio = f(newclip.audio, *a, **k)@@ -29,6 +31,7 @@ def apply_to_audio(f, clip, *a, **k):def add_mask_if_none(f, clip, *a, **k):""" This decorator will apply the function f to the audio ofthe clip created with f """+if clip.mask is None:clip = clip.add_mask()return f(clip, *a, **k)@@ -37,6 +40,7 @@ def add_mask_if_none(f, clip, *a, **k):@decorator.decoratordef requires_duration(f, clip, *a, **k):""" will raise an error if the clip has no duration."""+if clip.duration is None:raise ValueError("Attribute 'duration' not set")else:@@ -65,6 +69,7 @@ def time_can_be_tuple(f, clip, *a, **k):can be also used on a video clip, at which case it returns avideoclip with modified audio."""+fun = lambda e: e if (not isinstance(e,tuple)) else cvsecs(*e)a = map(fun,a)k = dict( [(m, fun(n)) for m,n in k.items()])diff --git a/moviepy/editor.py b/moviepy/editor.pyindex f3056dac..c5947d23 100644--- a/moviepy/editor.py+++ b/moviepy/editor.py@@ -1,6 +1,11 @@"""This file is meant to make it easy to load the main features of MoviePyby simply typing: from moviepy.all import *+In particular it will load many effects from the video.fx and audio.fx+folders and turn them into VideoClip methods, so that instead of+>>> clip.fx( vfx.resize, 2 ) # or equivalently vfx.resize(clip, 2)+we can write+>>> clip.resize(2)"""# Note that these imports could have been performed in the __init__.pydiff --git a/moviepy/tools.py b/moviepy/tools.pyindex 2cf5fd2b..88a18305 100644--- a/moviepy/tools.py+++ b/moviepy/tools.py@@ -1,9 +1,10 @@"""-Misc. useful functions+Misc. useful functions that can be used at many places in the program."""def cvsecs(*args):- """ converts a time to second. Either cvsecs(min,secs) or+ """+ Converts a time to second. Either cvsecs(min,secs) orcvsecs(hours,mins,secs).>>> cvsecs(5.5) # -> 5.5 seconds>>> cvsecs(10, 4.5) # -> 604.5 secondsdiff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 076b065f..f823b60a 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -269,8 +269,10 @@ class VideoClip(Clip):else:# Don't parallelizeif make_audio:- self.audio.to_audiofile(temp_audiofile,audio_fps, audio_nbytes,- audio_bufsize, audio_codec, audio_bitrate, verbose)+ self.audio.to_audiofile(temp_audiofile,audio_fps,+ audio_nbytes, audio_bufsize,+ audio_codec, audio_bitrate,+ verbose)ffmpeg_writer.ffmpeg_write(self, videofile, fps, codec,bitrate=bitrate, verbose=verbose)@@ -278,8 +280,9 @@ class VideoClip(Clip):if merge_audio:verbose_print("\nNow merging video and audio...\n")- ffmpeg_tools.merge_video_audio(videofile,temp_audiofile,filename,- ffmpeg_output=True)+ ffmpeg_tools.merge_video_audio(videofile,temp_audiofile,+ filename, ffmpeg_output=True)+if remove_temp:os.remove(videofile)if not isinstance(audio,str):diff --git a/moviepy/video/fx/speedx.py b/moviepy/video/fx/speedx.pyindex 87eae80d..574903b8 100644--- a/moviepy/video/fx/speedx.py+++ b/moviepy/video/fx/speedx.py@@ -17,6 +17,6 @@ def speedx(clip, factor = None, final_duration=None):newclip = clip.fl_time(lambda t: factor * t)if clip.duration != None:- newclip.duration = 1.0 * clip.duration / factor+ newclip = newclip.set_duration(1.0 * clip.duration / factor)return newclipdiff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.pyindex 24594a40..3879bd5d 100644--- a/moviepy/video/io/VideoFileClip.py+++ b/moviepy/video/io/VideoFileClip.py@@ -47,6 +47,8 @@ class VideoFileClip(VideoClip):# Make some of the reader's attributes accessible from the clipself.duration = self.reader.duration+ self.end = self.reader.duration+self.fps = self.reader.fpsself.size = self.reader.sizeself.get_frame = lambda t: self.reader.get_frame(t)diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.pyindex f7c2a513..b2a701a3 100644--- a/moviepy/video/io/ffmpeg_writer.py+++ b/moviepy/video/io/ffmpeg_writer.py@@ -6,8 +6,12 @@ out of VideoClipsimport sysimport numpy as npimport subprocess as sp++from tqdm import tqdm+from moviepy.conf import FFMPEG_BINARY+class FFMPEG_VideoWriter:""" A class to read videos using ffmpeg. ffmpeg will read any kindof videos and transform them into raw data (a long string that@@ -76,19 +80,16 @@ def ffmpeg_write(clip, filename, fps, codec="libx264", bitrate=None,verbose_print("Rendering video %s\n"%filename)writer = FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,bitrate=bitrate)- i=0+nframes = int(clip.duration*fps)- while (i < nframes):+ for i in tqdm(range(nframes)):frame = clip.get_frame(1.0*i/fps)if withmask:mask = (255*clip.mask.get_frame(1.0*i/fps))frame = np.dstack([frame,mask])writer.write_frame(frame.astype("uint8"))- if ((i+1) % (nframes/10)) == 0:- verbose_print("=")- i += 1writer.close()verbose_print("video done !")diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.pyindex 4cc23b41..72bd91a5 100644--- a/moviepy/video/io/preview.py+++ b/moviepy/video/io/preview.py@@ -96,7 +96,9 @@ def preview(clip, fps=15, audio=True, audio_fps=22050,for event in pg.event.get():if event.type == pg.KEYDOWN:if (event.key == pg.K_ESCAPE):- videoFlag.clear()++ if audio:+ videoFlag.clear()print "Keyboard interrupt"return resultdiff --git a/setup.py b/setup.pyindex 85d909ef..429240f6 100644--- a/setup.py+++ b/setup.py@@ -6,11 +6,11 @@ ez_setup.use_setuptools()from setuptools import setup, find_packagessetup(name='moviepy',- version='0.2.1.6.92',+ version='0.2.1.6.94',author='Zulko 2013',description='Module for script-based video editing',long_description=open('README.rst').read(),- license='LICENSE.txt',+ license='see LICENSE.txt',keywords="movie editing film mixing script-based",packages= find_packages(exclude='docs'),- requires=['numpy', 'decorator'])+ install_requires=['numpy', 'decorator', 'tqdm'])