Moviepy: write_audiofile raises IndexError/IOError

Created on 3 Apr 2016  Β·  3Comments  Β·  Source: Zulko/moviepy

This happened while writing a large (159MB, almost 3 hours) audio file.

Related issues

See #246, #262 (?), #265

Temporary Fix

write_audiofile completed successfully after I replaced each call of the form AudioFileClip(s) in my script by AudioFileClip(s, buffersize=20000) (i.e. setting buffersize to 20k). At that time I mistakenly believed the default buffersize for AudioFileClips to be 10k, but it is in fact 200k, so lowering(!) buffersize is what made it work properly. The call to write_audiofile remained unmodified (mentioned because this function also takes a buffersize as argument).

I have no idea whether this fix works in general or just for my specific file.

Traceback

(Note that IOError is aliased to OSError in Python3)

[MoviePy] Writing audio in ops01to40.mp3
 96%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹           | 219372/228977 [03:17<00:07, 1323.03it/s]Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/moviepy/audio/io/readers.py", line 187, in get_frame
    result[in_time] = self.buffer[indices]
IndexError: index 100001 is out of bounds for axis 0 with size 100001

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "conan2.py", line 54, in <module>
    res.write_audiofile('ops01to40.mp3')
  File "<decorator-gen-73>", line 2, in write_audiofile
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 204, in write_audiofile
    verbose=verbose, ffmpeg_params=ffmpeg_params)
  File "<decorator-gen-70>", line 2, in ffmpeg_audiowrite
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/io/ffmpeg_audiowriter.py", line 161, in ffmpeg_audiowrite
    nbytes= nbytes, fps=fps):
  File "/usr/lib/python3.5/site-packages/tqdm/_tqdm.py", line 459, in __iter__
    for obj in iterable:
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 81, in generator
    buffersize=chunksize)
  File "<decorator-gen-72>", line 2, in to_soundarray
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 127, in to_soundarray
    snd_array = self.get_frame(tt)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/lib/python3.5/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/lib/python3.5/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/lib/python3.5/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/lib/python3.5/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/lib/python3.5/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/io/AudioFileClip.py", line 71, in <lambda>
    self.make_frame =  lambda t: reader.get_frame(t)
  File "/usr/lib/python3.5/site-packages/moviepy/audio/io/readers.py", line 193, in get_frame
    "but len(buffer)=%d\n"%(len(self.buffer))+ str(error))
OSError: Error in file 38.mp3, At time t=224.51-224.55 seconds, indices wanted: 100000-100479, but len(buffer)=100001
index 100001 is out of bounds for axis 0 with size 100001
audio bug stale

Most helpful comment

Interestingly after reducing buffersize, moviepy looks for a range with a negative value in the front, like:

indices wanted: -49499-500, but len(buffer)=1000
index -49499 is out of bounds for axis 0 with size 1000

Perhaps this is just a simple indexing problem?

In the meantime, I have a more reliable (and less efficient) workaround to get the audio signal for anyone else experiencing this bug:

import numpy as np
audio = np.vstack(audio_clip.iter_frames())

All 3 comments

Interestingly after reducing buffersize, moviepy looks for a range with a negative value in the front, like:

indices wanted: -49499-500, but len(buffer)=1000
index -49499 is out of bounds for axis 0 with size 1000

Perhaps this is just a simple indexing problem?

In the meantime, I have a more reliable (and less efficient) workaround to get the audio signal for anyone else experiencing this bug:

import numpy as np
audio = np.vstack(audio_clip.iter_frames())

I see one (merged) PR linked from this issue, did it solve the problem? (I'm guessing #19 is related)

Oh wait, the other issue is in another repo... nevermind.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cquintini picture cquintini  Β·  4Comments

wayn picture wayn  Β·  4Comments

Deng-deng-deng-deng picture Deng-deng-deng-deng  Β·  3Comments

Netherdrake picture Netherdrake  Β·  4Comments

keikoro picture keikoro  Β·  4Comments