Skip to content

Commit

Permalink
Merge pull request #2257 from Breakthrough/issue-2044
Browse files Browse the repository at this point in the history
Ensure `last_read` is always set.
  • Loading branch information
Zulko authored Nov 24, 2024
2 parents bca8f13 + 943217d commit fcc580c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def initialize(self, start_time=0):
# to be read by self.read_frame().
# Eg when self.pos is 1, the 2nd frame will be read next.
self.pos = self.get_frame_number(start_time)
self.lastread = self.read_frame()
self.last_read = self.read_frame()

def skip_frames(self, n=1):
"""Reads and throws away n frames"""
Expand All @@ -144,7 +144,7 @@ def read_frame(self):
"""
Reads the next frame from the file.
Note that upon (re)initialization, the first frame will already have been read
and stored in ``self.lastread``.
and stored in ``self.last_read``.
"""
w, h = self.size
nbytes = self.depth * w * h
Expand Down Expand Up @@ -219,13 +219,18 @@ def get_frame(self, t):
elif (pos < self.pos) or (pos > self.pos + 100):
# We can't just skip forward to `pos` or it would take too long
self.initialize(t)
return self.lastread
return self.last_read
else:
# If pos == self.pos + 1, this line has no effect
self.skip_frames(pos - self.pos - 1)
result = self.read_frame()
return result

@property
def lastread(self):
"""Alias of `self.last_read` for backwards compatibility with MoviePy 1.x."""
return self.last_read

def get_frame_number(self, t):
"""Helper method to return the frame number at time ``t``"""
# I used this horrible '+0.00001' hack because sometimes due to numerical
Expand Down

0 comments on commit fcc580c

Please sign in to comment.