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

TypeError: 'float' object cannot be interpreted as an integer #376

Closed
WDBell opened this issue Jan 2, 2017 · 19 comments
Closed

TypeError: 'float' object cannot be interpreted as an integer #376

WDBell opened this issue Jan 2, 2017 · 19 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@WDBell
Copy link

WDBell commented Jan 2, 2017

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

@adelavega
Copy link

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

@mbeacom mbeacom added the bug Issues that report (apparent) bugs. label Feb 1, 2017
@mbeacom
Copy link
Collaborator

mbeacom commented Feb 1, 2017

This will be resolved when #384 is merged.

@laventura
Copy link

Hi, I get the same error on moviepy when I try to read an .mp4 file.
This was working code (back in Dec 16, 2016).

Is there an official resolution to this yet? Or should I just fix it locally as suggested by @WDBell (which seems to work).

Thanks

white_output = 'white.mp4'
clip1 = VideoFileClip("solidWhiteRight.mp4")
white_clip = clip1.fl_image(process_image) #NOTE: this function expects color images!!
%time white_clip.write_videofile(white_output, audio=False)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-5a41aa557f47> in <module>()
      1 white_output = 'white.mp4'
----> 2 clip1 = VideoFileClip("solidWhiteRight.mp4")
      3 white_clip = clip1.fl_image(process_image) #NOTE: this function expects color images!!
      4 get_ipython().magic('time white_clip.write_videofile(white_output, audio=False)')

/Users/aa/Developer/miniconda/envs/py35/lib/python3.5/site-packages/moviepy/video/io/VideoFileClip.py in __init__(self, filename, has_mask, audio, audio_buffersize, audio_fps, audio_nbytes, verbose)
     80                                        buffersize= audio_buffersize,
     81                                        fps = audio_fps,
---> 82                                        nbytes = audio_nbytes)
     83 
     84     def __del__(self):

/Users/aa/Developer/miniconda/envs/py35/lib/python3.5/site-packages/moviepy/audio/io/AudioFileClip.py in __init__(self, filename, buffersize, nbytes, fps)
     61         self.filename = filename
     62         reader = FFMPEG_AudioReader(filename,fps=fps,nbytes=nbytes,
---> 63                                          buffersize=buffersize)
     64 
     65         self.reader = reader

/Users/aa/Developer/miniconda/envs/py35/lib/python3.5/site-packages/moviepy/audio/io/readers.py in __init__(self, filename, buffersize, print_infos, fps, nbytes, nchannels)
     68         self.buffer_startframe = 1
     69         self.initialize()
---> 70         self.buffer_around(1)
     71 
     72 

/Users/aa/Developer/miniconda/envs/py35/lib/python3.5/site-packages/moviepy/audio/io/readers.py in buffer_around(self, framenumber)
    232         else:
    233             self.seek(new_bufferstart)
--> 234             self.buffer =  self.read_chunk(self.buffersize)
    235 
    236         self.buffer_startframe = new_bufferstart

/Users/aa/Developer/miniconda/envs/py35/lib/python3.5/site-packages/moviepy/audio/io/readers.py in read_chunk(self, chunksize)
    121         result = (1.0*result / 2**(8*self.nbytes-1)).\
    122                                  reshape((len(result)/self.nchannels,
--> 123                                           self.nchannels))
    124         #self.proc.stdout.flush()
    125         self.pos = self.pos+chunksize

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

@tburrows13
Copy link
Collaborator

@laventura #384 will be part of the repo in the next update.

@zippau
Copy link

zippau commented Feb 15, 2017

I have the same issue. @Gloin1313 any idea when it will be updated next?

@mbeacom
Copy link
Collaborator

mbeacom commented Feb 15, 2017

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

@ghost
Copy link

ghost commented Feb 15, 2017

Can this issue be closed?

@ghost
Copy link

ghost commented Feb 15, 2017

closing.. please reopen if the issue arises again!

@ghost ghost closed this as completed Feb 15, 2017
@hahnsangkim
Copy link

hahnsangkim commented Feb 16, 2017

I had the same issue and solved it by updating numpy as follows:
conda update --prefix yourenvs anaconda

