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

IndexError when converting audio to_soundarray() #246

Closed
pinae opened this issue Jan 6, 2016 · 4 comments
Closed

IndexError when converting audio to_soundarray() #246

pinae opened this issue Jan 6, 2016 · 4 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@pinae
Copy link

pinae commented Jan 6, 2016

When converting audio to a numpy array with .to_soundarray() I get a IndexError with some files. This occured with audion from video clips and with audio clips

The error occurs with this File: https://github.com/pinae/Audiosyncer/blob/master/sample_mono_short.flac
This code reproduces the error:

from moviepy.editor import *
sound = AudioFileClip("sample_mono_short.flac")
samples = sound.to_soundarray()

The whole error message:

IndexError                                Traceback (most recent call last)
/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/io/readers.py in get_frame(self, tt)
    186                 indices = frames - self.buffer_startframe
--> 187                 result[in_time] = self.buffer[indices]
    188                 return result

IndexError: index 120575 is out of bounds for axis 0 with size 120575

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-2-7b8ec45b76f0> in <module>()
      2 
      3 sound = AudioFileClip("sample_mono_short.flac")
----> 4 samples = sound.to_soundarray()

<decorator-gen-194> in to_soundarray(self, tt, fps, quantize, nbytes, buffersize)

/home/xxx/venv/lib/python3.4/site-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k)
     52         raise ValueError("Attribute 'duration' not set")
     53     else:
---> 54         return f(clip, *a, **k)
     55 
     56 

/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/AudioClip.py in to_soundarray(self, tt, fps, quantize, nbytes, buffersize)
    112             if self.duration>max_duration:
    113                 return stacker(self.iter_chunks(fps=fps, quantize=quantize, nbytes=2,
--> 114                                                  chunksize=buffersize))
    115             else:
    116                 tt = np.arange(0, self.duration, 1.0/fps)

/home/xxx/venv/lib/python3.4/site-packages/numpy/core/shape_base.py in vstack(tup)
    228 
    229     """
--> 230     return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
    231 
    232 def hstack(tup):

/home/xxx/venv/lib/python3.4/site-packages/numpy/core/shape_base.py in <listcomp>(.0)
    228 
    229     """
--> 230     return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
    231 
    232 def hstack(tup):

/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/AudioClip.py in generator()
     79                 tt = (1.0/fps)*np.arange(pospos[i],pospos[i+1])
     80                 yield self.to_soundarray(tt, nbytes= nbytes, quantize=quantize, fps=fps,
---> 81                                          buffersize=chunksize)
     82 
     83         if progress_bar:

<decorator-gen-194> in to_soundarray(self, tt, fps, quantize, nbytes, buffersize)

/home/xxx/venv/lib/python3.4/site-packages/moviepy/decorators.py in requires_duration(f, clip, *a, **k)
     52         raise ValueError("Attribute 'duration' not set")
     53     else:
---> 54         return f(clip, *a, **k)
     55 
     56 

/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/AudioClip.py in to_soundarray(self, tt, fps, quantize, nbytes, buffersize)
    125         #print tt.max() - tt.min(), tt.min(), tt.max()
    126 
--> 127         snd_array = self.get_frame(tt)
    128 
    129         if quantize:

 <decorator-gen-136> in get_frame(self, t)

/home/xxx/venv/lib/python3.4/site-packages/moviepy/decorators.py in wrapper(f, *a, **kw)
     87         new_kw = {k: fun(v) if k in varnames else v
     88                  for (k,v) in kw.items()}
---> 89         return f(*new_a, **new_kw)
     90     return decorator.decorator(wrapper)
     91 

/home/xxx/venv/lib/python3.4/site-packages/moviepy/Clip.py in get_frame(self, t)
     93                 return frame
     94         else:
---> 95             return self.make_frame(t)
     96 
     97     def fl(self, fun, apply_to=[] , keep_duration=True):

/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/io/AudioFileClip.py in <lambda>(t)
     69 
     70 
---> 71         self.make_frame =  lambda t: reader.get_frame(t)
     72         self.nchannels = reader.nchannels
     73 

/home/xxx/venv/lib/python3.4/site-packages/moviepy/audio/io/readers.py in get_frame(self, tt)
    191                        "At time t=%.02f-%.02f seconds, "%(tt[0], tt[-1])+
    192                        "indices wanted: %d-%d, "%(indices.min(), indices.max())+
--> 193                        "but len(buffer)=%d\n"%(len(self.buffer))+ str(error))
    194 
    195         else:

