Skip to content

Video editing with Python

Fixed bug in audioreader. Hopefully.

Zulkob4b0efee7597
diff --git a/README.rst b/README.rst
index 2cc8780e..963d1a81 100644
--- a/README.rst
+++ b/README.rst
@@ -26,6 +26,13 @@ A typical MoviePy script looks like that: ::
final_clip.to_videofile("myHolidays_edited.avi",fps=25, codec='mpeg4')
+
+Contribute !
+-------------
+MoviePy is an open-source software originally written by Zulko_ and released under the MIT licence.
+The project is hosted on Github_ and everyone is welcome to contribute ! Please give feedback if you are using it and encounter difficulties.
+
+
Download and Installation
---------------------------
@@ -42,7 +49,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 and 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: ::
@@ -50,7 +57,25 @@ Numpy can be installed with most software managers on Linux distributions. Both
(sudo) pip install decorator
(sudo) pip install numpy
+
+(Not so) Optional dependencies
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You are not obliged to install these but for many uses MoviePy will scream at you and say that the package or the software is missing. All these dependencies can be installed any time after the installation of MoviePy.
+
+- PyGame_ is needed for video and sound previews (really essential for advanced editing).
+- imageMagick_ is needed for all text generation, GIF support, and much more in the future.
+
+There are many packages for image manipulation/processing in python. Most effects are coded such that none of these packages are needed, or such that having at least one of these packages is sufficient. For instance, the feature ``clip.resize`` will be available if you have either Scikit Image *or* the PIL *or* OpenCV installed (PIL or OpenCV are to be prefered).
+
+- Scipy is needed for many advanced functionalities (tracking, segmenting, etc.)
+- `Scikit Image`_ may be needed for some advanced image manipulation.
+- The Python Imaging Library can be used for resizing videos.
+- `OpenCV 2.4.6`_ (which provides the python package ``cv2``) or more recent may be needed for some advanced image manipulation. See below for the installation of OpenCV.
+
+If you are on linux, these will surely be in your repos.
+
Installation with PIP
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -79,25 +104,6 @@ Before doing that, you should make sure that MoviePy can locate ffmpeg on your c
FFMPEG_BINARY = path/to/your/ffmpeg
-
-(Not so) Optional dependencies
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-You are not obliged to install these but for many uses MoviePy will scream at you and say that the package or the software is missing. All these dependencies can be installed any time after the installation of MoviePy.
-
-- PyGame_ is needed for video and sound previews (really essential for advanced editing).
-- imageMagick_ is needed for all text generation, GIF support, and much more in the future.
-
-There are many packages for image manipulation/processing in python. Most effects are coded such that none of these packages are needed, or such that having at least one of these packages is sufficient. For instance, the feature ``clip.resize`` will be available if you have either Scikit Image *or* the PIL *or* OpenCV installed (PIL or OpenCV are to be prefered).
-
-- Scipy is needed for many advanced functionalities (tracking, segmenting, etc.)
-- `Scikit Image`_ may be needed for some advanced image manipulation.
-- The Python Imaging Library can be used for resizing videos.
-- `OpenCV 2.4.6`_ (which provides the python package ``cv2``) or more recent may be needed for some advanced image manipulation. See below for the installation of OpenCV.
-
-If you are on linux, these will surely be in your repos.
-
-
Installing OpenCV 2.4.6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -135,6 +141,7 @@ Advice: do not throw your ``release`` folder away. If later you have strange bug
.. _PYPI: https://pypi.python.org/pypi/moviepy
+.. _Zulko : https://github.com/Zulko
.. _Github: https://github.com/Zulko/moviepy
.. _here: http://zulko.github.io/moviepy/
.. _`download MoviePy`: https://github.com/Zulko/moviepy
diff --git a/moviepy/audio/io/AudioFileClip.py b/moviepy/audio/io/AudioFileClip.py
index 2e2afd3a..05bf3d97 100644
--- a/moviepy/audio/io/AudioFileClip.py
+++ b/moviepy/audio/io/AudioFileClip.py
@@ -71,12 +71,14 @@ class AudioFileClip(AudioClip):
self._buffer_around(f_tmax)
try:
+ tup = in_time.nonzero()
+ inds2 = inds - self._fstart_buffer
result[in_time] = self.buffer[inds - self._fstart_buffer]
return result
- except IndexError:
+ except IndexError as error:
print ("Error: wrong indices in video buffer. Maybe"+
" buffer too small.")
- raise IndexError
+ raise error
else:
ind = int(self.fps*t)
@@ -105,7 +107,8 @@ class AudioFileClip(AudioClip):
fill the buffer with frames, centered on ``framenumber``
if possible
"""
- # start frame for the buffer
+
+ # start-frame for the buffer
fbuffer = framenumber - self.buffersize//2
fbuffer = max(0, fbuffer)
diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.py
index e84b6786..261c4c86 100644
--- a/moviepy/audio/io/readers.py
+++ b/moviepy/audio/io/readers.py
@@ -59,8 +59,7 @@ class FFMPEG_AudioReader:
if starttime !=0 :
offset = min(1,starttime)
- i_arg = [ FFMPEG_BINARY,
- "-ss", "%.05f"%(starttime-offset),
+ i_arg = ["-ss", "%.05f"%(starttime-offset),
'-i', self.filename, '-vn',
"-ss", "%.05f"%offset]
else:
@@ -72,7 +71,6 @@ class FFMPEG_AudioReader:
'-acodec', self.acodec,
'-ar', "%d"%self.fps,
'-ac', '%d'%self.nchannels, '-'])
-
self.proc = sp.Popen( cmd, bufsize=self.bufsize,
stdin=sp.PIPE,
stdout=sp.PIPE,
@@ -85,7 +83,8 @@ class FFMPEG_AudioReader:
self.pos = self.pos+chunksize
def read_chunk(self,chunksize):
- s = self.proc.stdout.read(self.nchannels*chunksize*self.nbytes)
+ L = self.nchannels*chunksize*self.nbytes
+ s = self.proc.stdout.read(L)
dt = {1: 'int8',2:'int16',4:'int32'}[self.nbytes]
result = np.fromstring(s, dtype=dt)
result = (1.0*result / 2**(8*self.nbytes-1)).\
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index f14d4638..4466f88f 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -625,15 +625,21 @@ class VideoClip(Clip):
#-----------------------------------------------------------------
# Previews:
-try:
- # Add methods preview and show (only if pygame installed)
- from moviepy.video.io.preview import show, preview
- VideoClip.preview = preview
- VideoClip.show = show
-except:
- pass
+# Add methods preview and show (only if pygame installed)
+try:
+ from moviepy.video.io.preview import show, preview
+except ImportError:
+ def preview(self, *args, **kwargs):
+ """ NOT AVAILABLE : clip.preview requires Pygame installed """
+ raise ImportError("clip.preview requires Pygame installed")
+ def show(self, *args, **kwargs):
+ """ NOT AVAILABLE : clip.show requires Pygame installed """
+ raise ImportError("clip.show requires Pygame installed")
+
+VideoClip.preview = preview
+VideoClip.show = show
diff --git a/moviepy/video/fx/crop.py b/moviepy/video/fx/crop.py
index 35d5748e..a60e7659 100644
--- a/moviepy/video/fx/crop.py
+++ b/moviepy/video/fx/crop.py
@@ -2,9 +2,26 @@ def crop(clip, x1=None, y1=None, x2=None, y2=None,
width = None, height=None,
x_center= None, y_center=None):
"""
- >>> crop(clip, x1,y1,x2,y2) # defines the rectangle of the crop
+ Returns a new clip in which just a rectangular subregion of the
+ original clip is conserved. x1,y1 indicates the top left corner and
+ x2,y2 is the lower right corner of the croped region.
+ All coordinates are in pixels. Float numbers are accepted.
+
+ To crop an arbitrary rectangle:
+ >>> crop(clip, x1=50, y1=60, x2=460, y2=275)
+
+ Only remove the part above y=30:
+ >>> crop(clip, y1=30)
+
+ Crop a rectangle that starts 10 pixels left and is 200px wide
>>> crop(clip, x1=10, width=200)
+ Crop a rectangle centered in x,y=(300,400), width=50, height=150 :
+ >>> crop(clip, x_center=300 , y_center=400, width=50, height=150)
+
+ Any combination of the above should work:
+ Rectangle centered in x=300, with explicit y-boundaries:
+ >>> crop(x_center=300, width=400, y1=100, y2=600)
"""
@@ -36,5 +53,6 @@ def crop(clip, x1=None, y1=None, x2=None, y2=None,
if y2 is None:
y2 = clip.size[1]
- return clip.fl_image(lambda pic: pic[y1:y2, x1:x2],
- applyto=['mask'])
+ return clip.fl_image(
+ lambda pic: pic[int(y1):int(y2), int(x1):int(x2)],
+ applyto=['mask'])
diff --git a/moviepy/video/fx/resize.py b/moviepy/video/fx/resize.py
index 4e05efab..7d406df6 100644
--- a/moviepy/video/fx/resize.py
+++ b/moviepy/video/fx/resize.py
@@ -99,6 +99,7 @@ def resize(clip, newsize=None, height=None, width=None):
if not resize_possible:
+
doc = resize.__doc__
def resize(clip, newsize=None, height=None, width=None):
raise ImportError("fx resize needs OpenCV or Scipy or PIL")