@Techlucy
Copy link

Techlucy commented May 2, 2017

Hello I have got the same problem now. I am using Python 3.5.2 |Anaconda custom (64-bit). Any help Thanks.

image

@tburrows13
Copy link
Collaborator

tburrows13 commented May 2, 2017

@Techlucy Have you got the latest version of moviepy? Run pip3 install moviepy --upgrade to get the latest version.
Or run, as @fido2478 suggests conda update --prefix yourenvs anaconda.

@Techlucy
Copy link

Techlucy commented May 2, 2017

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

@lfiaschi
Copy link

I can confirm @Techlucy I have this error with numpy 1.12.1, fixed installing numpy 1.11.0

@tjacobs
Copy link

tjacobs commented Jul 7, 2017

Still getting this error after running

pip3 install moviepy --upgrade

and it installed

Installing collected packages: numpy, pillow, imageio, tqdm, moviepy
  Found existing installation: numpy 1.12.1
    Uninstalling numpy-1.12.1:
      Successfully uninstalled numpy-1.12.1
  Found existing installation: Pillow 4.1.1
    Uninstalling Pillow-4.1.1:
      Successfully uninstalled Pillow-4.1.1
  Found existing installation: imageio 2.2.0
    Uninstalling imageio-2.2.0:
      Successfully uninstalled imageio-2.2.0
  Found existing installation: tqdm 4.14.0
    Uninstalling tqdm-4.14.0:
      Successfully uninstalled tqdm-4.14.0
Successfully installed imageio-2.1.2 moviepy-0.2.3.2 numpy-1.13.1 pillow-4.2.1 tqdm-4.11.2

What to do?

@nerdogram
Copy link

Still getting this error: TypeError: 'float' object cannot be interpreted as an integer

Did something else (Numpy?) change?

@tburrows13
Copy link
Collaborator

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.

@FrancescoScarlata
Copy link

FrancescoScarlata commented Nov 14, 2019

I'm having the same problem i think. I'm trying to use the lib heatmappy so i don't know all the code yet, but looks like the error is out of my control. Below there is the traceback.

File "C:\Users\creavr\AppData\Local\Programs\Python\Python36-32\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 82, in __init__
    nbytes = audio_nbytes)
  File "C:\Users\creavr\AppData\Local\Programs\Python\Python36-32\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 63, in __init__
    buffersize=buffersize)
  File "C:\Users\creavr\AppData\Local\Programs\Python\Python36-32\lib\site-packages\moviepy\audio\io\readers.py", line 70, in __init__
    self.buffer_around(1)
  File "C:\Users\creavr\AppData\Local\Programs\Python\Python36-32\lib\site-packages\moviepy\audio\io\readers.py", line 234, in buffer_around
    self.buffer =  self.read_chunk(self.buffersize)
  File "C:\Users\creavr\AppData\Local\Programs\Python\Python36-32\lib\site-packages\moviepy\audio\io\readers.py", line 123, in read_chunk
    self.nchannels))
TypeError: 'float' object cannot be interpreted as an integer

@Wissotsky
Copy link

Same problem

moviepy.video.tools.drawing.circle(moviesize, (500,500), 26, col1=1.0, col2=0, blur=1)
  File "C:\Users\Wissotsky\AppData\Local\Programs\Python\Python37\lib\site-packages\moviepy\video\tools\drawing.py", line 269, in circle
    1.0*(radius-blur)/radius)
  File "C:\Users\Wissotsky\AppData\Local\Programs\Python\Python37\lib\site-packages\moviepy\video\tools\drawing.py", line 149, in color_gradient
    M = np.dstack(np.meshgrid(range(w),range(h))[::-1]).astype(float)
TypeError: 'float' object cannot be interpreted as an integer

Repository owner deleted a comment from sahils2410 Apr 28, 2020
@sandracor
Copy link

Hello,

list1 = []
for i in range(0, len(final_seq)):
list1.append(np.mean(final_seq[i].reshape(-1,2.1157586473643497), axis=1))

final_seq = np.array(list1)

I got the Error:'float' object cannot be interpreted as an integer
hat can I do against it?

This issue was closed.
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