Skip to content

Video editing with Python

Audio writing now through FFMPEG. Still experimental.

Zulko9421fb7c50cf
diff --git a/MANIFEST.in b/MANIFEST.in
index 944f76ad..3bbbaa25 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,3 +2,4 @@ include *.txt
recursive-include docs *.txt
include *.rst
recursive-include docs *.rst
+include ez_setup.py
diff --git a/README.rst b/README.rst
index 09a56cda..decdce7e 100644
--- a/README.rst
+++ b/README.rst
@@ -39,7 +39,7 @@ MoviePy cannot run without these dependencies:
- `Numpy`_ is needed for image and sound manipulation
- The Decorator_ module is used in the MoviePy code for better code readability
-Numpy and Decorator will be automatically installed during MoviePy's installation if not present on your computer. As for ffmpeg, you can either install it or save the binary files in any folder and specify the path to these folders before installing MoviePy (see `Manual installation`_).
+These are generally easy to install. For ffmpeg, you can either install it or save the binary files in any folder and specify the path to these folders before installing MoviePy (see `Manual installation`_).
Installation with PIP
diff --git a/examples/example_with_sound.py b/examples/example_with_sound.py
index f431d488..12cc0411 100644
--- a/examples/example_with_sound.py
+++ b/examples/example_with_sound.py
@@ -30,7 +30,6 @@ mask = color_split((2*W/3,H), p1=(W/3,H), p2=(2*W/3,0),
clip_left.mask = ImageClip(mask, ismask=True)
-
# MAKE THE RIGHT CLIP : cut, crop, add a mask
clip_right = main_clip.coreader().subclip(21,21+duration).\
@@ -48,5 +47,5 @@ clip_right.mask = ImageClip(mask, ismask=True)
cc = CompositeVideoClip([clip_right.set_pos('right').fx(afx.volumex, 0.4),
clip_left.set_pos('left').fx(afx.volumex, 0.4)],
size = (W,H))
-cc.preview()
-#cc.to_videofile("../../biphone3.avi",fps=24, codec='mpeg4')
+#cc.preview()
+cc.to_videofile("../../biphone3.avi",fps=24, codec='mpeg4')
diff --git a/examples/painting_effect.py b/examples/painting_effect.py
index 29df14fb..2f976584 100644
--- a/examples/painting_effect.py
+++ b/examples/painting_effect.py
@@ -35,4 +35,4 @@ final_clip = concatenate([ clip_before,
painting_fading.set_duration(3),
clip_after])
-final_clip.to_videofile('../../audrey.avi',fps=charade.fps, codec = "mpeg4")
+final_clip.to_videofile('../../audrey.avi',fps=charade.fps, codec = "mpeg4", audio_bitrate="3000k")
diff --git a/examples/soundtrack.py b/examples/soundtrack.py
index fc4baab1..d627829b 100644
--- a/examples/soundtrack.py
+++ b/examples/soundtrack.py
@@ -14,7 +14,5 @@ movie = VideoFileClip("../../videos/dam.mov").\
#~ movie.audio = movie.audio.set_duration(movie.duration)
-#soundtrack.subclip(0,25).preview(fps=22050,buffersize=20000)
-
movie.to_videofile("../../test_soundtrack.avi", codec="mpeg4")
diff --git a/moviepy/all.py b/moviepy/all.py
index 83eb64c0..1d0354d3 100644
--- a/moviepy/all.py
+++ b/moviepy/all.py
@@ -9,7 +9,7 @@ by simply typing: from moviepy.all import *
# Clips
from moviepy.video.io.VideoFileClip import VideoFileClip
-from moviepy.video.ImageClip import ImageClip, ColorClip, TextClip
+from moviepy.video.VideoClip import ImageClip, ColorClip, TextClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.concatenate import concatenate
from moviepy.audio.io.AudioFileClip import AudioFileClip
diff --git a/moviepy/audio/AudioClip.py b/moviepy/audio/AudioClip.py
index 0eae5bdc..e71d1d85 100644
--- a/moviepy/audio/AudioClip.py
+++ b/moviepy/audio/AudioClip.py
@@ -5,8 +5,7 @@ import wave
from copy import copy
import numpy as np
-from io.writers import wave_write
-from io.preview import preview
+from moviepy.audio.io.ffmpeg_audiowriter import ffmpeg_audiowrite
from moviepy.decorators import requires_duration
from moviepy.Clip import Clip
@@ -65,47 +64,30 @@ class AudioClip(Clip):
inttype = {1:'int8',2:'int16',4:'int32'}[nbytes]
return (2**(8*nbytes-1)*snd_array).astype(inttype)
-
- @requires_duration
- def preview(self, fps=22050, buffersize=10000, nbytes= 2,
- audioFlag=None, videoFlag=None):
- """
- Plays the sound clip with pygame.
-
- :param fps: frame rate of the sound. 44100 gives top quality, but
- may cause problems if your computer is not fast enough and
- your clip is complicated. If the sound jumps during the
- preview lower it (11025 is still fine, 5000 is tolerable).
-
- :param buffersize: The sound is not generated all at once, but
- rather made by bunches of frames (chunks). ``buffersize``
- is the size of such a chunk. Try varying it if you meet
- audio problems (but you shouldn't have to).
-
- :param nbytes: number of bytes to encode the sound: 1 for 8bit
- sound, 2 for 16bit, 4 for 32bit sound. 2 bytes is fine.
-
- :param audioFlag, videoFlag: parameters whose sole purpose is to
- enable a good synchronization of the start of video and sound
- when the audio clip is played as the background of a video
- clip. ``audioFlag`` and ``videoFlag`` are threading.Event
- objects (from Python's standard threading module).
- """
-
- preview(self, fps, buffersize, nbytes, audioFlag, videoFlag)
-
@requires_duration
def to_audiofile(self, filename, fps=44100, nbytes = 2,
- buffersize=80000, verbose=True):
- """ Writes the soundclip to a .wav file. """
+ codec ='libvorbis', bitrate=None,
+ buffersize=60000, verbose=True):
+ """ Writes the soundclip to a file using FFMPEG """
- wave_write(self, filename,fps, nbytes, buffersize, verbose)
+ ffmpeg_audiowrite(clip, filename, fps, nbytes=nbytes,
+ buffersize=buffersize, codec=codec, bitrate=bitrate, verbose=True)
@property
def nchannels(self):
return len(list(self.get_frame(0)))
+
+AudioClip.to_audiofile = ffmpeg_audiowrite
+
+try:
+ # Add methods preview (only if pygame installed)
+ from moviepy.audio.io.preview import preview
+ AudioClip.preview = preview
+except:
+ pass
+from moviepy.audio.io.preview import preview
-
+
class AudioArrayClip(AudioClip):
"""
diff --git a/moviepy/audio/io/ffmpeg_audiowriter.py b/moviepy/audio/io/ffmpeg_audiowriter.py
new file mode 100644
index 00000000..78a91957
--- /dev/null
+++ b/moviepy/audio/io/ffmpeg_audiowriter.py
@@ -0,0 +1,92 @@
+import sys
+import wave
+import numpy as np
+import subprocess as sp
+
+from moviepy.conf import FFMPEG_BINARY
+from moviepy.decorators import requires_duration
+
+
+class FFMPEG_AudioWriter:
+ """ A class to read videos using ffmpeg. ffmpeg will read any kind
+ of videos and transform them into raw data (a long string that
+ can be reshaped into a RGB array).
+
+ :param filename: Any filename like 'video.mp4' etc. but if you
+ want to avoid complications it is recommended to use the
+ generic extension '.avi' for all your videos.
+ :param size: size (width,height) of the output video.
+ :param fps: frames per second of the output video.
+ :param codec: ffmpeg codec. It seems that in terms of quality
+ the hierarchy is
+
+ 'rawvideo' = 'png' > 'mpeg4' > 'libx264'
+
+ 'png' manages the same lossless quality as 'rawvideo' but
+ yields smaller files.
+
+ (type ffmpeg -codecs in a terminal)
+ :param bitrate: only relevant for codecs which accept a bitrate
+ bitrate = "5000k" offers nice results in general
+ :param withmask: True if there is a mask in the video to be
+ decoded.
+ """
+
+
+
+ def __init__(self, filename, fps_input, nbytes=2, nchannels = 2,
+ codec='libfdk_aac', bitrate=None, input_video=None):
+
+ self.filename = filename
+ 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 ]
+ self.proc = sp.Popen(cmd,stdin=sp.PIPE,
+ stdout=sp.PIPE,
+ stderr=sp.PIPE)
+
+ def write_frames(self,frames_array):
+ #self.proc.stdin.write(img_array.tostring())
+ frames_array.tofile(self.proc.stdin)
+
+ def close(self):
+ self.proc.stdin.close()
+ del self.proc
+
+
+
+@requires_duration
+def ffmpeg_audiowrite(clip, filename, fps, nbytes, buffersize,
+ codec='libvorbis', bitrate=None, verbose=True):
+ if verbose:
+ def verbose_print(s):
+ sys.stdout.write(s)
+ sys.stdout.flush()
+ else:
+ verbose_print = lambda *a : None
+
+ verbose_print("Rendering audio %s\n"%filename)
+
+ writer = FFMPEG_AudioWriter(filename, fps, nbytes, clip.nchannels,
+ codec=codec, bitrate=bitrate)
+
+ totalsize = int(fps*clip.duration)
+ nchunks = totalsize / buffersize + 1
+ pospos = np.array(list(range(0, totalsize, buffersize))+[totalsize])
+ ifeedback = max(1,nchunks/10)
+ for i in range(nchunks):
+ if ( (i% ifeedback) == 0): verbose_print("=")
+ tt = (1.0/fps)*np.arange(pospos[i],pospos[i+1])
+ sndarray = clip.to_soundarray(tt,nbytes)
+ writer.write_frames(sndarray)
+
+ writer.close()
+ verbose_print("audio done !")
diff --git a/moviepy/audio/io/preview.py b/moviepy/audio/io/preview.py
index b3f44efe..6c62d135 100644
--- a/moviepy/audio/io/preview.py
+++ b/moviepy/audio/io/preview.py
@@ -11,6 +11,7 @@ import pygame as pg
pg.init()
pg.display.set_caption('MoviePy')
+
@requires_duration
def preview(clip, fps=22050, buffersize=50000, nbytes= 2,
audioFlag=None, videoFlag=None):
diff --git a/moviepy/audio/io/writers.py b/moviepy/audio/io/wav_writer.py
similarity index 98%
rename from moviepy/audio/io/writers.py
rename to moviepy/audio/io/wav_writer.py
index 8772b1ab..c6c8ddb7 100644
--- a/moviepy/audio/io/writers.py
+++ b/moviepy/audio/io/wav_writer.py
@@ -1,7 +1,7 @@
import sys
import wave
import numpy as np
-
+import subprocess as sp
def wave_write(clip, filename,fps, nbytes, buffersize, verbose):
""" Writes an audioclip down to a wav file. Deprecated if the
diff --git a/moviepy/video/ImageClip.py b/moviepy/video/ImageClip.py
deleted file mode 100644
index 0f81476e..00000000
--- a/moviepy/video/ImageClip.py
+++ /dev/null
@@ -1,256 +0,0 @@
-"""
-Classes for advantageous handling of static clips.
-ImageClip, ColorClip, TextClip
-"""
-
-import subprocess
-import os
-import numpy as np
-import moviepy.video.VideoClip as VC
-import moviepy.video.io.readers as readers
-
-
-
-class ImageClip(VC.VideoClip):
-
- """
-
- A video clip originating from a picture. This clip will simply
- display the given picture at all times. For instance:
-
- >>> clip = ImageClip("myHouse.jpeg")
- >>> clip = ImageClip( someArray ) # a Numpy array represent
-
- :param img: Any picture file (png, tiff, jpeg, etc.) or any array
- representing an RGB image (for instance a frame from a VideoClip
- or a picture read with scipy of skimage's imread method).
-
- :param ismask: `True` if the clip is a mask.
- :param transparent: `True` (default) if you want the alpha layer
- of the picture (if it exists) to be used as a mask.
-
- :ivar img: array representing the image of the clip.
-
- """
-
- def __init__(self, img, ismask=False, transparent=True, fromalpha=False):
-
- VC.VideoClip.__init__(self, ismask=ismask)
-
- if isinstance(img, str):
- img = readers.read_image(img,with_mask=transparent)
-
- if len(img.shape) == 3: # img is (now) a RGB(a) numpy array
-
- if img.shape[2] == 4:
- if fromalpha:
- img = 1.0 * img[:, :, 3] / 255
- elif ismask:
- img = 1.0 * img[:, :, 0] / 255
- elif transparent:
- self.mask = ImageClip(
- 1.0 * img[:, :, 3] / 255, ismask=True)
- img = img[:, :, :3]
- elif ismask:
- img = 1.0 * img[:, :, 0] / 255
-
- # if the image was just a 2D mask, it should arrive here unchanged
- self.get_frame = lambda t: img
- self.size = img.shape[:2][::-1]
- self.img = img
-
- def fl(self, fl, applyto=[], keep_duration=True):
- """
- Equivalent to VideoClip.fl . The result is no more an
- ImageClip, it has the class VideoClip (as it may be animated)
- """
- # When we use fl on an image clip it may become animated.
- #Therefore the result is not an ImageClip, just a VideoClip.
- newclip = VC.VideoClip.fl(self,fl, applyto=applyto,
- keep_duration=keep_duration)
- newclip.__class__ = VC.VideoClip
- return newclip
-
- def fl_image(self, image_func, applyto= []):
- """
- Similar to VideoClip.fl_image, but for ImageClip the
- tranformed clip is computed once and for all at the beginning,
- and not for each 'frame'.
- """
-
- newclip = self.copy()
- arr = image_func(self.get_frame(0))
- newclip.size = arr.shape[:2][::-1]
- newclip.get_frame = lambda t: arr
- newclip.img = arr
-
- for attr in applyto:
- if hasattr(newclip, attr):
- a = getattr(newclip, attr)
- if a != None:
- setattr(newclip, attr, a.fl_image(image_func))
-
- return newclip
-
- def fl_time(self, applyto =['mask', 'audio']):
- """
- This method does nothing for ImageClips (but it may affect their
- masks of their audios). The result is still an ImageClip
- """
- newclip = copy(self, keep_class=True)
-
- for attr in applyto:
- if hasattr(newclip, attr):
- a = getattr(newclip, attr)
- if a != None:
- setattr(newclip, attr, a.fl_image(image_func))
-
- return newclip
-
-
-
-
-
-
-class ColorClip(ImageClip):
- """
- An ImageClip showing just one color.
- :param size: Size (width, height) in pixels of the clip
- :param color: If argument ``ismask`` is False, ``color`` indicates
- the color in RGB of the clip (default is black). If `ismask``
- is True, ``color`` must be a float between 0 and 1 (default is 1)
- :param ismask: Is the clip a mask clip ?
- """
- def __init__(self,size, col=(0, 0, 0), ismask=False):
- w, h = size
- shape = (h, w) if np.isscalar(col) else (h, w, len(col))
- ImageClip.__init__(self, np.tile(col, w * h).reshape(shape),
- ismask=ismask)
-
-
-
-class TextClip(ImageClip):
-
- """
-
- An image clip originating from a script-generated text image.
- Makes a text PNG using ImageMagick.
-
- :param txt: either a string, or a filename. If txt is in a file and
- whose name is ``mytext.txt`` for instance, then txt must be
- equal to ``@mytext.txt`` .
-
- :param size: Size of the picture in pixels. Can be auto-set if
- method='label', but mandatory if method='caption'.
- the height can be None, it will then be auto-determined.
-
- :param bg_color: Color of the background. See ``TextClip.list('color')``
- for a list of acceptable names.
-
- :param color: Color of the background. See ``TextClip.list('color')``
- for a list of acceptable names.
-
- :param font: Name of the font to use. See ``TextClip.list('font')`` for
- the list of fonts you can use on your computer.
-
- :param stroke_color: Color of the stroke (=contour line) of the text.
- if ``None``, there will be no stroke.
-
- :param stroke_width: Width of the strocke, in pixels. Can be a float,
- like 1.5.
-
- :param method: 'label' (the picture will be autosized so as to fit
- exactly the size) or 'caption' (the text will be drawn in a picture
- with fixed size provided with the ``size`` argument). If `caption`,
- the text will be wrapped automagically (sometimes it is buggy, not
- my fault, complain to the ImageMagick crew) and can be aligned or
- centered (see parameter ``align``).
-
- :param kerning: Changes the default spacing between letters. For
- instance ``kerning=-1`` will make the letters 1 pixel nearer from
- each other compared to the default spacing.
-
- :param align: center | East | West | South | North . Will work if
- ``method`` is set to ``caption``
-
- :param transparent: ``True`` (default) if you want to take into account
- the transparency in the image.
-
- """
-
- def __init__(self, txt, size=None, color='black', bg_color='transparent',
- fontsize=None, font='Times-New-Roman-Regular',
- stroke_color=None, stroke_width=1, method='label',
- kerning=None, align='center', interline=None,
- tempfile='temp.png',
- temptxt='temp.txt', transparent=True, remove_temp=True,
- print_cmd=False):
-
- if not txt.startswith('@'):
- temptxt = 'temp.txt'
- with open(temptxt, 'w+') as f:
- f.write(txt)
- txt = '@temp.txt'
- else:
- txt = "'%s'"%txt
-
- if size != None:
- size = ('' if size[0] is None else str(size[0]),
- '' if size[1] is None else str(size[1]))
-
- cmd = ( ["convert",
- "-background", bg_color,
- "-fill", color,
- "-font", font])
-
- if fontsize !=None:
- cmd += ["-pointsize", "%d"%fontsize]
- if kerning != None:
- cmd += ["-kerning", "%0.1f"%kerning]
- if stroke_color != None:
- cmd += ["-stroke", stroke_color, "-strokewidth",
- "%.01f"%stroke_width]
- if size != None:
- cmd += ["-size", "%sx%s"%(size[0], size[1])]
- if align != None:
- cmd += ["-gravity",align]
- if interline != None:
- cmd += ["-interline-spacing", "%d"%interline]
-
- cmd += ["%s:%s" %(method, txt),
- "-type", "truecolormatte", tempfile]
-
- if print_cmd:
- print " ".join(cmd)
-
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
- proc.wait()
- if proc.returncode:
- print ("Error: problem in the generation of the text file"+
- "by ImageMagick. Certainly wrong arguments in TextClip")
- ImageClip.__init__(self, tempfile, transparent=transparent)
- self.txt = txt
- self.color = color
- self.stroke_color = stroke_color
-
- if remove_temp:
- os.remove(tempfile)
- try:
- os.remove(temptxt)
- except:
- pass
-
- @staticmethod
- def list(arg):
- """ Returns the list of all valid entries for the argument given
- (can be ``font``, ``color``, etc...)
- argument of ``TextClip`` """
- process = subprocess.Popen(['convert', '-list', arg],
- stdout=subprocess.PIPE)
- result = process.communicate()[0]
- lines = result.splitlines()
-
- if arg == 'font':
- return [l[8:] for l in lines if l.startswith(" Font:")]
- elif arg == 'color':
- return [l.split(" ")[1] for l in lines[2:]]
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 6f4615fc..0822e616 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -20,10 +20,10 @@ from moviepy.decorators import apply_to_mask, requires_duration
import moviepy.audio.io as aio
import moviepy.video.io.ffmpeg_writer as ffmpeg_writer
+import moviepy.video.io.ffmpeg_reader as ffmpeg_reader
import moviepy.video.io.ffmpeg_tools as ffmpeg_tools
from moviepy.video.tools.drawing import blit
-import moviepy.video.io as vio
from moviepy.Clip import Clip
@@ -140,8 +140,9 @@ class VideoClip(Clip):
def to_videofile(self, filename, fps=24, codec='libx264',
- bitrate=None, audio=True, audio_fps=44100,
- audio_nbytes = 2, audio_bufsize = 40000, temp_wav=None,
+ bitrate=None, audio=True, audio_fps=44100,
+ audio_nbytes = 2, audio_codec= 'libvorbis',
+ audio_bitrate = None, audio_bufsize = 40000, temp_wav=None,
rewrite_audio = True, remove_temp = True,
para = True, verbose = True):
"""
@@ -180,6 +181,11 @@ class VideoClip(Clip):
"""
+ if audio_codec == 'raw16':
+ audio_codec = 'pcm_s16le'
+ elif audio_codec == 'raw32':
+ audio_codec = 'pcm_s32le'
+
if verbose:
def verbose_print(s):
sys.stdout.write(s)
@@ -202,9 +208,13 @@ class VideoClip(Clip):
# The audio will be the clip's audio
if temp_wav is None:
# make a name for the temporary folder
- temp_wav = Clip._TEMP_FILES_PREFIX + "to_videofile.wav"
+ ext = {'libvorbis':'.ogg',
+ 'libfdk_aac':'.m4a',
+ 'pcm_s16le':'.wav',
+ 'pcm_s32le': '.wav'}[audio_codec]
+ temp_wav = (Clip._TEMP_FILES_PREFIX +
+ "to_videofile_SOUND" + ext)
- temp_wav = Clip._TEMP_FILES_PREFIX + "to_videofile.wav"
make_audio = (not os.path.exists(temp_wav)) or rewrite_audio
merge_audio = True
@@ -229,7 +239,7 @@ class VideoClip(Clip):
audioproc = multiprocessing.Process(
target=self.audio.to_audiofile,
args=(temp_wav,audio_fps,audio_nbytes,
- audio_bufsize,verbose))
+ audio_bufsize,audio_codec, audio_bitrate,verbose))
audioproc.start()
ffmpeg_writer.ffmpeg_write(self, videofile, fps, codec,
bitrate=bitrate, verbose=verbose)
@@ -495,7 +505,7 @@ class VideoClip(Clip):
try:
# Add methods preview and show (only if pygame installed)
- from io.preview import show, preview
+ from moviepy.video.io.preview import show, preview
VideoClip.preview = preview
VideoClip.show = show
except:
@@ -551,7 +561,7 @@ class ImageClip(VideoClip):
VideoClip.__init__(self, ismask=ismask)
if isinstance(img, str):
- img = vio.readers.read_image(img,with_mask=transparent)
+ img = ffmpeg_reader.read_image(img,with_mask=transparent)
if len(img.shape) == 3: # img is (now) a RGB(a) numpy array
diff --git a/moviepy/video/compositing/concatenate.py b/moviepy/video/compositing/concatenate.py
index 421019a6..9e13bdb4 100644
--- a/moviepy/video/compositing/concatenate.py
+++ b/moviepy/video/compositing/concatenate.py
@@ -1,6 +1,5 @@
import numpy as np
-
from moviepy.video.VideoClip import VideoClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.audio.AudioClip import CompositeAudioClip
diff --git a/moviepy/video/compositing/on_color.py b/moviepy/video/compositing/on_color.py
index ad180614..cf876915 100644
--- a/moviepy/video/compositing/on_color.py
+++ b/moviepy/video/compositing/on_color.py
@@ -1,4 +1,4 @@
-from moviepy.video.ImageClip import ColorClip
+from moviepy.video.VideoClip import ColorClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
def on_color(clip, size=None, color=(0, 0, 0), pos=None, col_opacity=None):
diff --git a/moviepy/video/fx/blackwhite.py b/moviepy/video/fx/blackwhite.py
index 95b101cb..e24a38b7 100644
--- a/moviepy/video/fx/blackwhite.py
+++ b/moviepy/video/fx/blackwhite.py
@@ -1,7 +1,9 @@
+import numpy as np
+
def blackwhite(clip, RGB = [1,1,1], preserve_luminosity=True):
""" Desaturates the picture, makes it black and white.
method = sum (TODO: others) """
if RGB == 'CRT_phosphor':
RGB = [0.2125, 0.7154, 0.0721]
- return clip.fl_image(lambda im: np.dtack(3*[im.sum(axis=2)/3]) )
+ return clip.fl_image(lambda im: np.dstack(3*[im.sum(axis=2)/3]) )
diff --git a/moviepy/video/fx/mirror_x.py b/moviepy/video/fx/mirror_x.py
new file mode 100644
index 00000000..5dab6966
--- /dev/null
+++ b/moviepy/video/fx/mirror_x.py
@@ -0,0 +1,5 @@
+
+def mirror_x(clip, apply_to= "mask"):
+ """ flips the clip horizontally (and its mask too, by default) """
+ return clip.fl_image(lambda gf, t: gf(t)[:,::-1],
+ apply_to = apply_to)
diff --git a/moviepy/video/fx/mirror_y.py b/moviepy/video/fx/mirror_y.py
new file mode 100644
index 00000000..fe714bfb
--- /dev/null
+++ b/moviepy/video/fx/mirror_y.py
@@ -0,0 +1,4 @@
+def mirror_y(clip, apply_to= "mask"):
+ """ flips the clip vertically (and its mask too, by default) """
+ return clip.fl_image(lambda gf, t : gf(t)[::-1],
+ apply_to = apply_to)
diff --git a/moviepy/video/fx/xmirror.py b/moviepy/video/fx/xmirror.py
deleted file mode 100644
index 9f41ef4a..00000000
--- a/moviepy/video/fx/xmirror.py
+++ /dev/null
@@ -1,3 +0,0 @@
-def xmirror(clip, apply_to= "mask"):
- """ flips the clip horizontally (and its mask too, by default) """
- return clip.fl_image(gf(t)[:,::-1], apply_to = apply_to)
diff --git a/moviepy/video/fx/ymirror.py b/moviepy/video/fx/ymirror.py
deleted file mode 100644
index 99db3764..00000000
--- a/moviepy/video/fx/ymirror.py
+++ /dev/null
@@ -1,3 +0,0 @@
-def ymirror(clip, apply_to= "mask"):
- """ flips the clip horizontally (and its mask too, by default) """
- return clip.fl_image(gf(t)[::-1], apply_to = apply_to)
diff --git a/moviepy/video/io/DirectoryClip.py b/moviepy/video/io/DirectoryClip.py
index 363afc28..547af61a 100644
--- a/moviepy/video/io/DirectoryClip.py
+++ b/moviepy/video/io/DirectoryClip.py
@@ -1,6 +1,6 @@
from moviepy.video.VideoClip import VideoClip
-class DirectoryClip(VideoClip)
+class DirectoryClip(VideoClip):
"""
A VideoClip read from a directory containing pictures.
diff --git a/moviepy/video/io/ffmpeg_tools.py b/moviepy/video/io/ffmpeg_tools.py
index 8f5d396f..17de8cfb 100644
--- a/moviepy/video/io/ffmpeg_tools.py
+++ b/moviepy/video/io/ffmpeg_tools.py
@@ -52,13 +52,12 @@ def extract_subclip(filename, t1, t2, targetname=None):
@subprocess_call
-def merge_video_audio(video,audio,output, acodec='libvorbis',
+def merge_video_audio(video,audio,output, vcodec='copy', acodec='copy',
ffmpeg_output=False):
""" merges video file ``video`` and audio file ``audio`` into one
movie file ``output``. """
return ["ffmpeg", "-y", "-i", audio,"-i", video,
- "-vcodec", "copy",
- "-acodec", acodec, output]
+ "-vcodec", vcodec, "-acodec", acodec, output]
@subprocess_call
def extract_audio(inputfile,output,bitrate=3000,fps=44100):
diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.py
index 276d8a92..548c9a8a 100644
--- a/moviepy/video/io/ffmpeg_writer.py
+++ b/moviepy/video/io/ffmpeg_writer.py
@@ -55,7 +55,8 @@ class FFMPEG_VideoWriter:
stderr=sp.PIPE)
def write_frame(self,img_array):
- self.proc.stdin.write(img_array.tostring())
+ #self.proc.stdin.write(img_array.tostring())
+ img_array.tofile(self.proc.stdin)
def close(self):
self.proc.stdin.close()
diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.py
index df2bbc40..54a4cc07 100644
--- a/moviepy/video/io/preview.py
+++ b/moviepy/video/io/preview.py
@@ -94,6 +94,7 @@ 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):
+ pg.mixer.stop()
pg.mixer.quit()
print "Keyboard interrupt"
return
diff --git a/setup.py b/setup.py
index e4c7d8c8..33611351 100644
--- a/setup.py
+++ b/setup.py
@@ -6,11 +6,10 @@ ez_setup.use_setuptools()
from setuptools import setup, find_packages
setup(name='moviepy',
- version='0.2.1.1',
+ version='0.2.1.6',
author='Zulko 2013',
description='Module for script-based video editing',
long_description=open('README.rst').read(),
license='LICENSE.txt',
keywords="movie editing film mixing script-based",
- packages= find_packages(),
- install_requires = ['numpy','decorator','scipy','pygame'])
+ packages= find_packages(exclude='docs'))