Video editing with Python
Minor bug fixes and additions
Zulko8f47936b56c9
diff --git a/moviepy/all.py b/moviepy/all.pyindex 12123f8f..8adec3be 100644--- a/moviepy/all.py+++ b/moviepy/all.py@@ -25,3 +25,8 @@ import moviepy.video.compositing.transitions as transfximport moviepy.video.tools as videotoolsimport moviepy.video.io.ffmpeg_tools as ffmpeg_toolsfrom moviepy.tools import cvsecs++try:+ from moviepy.video.io.sliders import sliders+except:+ passdiff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.pyindex f2f8b121..fb7893c2 100644--- a/moviepy/audio/AudioClip.py+++ b/moviepy/audio/AudioClip.py@@ -49,7 +49,7 @@ class AudioClip(Clip):Clip.__init__(self)@requires_duration- def to_soundarray(self,tt, nbytes=2):+ def to_soundarray(self,tt=None,fps=None, nbytes=2):"""Transforms the sound into an array that can be played by pygameor written in a wav file. See ``AudioClip.preview``.@@ -59,6 +59,9 @@ class AudioClip(Clip)::param nbytes: number of bytes to encode the sound: 1 for 8bitsound, 2 for 16bit, 4 for 32bit sound."""+ if tt is None:+ tt = np.arange(0,self.duration, 1.0/fps)+snd_array = self.get_frame(tt)snd_array = np.maximum(-0.999, np.minimum(0.999,snd_array))inttype = {1:'int8',2:'int16',4:'int32'}[nbytes]diff --git a/moviepy/audio/fx/audio_fadein.py b/moviepy/audio/fx/audio_fadein.pyindex aef930d9..9314de46 100644--- a/moviepy/audio/fx/audio_fadein.py+++ b/moviepy/audio/fx/audio_fadein.py@@ -12,7 +12,7 @@ def audio_fadein(clip, duration):factor = min(1.0 * t / duration, 1)factor = np.array([factor,factor])else:- factor = np.minimum(1.0 * t / duration, 1).T- factor = np.vstack([factor.T,factor.T]).T+ factor = np.minimum(1.0 * t / duration, 1)+ factor = np.vstack([factor,factor]).Treturn factor * gftreturn clip.fl(fading, keep_duration = True)diff --git a/moviepy/audio/fx/audio_fadeout.py b/moviepy/audio/fx/audio_fadeout.pyindex 524d7022..4e80c954 100644--- a/moviepy/audio/fx/audio_fadeout.py+++ b/moviepy/audio/fx/audio_fadeout.py@@ -3,9 +3,19 @@ import numpy as np@audio_video_fx@requires_duration-def audio_fadeout(self, duration):+def audio_fadeout(clip, duration):""" Return a sound clip where the sound fades out progressivelyover ``duration`` seconds at the end of the clip. """- fading = lambda gf, t: np.maximum(- 1.0 * (self.duration - t) / duration, 0) * gf(t)- return self.fl(fading, keep_duration = True)++ def fading(gf,t):+ gft = gf(t)++ if np.isscalar(t):+ factor = min(1.0 * (clip.duration - t) / duration, 1)+ factor = np.array([factor,factor])+ else:+ factor = np.minimum( 1.0 * (clip.duration - t) / duration, 1)+ factor = np.vstack([factor,factor]).T+ return factor * gft++ return clip.fl(fading, keep_duration = True)diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex d32195d3..fdd0dfd9 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -425,7 +425,11 @@ class VideoClip(Clip):multiplied by ``op`` (any float, normally between 0 and 1)."""newclip = copy(self)- newclip.mask = self.mask.fl_image(lambda pic: op * pic)++ if not newclip.mask:+ newclip = newclip.add_mask()++ newclip.mask = newclip.mask.fl_image(lambda pic: op * pic)return newclip@apply_to_mask@@ -498,6 +502,14 @@ class VideoClip(Clip):newclip = copy(self)newclip.audio = Nonereturn newclip++ def afx(self, fun, *a, **k):+ """+ Returns a new clip whose audio has been transformed by ``fun``.+ """+ newclip = self.copy()+ newclip.audio = newclip.audio.fx(fun, *a, **k)+ return newclip#-----------------------------------------------------------------# Previews:@@ -606,12 +618,12 @@ class ImageClip(VideoClip):return newclip- def fl_time(self, applyto =['mask', 'audio']):+ def fl_time(self, timefun, applyto =['mask', 'audio']):"""This method does nothing for ImageClips (but it may affect theirmasks of their audios). The result is still an ImageClip"""- newclip = copy(self, keep_class=True)+ newclip = self.copy()for attr in applyto:if hasattr(newclip, attr):diff --git a/moviepy/video/fx/__init__.py b/moviepy/video/fx/__init__.pyindex b3fda558..38b6baba 100644--- a/moviepy/video/fx/__init__.py+++ b/moviepy/video/fx/__init__.py@@ -7,7 +7,7 @@ import osdirectory = os.path.dirname(os.path.realpath(__file__))files = os.listdir(directory)-fx_list = [f for f in files if ( f.endswith('py') and not f.startswith('_'))]+fx_list = [f for f in files if ( f.endswith('.py') and not f.startswith('_'))]__all__ = [c[:-3] for c in fx_list]for name in __all__:diff --git a/moviepy/video/fx/speedx.py b/moviepy/video/fx/speedx.pyindex b83580ba..4d7eefd9 100644--- a/moviepy/video/fx/speedx.py+++ b/moviepy/video/fx/speedx.py@@ -2,14 +2,20 @@ from moviepy.decorators import apply_to_mask,apply_to_audio@apply_to_mask@apply_to_audio-def speedx(self, factor):- """- Returns a clip playing the current clip but at a speed multiplied- by ``factor``.- The same effect is applied to the clip's audio and mask if any.- """- newclip = self.fl_time(lambda t: factor * t)- if self.duration != None:- return newclip.set_duration(1.0 * self.duration / factor)- else:- return newclip+def speedx(clip, factor = None, final_duration=None):+ """+ Returns a clip playing the current clip but at a speed multiplied+ by ``factor``. Instead of factor one can indicate the desired+ ``final_duration`` of the clip, and the factor will be automatically+ computed.+ The same effect is applied to the clip's audio and mask if any.+ """++ if final_duration:+ factor = 1.0* clip.duration / final_duration++ newclip = clip.fl_time(lambda t: factor * t)+ if clip.duration != None:+ return newclip.set_duration(1.0 * clip.duration / factor)+ else:+ return newclipdiff --git a/setup.py b/setup.pyindex 94e126eb..18c342a5 100644--- a/setup.py+++ b/setup.py@@ -6,7 +6,7 @@ ez_setup.use_setuptools()from setuptools import setup, find_packagessetup(name='moviepy',- version='0.2.1.6.2',+ version='0.2.1.6.3',author='Zulko 2013',description='Module for script-based video editing',long_description=open('README.rst').read(),