Video editing with Python
started cleaning the audio parts. fixed bug in image import by adding 'PNG32:'. thanks jackMort !
Zulko4e0ca6864994
diff --git a/docs/install.rst b/docs/install.rstindex c3eed563..c2d3d72c 100644--- a/docs/install.rst+++ b/docs/install.rst@@ -13,7 +13,7 @@ MoviePy cannot run without these dependencies:**Make sure to use a recent version of ffmpeg**. You can either install it or save the binary files in any folder and specify the path to these folders before installing MoviePy (for the latter, see `Manual installation`_ below).-Debian/Ubuntu users, you certainly have an out-of-date version of FFMPEG, you *must* download a recent version from the ffmpeg_ website.+**Debian and Ubuntu users**, you certainly have an out-of-date version of FFMPEG, you *must* download a recent version from the ffmpeg_ website.Normally Numpy and Decorator will be automatically installed when you install MoviePy. In case of doubt/problem they can also be installed manually.Numpy can be installed with most software managers on Linux distributions. Both Numpy and Decorator can be installed as follows with pip: ::diff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.pyindex 8e3d9aaf..5beb5c1f 100644--- a/moviepy/audio/AudioClip.py+++ b/moviepy/audio/AudioClip.py@@ -67,21 +67,16 @@ class AudioClip(Clip):inttype = {1:'int8',2:'int16',4:'int32'}[nbytes]return (2**(8*nbytes-1)*snd_array).astype(inttype)- @requires_duration- def to_audiofile(self, filename, fps=44100, nbytes = 2,- codec ='libvorbis', bitrate=None,- buffersize=60000, verbose=True):- """ Writes the soundclip to a file using FFMPEG """-- ffmpeg_audiowrite(clip, filename, fps, nbytes=nbytes,- buffersize=buffersize, codec=codec, bitrate=bitrate, verbose=True)-@propertydef nchannels(self):return len(list(self.get_frame(0)))- def to_audiofile(self,filename, fps=44100, nbytes=2, buffersize=5000,- codec='libvorbis', bitrate=None, verbose=True):++ @requires_duration+ def to_audiofile(self,filename, fps=44100, nbytes=2,+ buffersize=5000, codec='libvorbis',+ bitrate=None, verbose=True):+return ffmpeg_audiowrite(self,filename, fps, nbytes, buffersize,codec, bitrate, verbose)@@ -112,7 +107,7 @@ class AudioArrayClip(AudioClip):self.duration = 1.0 * len(array) / fps- def gf(t):+ def get_framef(t):""" complicated, but must be able to handle the case where tis a list of the form sin(t) """@@ -129,7 +124,7 @@ class AudioArrayClip(AudioClip):else:return self.array[i]- self.get_frame = gf+ self.get_frame = get_frameclass CompositeAudioClip(AudioClip):@@ -154,13 +149,17 @@ class CompositeAudioClip(AudioClip):if not any([(e is None) for e in ends]):self.duration = max(ends)- def gf(t):+ def get_frame(t):+sounds= [c.get_frame(t - c.start)for c in clips if c.is_playing(t)]+if isinstance(t,np.ndarray):zero = np.zeros((len(t),2))+else:zero = np.zeros(2)+return zero + sum(sounds)- self.get_frame = gf+ self.get_frame = get_framediff --git a/moviepy/audio/io/ffmpeg_audiowriter.py b/moviepy/audio/io/ffmpeg_audiowriter.pyindex 78a91957..a452041d 100644--- a/moviepy/audio/io/ffmpeg_audiowriter.py+++ b/moviepy/audio/io/ffmpeg_audiowriter.py@@ -38,17 +38,17 @@ class FFMPEG_AudioWriter:codec='libfdk_aac', bitrate=None, input_video=None):self.filename = filename- cmd = [ FFMPEG_BINARY, '-y',+ cmd = ([ FFMPEG_BINARY, '-y',"-f", 's%dle'%(8*nbytes),"-acodec",'pcm_s%dle'%(8*nbytes),'-r', "%d"%fps_input,'-ac',"%d"%nchannels,- '-i', '-']+ ([- '-vn'] if input_video==None else [- "-i", input_video, '-vcodec', 'copy'])+[- '-acodec', codec] + (- ['-b',bitrate] if (bitrate!=None) else []) + [- filename ]+ '-i', '-']+ + (['-vn'] if input_video==None else+ [ "-i", input_video, '-vcodec', 'copy'])+ + ['-acodec', codec]+ + (['-b',bitrate] if (bitrate!=None) else [])+ + [ filename ])self.proc = sp.Popen(cmd,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE)diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex 9e398d83..076b065f 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -142,7 +142,8 @@ class VideoClip(Clip):def to_videofile(self, filename, fps=24, codec='libx264',bitrate=None, audio=True, audio_fps=44100,audio_nbytes = 2, audio_codec= 'libvorbis',- audio_bitrate = None, audio_bufsize = 40000, temp_wav=None,+ audio_bitrate = None, audio_bufsize = 40000,+ temp_audiofile=None,rewrite_audio = True, remove_temp = True,para = True, verbose = True):"""@@ -196,7 +197,7 @@ class VideoClip(Clip):if isinstance(audio, str):# audio is some audiofile it is maybe not a wav file. It is# NOT temporary file, it will NOT be removed at the end.- temp_wav = audio+ temp_audiofile = audiomake_audio = Falsemerge_audio = True@@ -206,16 +207,30 @@ class VideoClip(Clip):elif audio:# The audio will be the clip's audio- if temp_wav is None:- # make a name for the temporary folder- ext = {'libvorbis':'.ogg',- 'libfdk_aac':'.m4a',- 'pcm_s16le':'.wav',- 'pcm_s32le': '.wav'}[audio_codec]- temp_wav = (Clip._TEMP_FILES_PREFIX +- "to_videofile_SOUND" + ext)+ if temp_audiofile is None:++ # make a name for the temporary file++ D_ext = {'libmp3lame': 'mp3',+ 'libvorbis':'ogg',+ 'libfdk_aac':'m4a',+ 'pcm_s16le':'wav',+ 'pcm_s32le': 'wav'}++ if audio_codec in D_ext.values():+ ext = audio_codec+ else:+ if audio_codec in D_ext.keys():+ ext = D_ext[audio_codec]+ else:+ raise ValueError('audio_codec for file'+ '%d unkown !'%filename)++ temp_audiofile = (Clip._TEMP_FILES_PREFIX ++ "to_videofile_SOUND." + ext)- make_audio = (not os.path.exists(temp_wav)) or rewrite_audio+ make_audio = ( (not os.path.exists(temp_audiofile))+ or rewrite_audio)merge_audio = Trueelse:@@ -224,21 +239,25 @@ class VideoClip(Clip):merge_audio = Falseif merge_audio:+name, ext = os.path.splitext(os.path.basename(filename))videofile = Clip._TEMP_FILES_PREFIX + "to_videofile" + ext+else:+videofile = filename-+ # enough cpu for multiprocessing ?enough_cpu = (multiprocessing.cpu_count() > 2)verbose_print("Making file %s ...\n"%filename)+if para and make_audio and enough_cpu:# Parallelizeverbose_print("Writing audio/video in parrallel.\n")audioproc = multiprocessing.Process(target=self.audio.to_audiofile,- args=(temp_wav,audio_fps,audio_nbytes,+ args=(temp_audiofile,audio_fps,audio_nbytes,audio_bufsize,audio_codec, audio_bitrate,verbose))audioproc.start()ffmpeg_writer.ffmpeg_write(self, videofile, fps, codec,@@ -250,7 +269,7 @@ class VideoClip(Clip):else:# Don't parallelizeif make_audio:- self.audio.to_audiofile(temp_wav,audio_fps, audio_nbytes,+ 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)@@ -259,12 +278,12 @@ class VideoClip(Clip):if merge_audio:verbose_print("\nNow merging video and audio...\n")- ffmpeg_tools.merge_video_audio(videofile,temp_wav,filename,+ ffmpeg_tools.merge_video_audio(videofile,temp_audiofile,filename,ffmpeg_output=True)if remove_temp:os.remove(videofile)if not isinstance(audio,str):- os.remove(temp_wav)+ os.remove(temp_audiofile)verbose_print("\nYour video is ready ! Fingers crossed"+" for the Oscars !")@@ -829,7 +848,7 @@ class TextClip(ImageClip):cmd += ["-interline-spacing", "%d"%interline]cmd += ["%s:%s" %(method, txt),- "-type", "truecolormatte", tempfile]+ "-type", "truecolormatte", "PNG32:%s"%tempfile]if print_cmd:print " ".join(cmd)diff --git a/moviepy/video/fx/speedx.py b/moviepy/video/fx/speedx.pyindex 4d7eefd9..87eae80d 100644--- a/moviepy/video/fx/speedx.py+++ b/moviepy/video/fx/speedx.py@@ -15,7 +15,8 @@ def speedx(clip, factor = None, final_duration=None):factor = 1.0* clip.duration / final_durationnewclip = clip.fl_time(lambda t: factor * t)+if clip.duration != None:- return newclip.set_duration(1.0 * clip.duration / factor)- else:- return newclip+ newclip.duration = 1.0 * clip.duration / factor++ return newclipdiff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.pyindex 6f50b7cb..24594a40 100644--- a/moviepy/video/io/VideoFileClip.py+++ b/moviepy/video/io/VideoFileClip.py@@ -54,12 +54,15 @@ class VideoFileClip(VideoClip):# Make a reader for the audio, if any.if audio:try:- self.audio = AudioFileClip(filename, buffersize= audio_buffersize,- fps = audio_fps, nbytes = audio_nbytes)+ self.audio = AudioFileClip(filename,+ buffersize= audio_buffersize,+ fps = audio_fps,+ nbytes = audio_nbytes)except:if verbose:print "No audio found in %s"%filenamepass+def coreader(self, audio=True):""" Returns a copy of the AudioFileClip, i.e. a new entrance point