OSError: Error in file sample_mono_short.flac, At time t=27.21-27.68 seconds, indices wanted: 100000-120687, but len(buffer)=120575
index 120575 is out of bounds for axis 0 with size 120575
@pinae
Copy link
Author

pinae commented Jan 6, 2016

I successfully converted the audio from a problematic file by reducing the buffersize to 1000. That might be a hint where the problem lies.

@fortunto2
Copy link

fortunto2 commented Feb 16, 2016

i have same problem

[MoviePy] Writing audio in baaabk9kTEMP_MPY_wvf_snd.mp3
 39%|███▉      | 301/776 [00:00<00:00, 543.58it/s]Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/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 "./1job.py", line 246, in <module>
    duration = template.fast.render(allParam, data, videos, audios)
  File "/ubuntu/newconv/template/fast.py", line 400, in render
    ffmpeg_params=ffmpeg_params, threads=8, write_logfile=True)  
  File "<decorator-gen-51>", line 2, in write_videofile
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, _a, *_k)
  File "<decorator-gen-50>", line 2, in write_videofile
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, _new_a, *_new_kw)
  File "<decorator-gen-49>", line 2, in write_videofile
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, _a, *_k)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/video/VideoClip.py", line 330, in write_videofile
    verbose=verbose)
  File "<decorator-gen-73>", line 2, in write_audiofile
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, _a, *_k)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/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/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, _a, *_k)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/io/ffmpeg_audiowriter.py", line 161, in ffmpeg_audiowrite
    nbytes= nbytes, fps=fps):
  File "/usr/local/lib/python3.4/dist-packages/tqdm-3.8.0-py3.4.egg/tqdm/_tqdm.py", line 459, in __iter__
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 81, in generator
    buffersize=chunksize)
  File "<decorator-gen-72>", line 2, in to_soundarray
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, _a, *_k)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/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/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 89, in wrapper
    return f(_new_a, *_new_kw)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 89, in wrapper
    return f(_new_a, *_new_kw)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/fx/volumex.py", line 18, in <lambda>
    return clip.fl(lambda gf, t: factor \* gf(t),
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 89, in wrapper
    return f(_new_a, *_new_kw)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 89, in wrapper
    return f(_new_a, *_new_kw)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 292, in make_frame
    for c,part in zip(self.clips, played_parts)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/AudioClip.py", line 293, in <listcomp>
    if (part is not False) ]
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/decorators.py", line 89, in wrapper
    return f(_new_a, *_new_kw)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/io/AudioFileClip.py", line 71, in <lambda>
    self.make_frame =  lambda t: reader.get_frame(t)
  File "/usr/local/lib/python3.4/dist-packages/moviepy-0.2.2.11-py3.4.egg/moviepy/audio/io/readers.py", line 193, in get_frame
    "but len(buffer)=%d\n"%(len(self.buffer))+ str(error))
OSError: Error in file /ubuntu/conv/60886/conv/baaabk9k/1_000.mp4, At time t=13.62-13.67 seconds, indices wanted: 100000-101999, but len(buffer)=100001
index 100001 is out of bounds for axis 0 with size 100001

@fortunto2
Copy link

fortunto2 commented Feb 16, 2016

in /ubuntu/conv/60886/conv/baaabk9k/1_000.mp4

[aac @ 0x3aec880] 
Input buffer exhausted before END element found
Error while decoding stream #0:1: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 0, offset 0x80dd: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x80ef: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x82b8: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 0, offset 0x8499: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x84ab: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 0, offset 0x860b: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x8623: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x8788: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 0, offset 0x88dd: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x88f2: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x3ae5d00] stream 1, offset 0x8a5e: partial file
/ubuntu/conv/60886/conv/baaabk9k/1_000.mp4: Invalid data found when processing input

frame=   43 fps=0.0 q=-1.0 Lsize=      38kB time=00:00:01.36 bitrate= 226.7kbits/s dup=5 drop=0  
video:12kB audio:23kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 7.773448%

@keikoro keikoro added the bug Issues that report (apparent) bugs. label Feb 17, 2017
ghost pushed a commit that referenced this issue Apr 4, 2017
* audio error handling made failsafe, as for video

* fixed case when accessing time out of the estimated valid range

* Added test video for issue #246

* remove change not directly related to PR
@keikoro
Copy link
Collaborator

keikoro commented Nov 25, 2017

Looks like a fix for this was merged. Closing.

@keikoro keikoro closed this as completed Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

3 participants