From 1ba225c4ca086db46b91024a444a95b679d4d7c3 Mon Sep 17 00:00:00 2001 From: CarolinePascal Date: Wed, 24 Jun 2026 17:42:27 +0200 Subject: [PATCH] fix(PyAV container seek): fixing initial PyAV container seek to be robust againsy codec choice --- src/lerobot/datasets/video_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lerobot/datasets/video_utils.py b/src/lerobot/datasets/video_utils.py index 67749c3d9..944428f4c 100644 --- a/src/lerobot/datasets/video_utils.py +++ b/src/lerobot/datasets/video_utils.py @@ -152,7 +152,13 @@ def decode_video_frames_pyav( # https://pyav.basswood-io.com/docs/stable/api/container.html#av.container.InputContainer.seek with av.open(video_path) as container: stream = container.streams.video[0] - container.seek(int(first_ts * av.time_base), backward=True) + # Seek to the nearest keyframe at or before `first_ts` with a 1 frame margin + container.seek( + round(first_ts / stream.time_base) - 1, + backward=True, + any_frame=False, + stream=stream, + ) for frame in container.decode(stream): if frame.pts is None: