MCPcopy Index your code
hub / github.com/Breakthrough/PySceneDetect / test_seek

Method test_seek

tests/test_video_stream.py:210–254  ·  view source on GitHub ↗

Validate `seek()` functionality with different offset types.

(self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters)

Source from the content-addressed store, hash-verified

208 assert stream.position_ms == pytest.approx(0, abs=TIME_TOLERANCE_MS)
209
210 def test_seek(self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters):
211 """Validate `seek()` functionality with different offset types."""
212 stream = vs_type(test_video.path)
213
214 # Seek to a given frame number (int).
215 stream.seek(200)
216 assert stream.frame_number == 200
217 assert stream.position == stream.base_timecode + 199
218 assert stream.position_ms == pytest.approx(
219 1000.0 * (199.0 / float(stream.frame_rate)), abs=TIME_TOLERANCE_MS
220 )
221 stream.read()
222 assert stream.frame_number == 201
223 assert stream.position == stream.base_timecode + 200
224 assert stream.position_ms == pytest.approx(
225 1000.0 * (200.0 / float(stream.frame_rate)), abs=TIME_TOLERANCE_MS
226 )
227
228 # Seek to a time in seconds (float).
229 stream.seek(2.0)
230 assert stream.frame_number == round(stream.frame_rate * 2.0)
231 # FrameTimecode is currently one "behind" the frame_number since it
232 # starts counting from zero. This should eventually be changed.
233 assert stream.position == (stream.base_timecode + 2.0) - 1
234 assert stream.position_ms == pytest.approx(
235 2000.0 - (1000.0 / stream.frame_rate), abs=1000.0 / stream.frame_rate
236 )
237 stream.read()
238 assert stream.frame_number == 1 + round(stream.frame_rate * 2.0)
239 assert stream.position == stream.base_timecode + 2.0
240 assert stream.position_ms == pytest.approx(2000.0, abs=1000.0 / stream.frame_rate)
241
242 # Seek to a FrameTimecode.
243 stream.seek(stream.base_timecode + 2.0)
244 assert stream.frame_number == round(stream.frame_rate * 2.0)
245 # FrameTimecode is currently one "behind" the frame_number since it
246 # starts counting from zero. This should eventually be changed.
247 assert stream.position == (stream.base_timecode + 2.0) - 1
248 assert stream.position_ms == pytest.approx(
249 2000.0 - (1000.0 / stream.frame_rate), abs=1000.0 / stream.frame_rate
250 )
251 stream.read()
252 assert stream.frame_number == 1 + round(stream.frame_rate * 2.0)
253 assert stream.position == stream.base_timecode + 2.0
254 assert stream.position_ms == pytest.approx(2000.0, abs=1000.0 / stream.frame_rate)
255
256 def test_seek_start(self, vs_type: ty.Callable[..., VideoStream], test_video: VideoParameters):
257 """Validate behaviour of `seek()` at the start of a video."""

Callers

nothing calls this directly

Calls 2

seekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected