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

Seeking by frame is inexact and inconsistent #2115

Open
bzczb opened this issue Feb 14, 2024 · 0 comments · May be fixed by #2117
Open

Seeking by frame is inexact and inconsistent #2115

bzczb opened this issue Feb 14, 2024 · 0 comments · May be fixed by #2117
Labels
bug Issues that report (apparent) bugs. lib-FFmpeg Issues pertaining to dependency FFmpeg. video Related to VideoClip and related classes, or handling of video in general.

Comments

@bzczb
Copy link

bzczb commented Feb 14, 2024

Expected Behavior

clip.make_frame(0) returns frame 0, clip.make_frame(1 / clip.fps) returns frame 1, clip.make_frame(2 / clip.fps) returns frame 2, etc.

Actual Behavior

moviepy largely treats "get the frame at time x" as shorthand for "get the frame displayed at time x", so "get the frame at time 0.00001" should mean "get frame 0". But ffmpeg treats "get the frame at time x" as "skip all frames until reaching time x", so sometimes clip.make_frame(0.00001) will return frame 1, and sometimes it will return frame 0, depending on what's been cached in last_read.

Steps to Reproduce the Problem

Load a video clip which has a different image every frame. (Some clips will have the same image for multiple consecutive frames, which will make it seem like it works correctly)

Here is a clip you can use:

colorbars.mp4
import moviepy.editor as edit

clip = edit.VideoFileClip(r"colorbars.mp4")

test1 = clip.make_frame(0)
test2 = clip.make_frame(0.001)
test3 = clip.make_frame(60)
test4 = clip.make_frame(0.001)
test5 = clip.make_frame(60)
test6 = clip.make_frame(0)
(test1 == test2).all()
True
(test1 == test6).all()
True
(test3 == test5).all()
False
(test2 == test4).all()
False

Specifications

  • Python Version: 3.10
  • MoviePy Version: master
  • Platform Name: Windows

Testing note

test_unusual_order_frame_pos() in test/test_ffmpeg_reader.py is insufficient to detect this bug, as the test video used runs at 1 frame per second exactly. The inconsistency between "moviepy seek" and "ffmpeg seek" does not appear if the timestamps of all frames can be represented exactly in decimal!

@bzczb bzczb added the bug Issues that report (apparent) bugs. label Feb 14, 2024
@bzczb bzczb linked a pull request Feb 14, 2024 that will close this issue
4 tasks
@keikoro keikoro added lib-FFmpeg Issues pertaining to dependency FFmpeg. video Related to VideoClip and related classes, or handling of video in general. labels Feb 14, 2024
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. lib-FFmpeg Issues pertaining to dependency FFmpeg. video Related to VideoClip and related classes, or handling of video in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants