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

vfx.scroll giving TypeError: slice indices must be integers or None or have an __index__ method #527

Closed
tburrows13 opened this issue Apr 5, 2017 · 6 comments
Labels
bug Issues that report (apparent) bugs.

Comments

@tburrows13
Copy link
Collaborator

tburrows13 commented Apr 5, 2017

I run:

new_clip = vfx.scroll(clip, w=1000, x_speed=5)
new_clip = new_clip.set_duration(float(clip.w - 1000) / 5)
new_clip.write_videofile("pano.mp4", fps=24)

as recommended by Zulko in #240, but it gives the following error:

  File "/Users/tomburrows/Dropbox/Python Programming/QF_Editor/panorama_scroll.py", line 8, in <module>
    new_clip.write_videofile("pano.mp4")
  File "<decorator-gen-51>", line 2, in write_videofile
  File "/anaconda/lib/python3.5/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-50>", line 2, in write_videofile
  File "/anaconda/lib/python3.5/site-packages/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 "/anaconda/lib/python3.5/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/anaconda/lib/python3.5/site-packages/moviepy/video/VideoClip.py", line 345, in write_videofile
    progress_bar=progress_bar)
  File "/anaconda/lib/python3.5/site-packages/moviepy/video/io/ffmpeg_writer.py", line 209, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "/anaconda/lib/python3.5/site-packages/tqdm/_tqdm.py", line 833, in __iter__
    for obj in iterable:
  File "/anaconda/lib/python3.5/site-packages/moviepy/Clip.py", line 475, in generator
    frame = self.get_frame(t)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/anaconda/lib/python3.5/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/anaconda/lib/python3.5/site-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/anaconda/lib/python3.5/site-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/anaconda/lib/python3.5/site-packages/moviepy/video/fx/scroll.py", line 17, in f
    return gf(t)[y:y+h, x:x+w]
TypeError: slice indices must be integers or None or have an __index__ method

Doing some research, this is because x is 0 when you first call it, but then when it writes the video to a file, it iterates for each frame, and the second time, x is 1.0. This is a float, not an int so it fails.
A solution that worked for me is to change lines 14 and 15 of scroll.py to change the float into a int.
Can anyone repro this, and shall we make the suggested changes?

@ghost
Copy link

ghost commented Apr 5, 2017

I believe this is the code causing the issues:

 x = max(0, min(xmax, x_start+ np.round(x_speed*t)))
 y = max(0, min(ymax, y_start+ np.round(y_speed*t)))

could we change np.round to just round? I assume np.round is returning a float instead of an int. Is that correct?

@tburrows13
Copy link
Collaborator Author

@Earney, yes that is the code I figured is the error. I just stuck and int(max..)))) round the whole thing, but yours sounds better (I've never used numpy).

@tburrows13
Copy link
Collaborator Author

Changing np.round to round does not fix it.
The code that is called each frame is here:

def f(gf,t):
    x = max(0, min(xmax, x_start+ np.round(x_speed*t)))
    y = max(0, min(ymax, y_start+ np.round(y_speed*t)))
    print(t, y, h, x, w)  # Added by me for tests
    return gf(t)[y:y+h, x:x+w]

The above prints 0 0 1080 0 2000 when the scroll effect is applied. Then it prints 0.0 0 1080 0 2000 after write_videofile is called for the first frame. Then for the second frame, it prints 0.0666666666667 0 1080 10.0 2000 which causes it to error, because 10.0 is a float, not an integer.

@tburrows13
Copy link
Collaborator Author

panorama
This is the picture that fails.

@ghost
Copy link

ghost commented Apr 5, 2017

awesome.. I'll give this a try..

@ghost
Copy link

ghost commented Apr 6, 2017

this works for me without modifications.

@mbeacom mbeacom added the bug Issues that report (apparent) bugs. label Apr 12, 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

2 participants