diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py index 9629f18e3..332fe340e 100644 --- a/moviepy/video/VideoClip.py +++ b/moviepy/video/VideoClip.py @@ -902,7 +902,9 @@ def __init__(self, data, data_to_frame, fps, is_mask=False, has_constant_size=Tr self.fps = fps def make_frame(t): - return self.data_to_frame(self.data[int(self.fps * t)]) + return self.data_to_frame( + self.data[min(int(self.fps * t), len(self.data) - 1)] + ) VideoClip.__init__( self, @@ -1424,7 +1426,7 @@ def __init__( VideoClip.__init__( self, - make_frame=lambda t: frame_array[int(t * fps)], + make_frame=lambda t: frame_array[min(int(t * fps), self.total_frames - 1)], is_mask=is_mask, duration=duration, ) diff --git a/moviepy/video/fx/freeze.py b/moviepy/video/fx/freeze.py index 76f13d96d..4618fde64 100644 --- a/moviepy/video/fx/freeze.py +++ b/moviepy/video/fx/freeze.py @@ -16,7 +16,7 @@ def freeze(clip, t=0, freeze_duration=None, total_duration=None, padding_end=0): """ if t == "end": - t = clip.duration - padding_end - 1 + t = clip.duration - padding_end if freeze_duration is None: freeze_duration = total_duration - clip.duration diff --git a/tests/test_fx.py b/tests/test_fx.py index fdd97b457..6145accff 100644 --- a/tests/test_fx.py +++ b/tests/test_fx.py @@ -141,7 +141,7 @@ def test_freeze(): target3 = BitmapClip([["R"], ["G"], ["G"], ["B"]], fps=1) assert clip3 == target3 - clip4 = freeze(clip, t="end", total_duration=4, padding_end=1) + clip4 = freeze(clip, t="end", total_duration=4, padding_end=2) target4 = BitmapClip([["R"], ["G"], ["G"], ["B"]], fps=1) assert clip4 == target4