You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using ImageSequenceClip with low framerates, certain frames become repeated because of floating point arithmetic. This should have been fixed in #464 back in 2017 (for some reason I can't link to the issue properly), but I had the same problem in 2.1.2.
Expected Behavior
No frames repeat
Actual Behavior
If using a framerate of 3 fps, the 13th, 16th and 19th frame repeats are repeats of the 12th, 15th and 18th.
Steps and code to Reproduce the Problem
The following code checks if the correct frames are returned
importmoviepy.video.io.ImageSequenceClipimportnumpyasnp# set of frames that are all different levels of greyframes= [np.ones((400, 400, 3))*fforfinnp.linspace(0, 1, 20)]
forframes_per_secondinrange(1,31):
print(f"fps: {frames_per_second}, repeated frames: ", end='')
movie=moviepy.video.io.ImageSequenceClip.ImageSequenceClip(frames, fps=frames_per_second)
last_frame=frames[-1]
fori, frameinenumerate(movie.iter_frames()):
ifnp.any(frame==last_frame):
print(f" {i}", end='')
last_frame=frameprint('')
The issue arises because find_image_index(t) (line 115, ImageSequenceClip.py) compares the given time to self.images_starts, and the floating point arithmetic sometimes causes this to fail.
The fix in #464 ( b7de3cc ) adds a delta (np.finfo(np.float32).eps ~ 1.1920929e-07) to the calculation of the self.images_starts, which now reads:
While using ImageSequenceClip with low framerates, certain frames become repeated because of floating point arithmetic. This should have been fixed in #464 back in 2017 (for some reason I can't link to the issue properly), but I had the same problem in 2.1.2.
Expected Behavior
No frames repeat
Actual Behavior
If using a framerate of 3 fps, the 13th, 16th and 19th frame repeats are repeats of the 12th, 15th and 18th.
Steps and code to Reproduce the Problem
The following code checks if the correct frames are returned
It outputs:
Proposed solution.
The issue arises because
find_image_index(t)
(line 115, ImageSequenceClip.py) compares the given time toself.images_starts
, and the floating point arithmetic sometimes causes this to fail.The fix in #464 ( b7de3cc ) adds a delta (np.finfo(np.float32).eps ~ 1.1920929e-07) to the calculation of the
self.images_starts
, which now reads:However, because of the nature of floating point arithmetic, this delta is only sufficiently large for numbers close to 1.0.
i.e.
A simple solution is to increase the time delta, for example to 1e-6.
This solution would the above test:
(which tests up to 1k frames)
An alternative solution is to change
find_image_index()
:i.e. from:
to
But in this case the changes from b7de3cc should probably be reverted.
Specifications
The text was updated successfully, but these errors were encountered: