Skip to content

[python] Speed up TorchCodec random video frame reads with persisted indexes - #10821

Open
XiaoHongbo-Hope wants to merge 7 commits into
apache:masterfrom
XiaoHongbo-Hope:python-indexed-torchcodec-reader
Open

XiaoHongbo-Hope wants to merge 7 commits into
apache:masterfrom
XiaoHongbo-Hope:python-indexed-torchcodec-reader

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Explicit TorchCodec reads currently scan videos during initialization, even when a persisted keyframe index is available.

Use the MP4 sample table for timestamp seeks, prefetch metadata and target GOP ranges, and verify returned PTS. Unsupported layouts or failed verification fall back to exact mode. Applies to video_backend="torchcodec"; the default backend is unchanged.

Replica decoders share read-only timelines. Uniform timing uses arithmetic sequences; irregular timing retains one shared pair of arrays. Metadata is released with the last decoder and is not transferred to workers. Keyframe lookup no longer copies an ordinal list.

Tests

57 tests passed with real PyAV/TorchCodec, covering B-frames, VFR, track selection, fallback, million-sample memory bounds, replica sharing and cleanup. Worker cache reset, Python 3.6 syntax, flake8 and diff checks passed.

@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [python] Use persisted video indexes for TorchCodec frame reads [python] Accelerate TorchCodec random video frame reads with persisted indexes Oct 30, 2026
@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [python] Accelerate TorchCodec random video frame reads with persisted indexes [python] Speed up TorchCodec random video frame reads with persisted indexes Oct 30, 2026
@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review October 31, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant