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

make_frame(t) after concatenation #632

Closed
timpauli opened this issue Aug 16, 2017 · 3 comments · Fixed by #1195
Closed

make_frame(t) after concatenation #632

timpauli opened this issue Aug 16, 2017 · 3 comments · Fixed by #1195

Comments

@timpauli
Copy link

timpauli commented Aug 16, 2017

First of all I wanted to say what a cool project moviepy is and thank everyone who participated in it.

I wrote an algorithm using moviepy which cuts a clip in very tiny bits and applies different effects to it and then concatenates them back together.

Sometimes I get this error message while rendering in the end:

  File "<decorator-gen-51>", line 2, in write_videofile
  File "/usr/local/lib/python3.5/dist-packages/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.5/dist-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 "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 349, in write_videofile
    progress_bar=progress_bar)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 209, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "/usr/local/lib/python3.5/dist-packages/tqdm/_tqdm.py", line 833, in __iter__
    for obj in iterable:
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 475, in generator
    frame = self.get_frame(t)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/compositing/concatenate.py", line 83, in make_frame
    return clips[i].get_frame(t - tt[i])
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 533, in <lambda>
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 533, in <lambda>
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 188, in <lambda>
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 188, in <lambda>
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 188, in <lambda>
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/VideoClip.py", line 533, in <lambda>
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "<decorator-gen-14>", line 2, in get_frame
  File "/usr/local/lib/python3.5/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python3.5/dist-packages/moviepy/video/compositing/concatenate.py", line 83, in make_frame
    return clips[i].get_frame(t - tt[i])
IndexError: list index out of range

Unfortunately I cant narrow it down to a minimal example that repoduces it but in
concatenate.py in line 82 the make_frame(t)-method tries to find out which of the concatenated clips it has to use for the current frame. For this it enumerates over tt but tt has always one item more than there are clips because of its creation in line 71. So in some cases (which exactly I dont fully understand) it reaches this last index which leads to the error above.

You can see that when you make an explicit call to make_frame(t) after concatenation:

from moviepy.editor import concatenate_videoclips

def concatenate_make_frame_error(inputclip):
    concatenate_videoclips([inputclip, inputclip]).make_frame(inputclip.duration * 2)

A quick fix which seems to break nothing would be to adjust line 82 to i = max([i for i, e in zip(range(len(tt) - 1), tt) if e <= t]). So to just skip the last entry for the enumeration.

timpauli added a commit to timpauli/moviepy that referenced this issue Aug 18, 2017
@llazzaro
Copy link

Hi,

I hit the same issue when the subtitles time is outside the video limits.
For example in a video of 10 seconds, if I use a subtitle from (9, 11) I got the same traceback.

Here is a sample code to reproduce the bug:

subs = [
        ((9,1 1), 'sub1'),
]
subtitles = SubtitlesClip(subs, generator)
 cvc = CompositeVideoClip(
        [final_clip, subtitles.set_pos(('center', 'bottom'))],
        use_bgclip=True
    )
    cvc.write_videofile('bug.mp4', fps=30, audio_codec="aac")

Hope it helps!
I could try to fix this issue with a pull request in the future

@tburrows13
Copy link
Collaborator

Hey @llazzaro, I tried, but I couldn't replicate your crash. For me, the background clip just stopped for a second before the video finished.

Even though you are getting an IndexError, this is definitely a different issue, so would you mind opening a new issue with more details (such as the clip that you are using as final_clip)?

@llazzaro
Copy link

@tburrows13 I will try to open a new issue with a test to reproduce the bug, thanks!

@tburrows13 tburrows13 linked a pull request May 15, 2020 that will close this issue
5 tasks
koutoftimer added a commit to koutoftimer/moviepy that referenced this issue Feb 3, 2023
koutoftimer added a commit to koutoftimer/moviepy that referenced this issue Feb 3, 2023
@koutoftimer koutoftimer mentioned this issue Feb 3, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants