@@ -189,7 +189,10 @@ def seek(self, target: Union[FrameTimecode, float, int]):
189189 raise SeekError ("Target frame is beyond end of video!" ) from ex
190190 raise
191191 self ._last_frame = self ._reader .lastread
192- self ._frame_number = target .frame_num
192+ self ._frame_number = min (
193+ target .frame_num ,
194+ FrameTimecode (self ._reader .infos ["duration" ], self .frame_rate ).frame_num - 1 ,
195+ )
193196
194197 def reset (self ):
195198 """Close and re-open the VideoStream (should be equivalent to calling `seek(0)`)."""
@@ -215,16 +218,16 @@ def read(self, decode: bool = True, advance: bool = True) -> Union[np.ndarray, b
215218 return self ._last_frame_rgb
216219 if not hasattr (self ._reader , "lastread" ):
217220 return False
221+ # TODO: In Moviepy2.0 this is broken - lastread is updated in-place in some cases.
218222 self ._last_frame = self ._reader .lastread
219- self ._reader .read_frame ()
220- if self ._last_frame is self ._reader .lastread :
221- # Didn't decode a new frame, must have hit EOF.
223+ frame = self ._reader .read_frame ()
224+ if frame is self ._last_frame :
222225 if self ._eof :
223226 return False
224227 self ._eof = True
225228 self ._frame_number += 1
226229 if decode :
227230 if self ._last_frame is not None :
228231 self ._last_frame_rgb = cv2 .cvtColor (self ._last_frame , cv2 .COLOR_BGR2RGB )
229- return self ._last_frame_rgb
230- return True
232+ return self ._last_frame_rgb if not self . _eof else False
233+ return not self . _eof
0 commit comments