Skip to content

Support scan() and seek(0) on streams without timestamps - #1783

Draft
NicolasHug wants to merge 1 commit into
packet-from-bytesfrom
raw-stream-scan
Draft

NicolasHug wants to merge 1 commit into
packet-from-bytesfrom
raw-stream-scan

Conversation

@NicolasHug

@NicolasHug NicolasHug commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This is part of a stack that adds demuxer-free decoding to the low-level APIs: decoding packets that don't come from a Demuxer (#1585), demuxing and decoding in different processes, and raw H.264 / HEVC streams (#1771).


Raw H.264 / HEVC elementary streams have no timestamps, so FFmpeg can't seek them to a timestamp. That made VideoStream.scan() fail, because it rewinds the demuxer before and after reading the stream, and made Demuxer.seek() fail entirely (#1771).

  • Rewinding: seek(0) now rewinds such streams by byte offset, so scan() works too.
  • Other seeks: seeking anywhere else still raises, with an explanation. Seeking raw streams to keyframes could be a follow-up.
  • FrameIndex:
    • pts_seconds is NaN for frames without a pts.
    • index_at() and key_frame_seconds_for() raise on a stream with no timestamps at all.
    • The frame count, durations and keyframe positions are available. Without timestamps, those are in decoding order, which for open GOPs isn't where keyframes are displayed. The docs say so, and a test uses an open-GOP HEVC stream.

VideoDecoder still doesn't support raw streams: the low-level APIs are where they're handled.

Part of #1771.

Tests

  • scan() on raw H.264 and HEVC streams.
  • Rewinding mid-stream gives the same packets.
  • Seeking elsewhere raises.

Stack created with GitHub Stacks CLI • Give Feedback 💬

@NicolasHug
NicolasHug added this pull request to stack #1784 October 27, 2026 13:04
@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1783

Note: Links to docs will display an error until the docs builds have been completed.

❌ 19 New Failures, 10 Unrelated Failures

As of commit ba2c9c4 with merge base ffb098a (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 27, 2026
@NicolasHug
NicolasHug force-pushed the raw-stream-scan branch 3 times, most recently from 536c1bb to 976645b Compare October 27, 2026 13:54
Raw H.264 / HEVC elementary streams have no timestamps, so FFmpeg can't
seek them to a timestamp. That made VideoStream.scan() fail (it rewinds
the demuxer before and after reading the stream), and Demuxer.seek()
fail entirely.

seek(0) now rewinds such streams by byte offset, so scan() works too.
Seeking anywhere else still raises, now with an explanation. A
FrameIndex's pts_seconds are NaN for frames without a pts, and index_at()
/ key_frame_seconds_for() raise on a stream with no timestamps at all.
The frame count, durations and keyframe positions (in decoding order)
are available.

Part of #1771.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant