MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / seek

Method seek

scenedetect/backends/pyav.py:250–287  ·  view source on GitHub ↗

Seek to the given timecode. If given as a frame number, represents the current seek pointer (e.g. if seeking to 0, the next frame decoded will be the first frame of the video). For 1-based indices (first frame is frame #1), the target frame number needs to be converted to 0-

(self, target: TimecodeLike)

Source from the content-addressed store, hash-verified

248 return display_aspect_ratio / frame_aspect_ratio
249
250 def seek(self, target: TimecodeLike) -> None:
251 """Seek to the given timecode. If given as a frame number, represents the current seek
252 pointer (e.g. if seeking to 0, the next frame decoded will be the first frame of the video).
253
254 For 1-based indices (first frame is frame #1), the target frame number needs to be converted
255 to 0-based by subtracting one. For example, if we want to seek to the first frame, we call
256 seek(0) followed by read(). If we want to seek to the 5th frame, we call seek(4) followed
257 by read(), at which point frame_number will be 5.
258
259 May not be supported on all input codecs (see `is_seekable`).
260
261 Arguments:
262 target: Target position in video stream to seek to.
263 If float, interpreted as time in seconds.
264 If int, interpreted as frame number.
265 Raises:
266 ValueError: `target` is not a valid value (i.e. it is negative).
267 """
268 if not isinstance(target, FrameTimecode):
269 target = FrameTimecode(target, self.frame_rate)
270 if target < 0:
271 raise ValueError("Target cannot be negative!")
272 beginning = target == 0
273
274 target = self.base_timecode + target
275 if target >= 1:
276 target = target - 1
277 target_pts = self._video_stream.start_time + int(
278 (self.base_timecode + target).seconds / self._video_stream.time_base
279 )
280 self._frame = None
281 self._decoder = None
282 self._container.seek(target_pts, stream=self._video_stream)
283 if not beginning:
284 self.read(decode=False)
285 while self.position < target:
286 if self.read(decode=False) is False:
287 break
288
289 def reset(self):
290 """Close and re-open the VideoStream (should be equivalent to calling `seek(0)`)."""

Callers 5

_handle_eofMethod · 0.95
runMethod · 0.45
save_imagesFunction · 0.45
_detectFunction · 0.45

Calls 2

readMethod · 0.95
FrameTimecodeClass · 0.90

Tested by 1