moviepy: TypeError: 'float' object cannot be interpreted as an integer

I’m new to moviepy.

clip = VideoFileClip("Rough Guide to Dublin (54).mp4")

I tried three mp4 files, all with the same result. Fuller information:

>>> clip = VideoFileClip("Sailing Mediterranean - 7 Sardinia.mp4")
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python34\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 82, in __init__
    nbytes = audio_nbytes)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 63, in __init__
    buffersize=buffersize)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 70, in __init__
    self.buffer_around(1)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 234, in buffer_around
    self.buffer =  self.read_chunk(self.buffersize)
  File "C:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 123, in read_chunk
    self.nchannels))
TypeError: 'float' object cannot be interpreted as an integer

Suggest this change to code (and hope that this is a reasonable place to post this). In readers.py, substitute the second result = statement.

    def read_chunk(self,chunksize):
        #~ chunksize = int(round(chunksize))
        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)).\
                                 #~ reshape((len(result)/self.nchannels,
                                          #~ self.nchannels))

        result = (1.0*result / 2**(8*self.nbytes-1)).\
                                 reshape((int(len(result)/self.nchannels),
                                          self.nchannels))

        #self.proc.stdout.flush()
        self.pos = self.pos+chunksize
        return result

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 19

Most upvoted comments

I’m having the same problem. Looks like reshape is expecting an integer, but it gets a float because Python 3 does not auto convert floats to integers in division unless you use //.

I may open a PR

This will be resolved when #384 is merged.

Well me I am using it on Training neural network with Tensorflow. However I have corrected the error by installing the numpy 1.11.0 version.

I consulted this repository

It is a very common error in Python programming. You’ll have to give the full traceback if you want help with it. It could be anywhere.

@zippau It’s merged into master and being pushed to pypi this morning.