question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: wrong indices in video buffer. Maybe buffer too small.

See original GitHub issue

The following code:

wordSlide = ColorClip((1280,720), (228,232,111))
wordText = TextClip(wordStr, font="Arial-Regular", color="YellowGreen", fontsize=90)
wordAudio = AudioFileClip(path + "word.aif")
wordClip = CompositeVideoClip([wordSlide.set_audio(wordAudio),
    wordText.set_pos('center')]).set_duration(wordAudio.duration)

Produces:

Error: wrong indices in video buffer. Maybe buffer too small.
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<string>", line 2, in preview
  File "/usr/local/lib/python2.7/site-packages/moviepy/decorators.py", line 60, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python2.7/site-packages/moviepy/audio/io/preview.py", line 59, in preview
    sndarray = clip.to_soundarray(tt,nbytes)
  File "<string>", line 2, in to_soundarray
  File "/usr/local/lib/python2.7/site-packages/moviepy/decorators.py", line 60, in requires_duration
    return f(clip, *a, **k)
  File "/usr/local/lib/python2.7/site-packages/moviepy/audio/AudioClip.py", line 83, in to_soundarray
    snd_array = self.get_frame(tt)
  File "/usr/local/lib/python2.7/site-packages/moviepy/audio/AudioClip.py", line 189, in get_frame
    if (part is not False) ]
  File "/usr/local/lib/python2.7/site-packages/moviepy/audio/io/AudioFileClip.py", line 69, in <lambda>
    self.get_frame =  lambda t: self.reader.get_frame(t)
  File "/usr/local/lib/python2.7/site-packages/moviepy/audio/io/readers.py", line 173, in get_frame
    raise error
IndexError: index 45785 is out of bounds for axis 0 with size 45784

A little hack that kinda makes it go away is to do:

wordSlide = ColorClip((1280,720), (228,232,111))
wordText = TextClip(wordStr, font="Arial-Regular", color="YellowGreen", fontsize=90)
wordAudio = AudioFileClip(path + "word.aif")
wordClip = CompositeVideoClip([wordSlide.set_audio(wordAudio),
    wordText.set_pos('center')]).set_duration(wordAudio.duration - 0.01)

Although this doesn’t fix anything. It just happens to work in this case, but not for other clips. Why is it crashing?

The wordAudio.duration is 1.04s in this case. On some audio files it crashes, on some it doesn’t. Is this the accuracy problem with generating number of frames based on audio length?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:38 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
Zulkocommented, Jun 4, 2014

First, an update on your bugs.

At least on my computer, it seems that the main problem is that you ask the same clip to play three times, which forces the ffmpeg-reader to “rewind” or re-initialize, and that’s where the bug happens. You so that it is clearer:

# Won't work
video = concatenate([ wordClip.fadein(0.3),
                  spellingClip,
                  wordClip,    ###
                  meaningClip,
                  wordClip,    ###
                  exampleClip,
                  ending ])
# Will work
video = concatenate([ wordClip.fadein(0.3),
                  spellingClip,
                  meaningClip,
                  exampleClip,
                  ending ])

I will try to see what causes this bug. In the meantime, the most reliable solution is to create different entry points into the file:

clip1 = VideoFileClip("myvideo.mp4")
clip2 = VideoFileClip("myvideo.mp4")
clip3 = VideoFileClip("myvideo.mp4")

Since you need to process these clips afterwards, the best thing to do is to make a loop or a function, like this:

def make_wordClip(wordStr, wordFile):
wordSlide = ColorClip((1280,720), (178, 240, 120))
    wordText = TextClip(wordStr, font="Helvetica", color="#5782D4",
                    fontsize=90)
    wordAudio = AudioFileClip(wordFile, buffersize=4000)
    wordClip = CompositeVideoClip([wordSlide.set_audio(wordAudio),
                               wordText.set_pos('center')])\
           .set_duration(wordAudio.duration)
    return wordClip

wordClips = [make_wordClip(wordStr, "word.aif") for i in [1,2,3]]

#later 

video = concatenate([ wordClips[0].fadein(0.3),
                  spellingClip,
                  wordClips[1],    ###
                  meaningClip,
                  wordClips[2],    ###
                  exampleClip,
                  ending ])
0reactions
Netherdrakecommented, Jun 8, 2014

I have ran a couple hundred renderings, and I can confirm the bug is definitely fixed. Thank you very much! You’re awesome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML5 Video buffered attribute features - Stack Overflow
But I am seeking only 3 portions, it seems too small a number to start clearing the cache. And no, the resulting single...
Read more >
Video - Bad buffer index: -10000 - Unity Forum
I thought it has something to do with setting the wrong frame (too big or too small frame index that doesn't exist because...
Read more >
WebGL 2 Uniform Buffer Objects size inconsistent on Mac and ...
"Error: WebGL warning: drawElements: Buffer for uniform block is smaller than UNIFORM_BLOCK_DATA_SIZE." According to the ES 3.0 spec: If pname is ...
Read more >
3.6. Buffers — The Linux Kernel documentation
Additionally, drivers shall return a EINVAL error from the VIDIOC_QBUF() ioctl if the buffer being queued is too small for the current format...
Read more >
What is buffering on TV? - SkyLine/SkyBest
Possibly the most common form of buffering occurs when your internet speed is ... The final problem you may have that is causing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found