Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_audiofile raises IndexError/IOError #281

Open
xjcl opened this issue Apr 3, 2016 · 5 comments
Open

write_audiofile raises IndexError/IOError #281

xjcl opened this issue Apr 3, 2016 · 5 comments
Labels
audio Related to AudioClip, or handling of audio in general. bug Issues that report (apparent) bugs.

Comments

@xjcl
Copy link

xjcl commented Apr 3, 2016

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
@somewacko
Copy link

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())

@keikoro
Copy link
Collaborator

keikoro commented Dec 17, 2018

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

@keikoro
Copy link
Collaborator

keikoro commented Dec 17, 2018

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

@keikoro keikoro added the stale For issues lacking activity, whose creators have become unresponsive,... label Dec 17, 2018
@keikoro keikoro added the audio Related to AudioClip, or handling of audio in general. label Oct 5, 2020
@Shubham-Kumar-2000
Copy link

Hi I am still facing this issue How to resolve this issue?

Any workarounds is appreciated

@Ned-Comet
Copy link

audio.write_audiofile("xxxx.wav", fps=44100, codec='pcm_s16le') works for me.
I met the same issue when I set fps=30 the same as video fps

Hi I am still facing this issue How to resolve this issue?

Any workarounds is appreciated

@keikoro keikoro removed the stale For issues lacking activity, whose creators have become unresponsive,... label Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Related to AudioClip, or handling of audio in general. bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

6 participants