This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 3821db1972 [python] Coalesce initial MP4 range reads for random frames
(#11108)
3821db1972 is described below
commit 3821db1972b87d5cd3ac1d025ec214cc3842ae9a
Author: XiaoHongbo <[email protected]>
AuthorDate: Thu Nov 12 13:58:16 2026 +0800
[python] Coalesce initial MP4 range reads for random frames (#11108)
---
.../pypaimon/multimodal/lerobot/dataset.py | 7 +++++-
.../pypaimon/tests/multimodal_lerobot_test.py | 28 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/paimon-python/pypaimon/multimodal/lerobot/dataset.py
b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
index 98a2be6969..4dd2880fbd 100644
--- a/paimon-python/pypaimon/multimodal/lerobot/dataset.py
+++ b/paimon-python/pypaimon/multimodal/lerobot/dataset.py
@@ -2228,7 +2228,12 @@ def _open_video_decoder(stream, backend=None,
codec_threads=0):
if 0 < hint[1] <= _MAX_METADATA_BYTES and callable(ranges):
source = _RangeBackedVideo(stream.video_length, ranges)
source.video_moov_range = hint
- source.prefetch([(0, min(65536, stream.video_length)),
hint])
+ head = 65536
+ if 0 <= hint[0] and hint[0] + hint[1] <= head:
+ # PyAV may probe past a front-loaded moov. Fetch its
+ # immediate neighborhood in the same range request.
+ head = min(256 * 1024, hint[0] + hint[1] + 128 * 1024)
+ source.prefetch([(0, min(head, stream.video_length)),
hint])
stream.video_bootstrap = source
keyframe_index = ContainerFrameIndex(source,
stream.video_length)
except (ValueError, OSError, RuntimeError, EOFError,
OverflowError, IndexError, struct.error):
diff --git a/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
b/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
index a52d6246b3..99b8ab5f94 100644
--- a/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
+++ b/paimon-python/pypaimon/tests/multimodal_lerobot_test.py
@@ -907,6 +907,34 @@ class LeRobotValidationTest(unittest.TestCase):
with self.assertRaises(OSError):
_open_video_decoder(stream, backend="torchcodec")
+ def test_mp4_bootstrap_prefetch_coalesces_front_moov_probe(self):
+ payload = bytes(512 * 1024)
+ module = "pypaimon.multimodal.lerobot.dataset."
+ cases = (
+ ((28, 11759), [(0, 28 + 11759 + 128 * 1024)]),
+ ((200 * 1024, 11759),
+ [(0, 65536), (200 * 1024, 11759)]),
+ )
+ for hint, expected in cases:
+ with self.subTest(hint=hint):
+ source = io.BytesIO(payload)
+ source.video_length = len(payload)
+ source.video_moov_range = hint
+ calls = []
+
+ def read_ranges(ranges):
+ calls.append(list(ranges))
+ return [payload[start:start + size]
+ for start, size in ranges]
+
+ source.video_read_ranges = read_ranges
+ with patch(module + "ContainerFrameIndex",
+ return_value=object()), patch(
+ module + "_PyAVVideoDecoder",
+ return_value=object()):
+ _open_video_decoder(source)
+ self.assertEqual([expected], calls)
+
def test_indexed_default_backend_falls_back_to_torchcodec(self):
stream = Mock()
stream.video_keyframe_index = FrameIndex(