Repository navigation
[python] Share video metadata cache across collators - #11438
XiaoHongbo-Hope wants to merge 4 commits into
Conversation
f443f00 to
76eea65
Compare
JingsongLi
left a comment
There was a problem hiding this comment.
Please fix the cache key before merging. The documentation and test comments are suggestions.
| self._decode_pool = _VideoDecodePool() | ||
| self._decoders = OrderedDict() | ||
| self._video_metadata_cache = _VideoMetadataCache() | ||
| self._video_metadata_cache = (metadata_cache if metadata_cache is not None |
There was a problem hiding this comment.
[P1] Fix before merge
The shared cache uses the video descriptor as its key, while each collator resolves that descriptor through its own FileIO. Two S3-compatible endpoints can serve different MP4s for the same URI and byte range. In a local repro with two FileIO test doubles and real MP4s, the second PyAV collator returned frame ordinal 7 for a request for ordinal 5 after reusing the first video's index.
Please include the resolved storage namespace in the cache key. When a stable namespace is unavailable, scope entries to the FileIO instance. A regression test should cover two sources that resolve the same descriptor to different media.
| in each DataLoader worker. `decoder_factory(stream)` opens any codec library; | ||
| `decode_fn(decoder, frame_index, row)` receives the embedded frame ordinal. | ||
|
|
||
| To share parsed MP4 indexes across collators in one process, pass the same |
There was a problem hiding this comment.
[P2] Suggestion
The SequentialPyAvDecoder example calls av.open() for every decoder session, so passing metadata_cache to these collators still repeats MP4 parsing. The public LeRobot and window dataset APIs also create private per-collator caches. Consider passing metadata_cache through an existing public indexed reader API and showing two collators reuse one index in the same process.
| stream.video_metadata_cache = cache | ||
| stream.video_metadata_key = 'same-video' | ||
| stream.video_read_ranges = lambda ranges: [mp4[o:o + n] for o, n in ranges] | ||
| barrier.wait(timeout=5) |
There was a problem hiding this comment.
[P2] Suggestion
The barrier releases the callers together, so the first parse can finish before any other caller checks the cache. All three new concurrency test cases passed locally with get_or_load replaced by a plain lookup, load, and store. Consider holding the first loader with an event until the other calls are waiting on it, then releasing it and asserting that the loader ran once.
What changed
VideoMetadataCacheso collators in the same process can share parsed MP4 metadata while retaining the existing per-collator default.Why
Multiple
VideoFrameCollatorinstances serving requests for the same physical video can each parse its MP4 sample table. Sharing a bounded cache avoids that repeated metadata work. The cache remains process-local; applications with separate DataLoader processes need a shared media service if they want reuse across those processes.Tests
python -m pytest -q paimon-python/pypaimon/tests/multimodal_video_test.py paimon-python/pypaimon/tests/mp4_test.py paimon-python/pypaimon/tests/indexed_torchcodec_test.py(74 passed, 37 skipped; optional TorchCodec/PyTorch cases unavailable in this environment)git diff --check