Skip to content

Player: an H.264 non-IDR I-slice at a random access point is a keyframe (seeks in Blu-ray remuxes stuck on Buffering) - #1085

Merged
GLinnik21 merged 2 commits into
plxnative:mainfrom
danzig666:claude/h264-recovery-point-keyframes
Oct 29, 2026
Merged

GLinnik21 merged 2 commits into
plxnative:mainfrom
danzig666:claude/h264-recovery-point-keyframes

Conversation

@danzig666

Copy link
Copy Markdown
Contributor

Summary

Seeking in some Blu-ray remuxes never finished: the player sat on "Buffering…" at the target for good, through both stuck-seek retries and the reload. In these files only the very first frame is an IDR; every later point a seek lands on is an ordinary I-frame behind a recovery point. The player only accepted an IDR as the frame to restart from, so it waited for one that never came. It now also accepts such an I-frame.

Technical details

  • ff::packet_to_annexb counted an H.264 AU as a keyframe only for an IDR NAL (type 5). The post-seek rebase in engine::feed_stream (es == 1 && key != 0) drops every AU until a keyframe, so a file with one IDR could never rebase after a seek.
  • A non-IDR slice NAL (type 1) whose slice_type is I (2 or 7) now counts as a keyframe when the packet carries AV_PKT_FLAG_KEY, or when an SPS precedes it in the same AU (Blu-ray streams repeat the parameter sets in band at each random access point). P- and B-slices never count. The parameter-set prepend then behaves as it does for an IDR. h264_slice_is_intra reads the slice header's first two Exp-Golomb fields; open-GOP leading B-frames are clamped by the existing fp < 0 guard, as for an HEVC CRA, which already counted.
  • The in-band-SPS condition is broader than the container flag: in a stream that repeats SPS/PPS in every AU (x264 --repeat-headers, broadcast TS), an unflagged scenecut I-frame would also count. The rebase is the only consumer of the AU key flag, and a seek normally lands on an indexed (flagged) packet first. I kept the condition because the TV test below cannot tell which of the two conditions carried the fix. Dropping it would leave the flag-only rule, if you prefer that.
  • Not covered: ts_h264_access_unit (the HLS/TS path) still counts only IDR, so a remux of such a file copied into TS segments would still fail with "HLS segment does not begin with an IDR". That could take the same I-slice rule as a follow-up.

Testing

  • New tests in ff_packet_framing_tests.rs: a flagged non-IDR I-slice is a keyframe and gets the parameter sets (slice_type 7 and 2); a flagged P- or B-slice and an unflagged bare I-slice are not; an I-slice behind an in-band SPS is. The first one failed against the IDR-only rule before the fix.
  • make test-crate C=plx_media T=ff:: (226 passed), make check-nodef, make lint, ci/check-deps.sh.
  • On a TV: an LG 2022 OLED (webOS 10.2.2, ponytail-paparoa, board O22), direct play of a 1080p H.264 + AC3 Blu-ray remux MKV (19 GB). Before the fix, a seek to 0:32 logged AU#0 size=177514 key=false and nothing was fed until the reload, which stuck the same way. With the fix, seeking works, from a fork build of the same change.

Generated by Claude Code

claude and others added 2 commits October 26, 2026 22:55
A Blu-ray remux has one IDR, its first frame; every later random access
point is an I-slice behind a recovery point, flagged a keyframe by the
container and indexed by its Cues, with the SPS/PPS repeated in band.
Only IDR counted as a keyframe, so after a seek the post-seek rebase
dropped every AU waiting for one and the player stayed on Buffering
through both stuck-seek retries and the reload. packet_to_annexb now also
counts a non-IDR I-slice when the packet carries AV_PKT_FLAG_KEY or an
SPS ahead of it in the same AU; P- and B-slices never count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KBgjCe8KH6Nnp3K51Fybrv
…cess point

The keyframe rule in the demuxer contract (docs/ffmpeg-demuxer-plan.md) and in the opening sentence of packet_to_annexb's doc comment named only the IDR; a non-IDR I-slice flagged AV_PKT_FLAG_KEY, or behind an in-band SPS, is a keyframe too.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit da8424b into plxnative:main Oct 29, 2026
13 checks passed
@GLinnik21

Copy link
Copy Markdown
Collaborator

Merged, thank you! I only updated two doc lines that still said a keyframe is IDR-only.

danzig666 pushed a commit to danzig666/plx-native that referenced this pull request Nov 4, 2026
Upstream rebuilt the player HUD as packages (appkit/player_hud.rs is now
a directory), merged this fork's plxnative#986 (edge scrolling) and plxnative#1085 (H.264
recovery-point keyframes), and added its own automatic intro/credits
skipping (plxnative#1227). Conflicts take upstream's side throughout; the fork's
own Skip intros / Skip credits settings, notices and strings are dropped
in favour of plxnative#1227. The fork's player additions (clock, media line,
subtitle-tone dim, BACK-hide jitter gate) and its fork.18 pointer changes
are re-applied on top in their own commits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KBgjCe8KH6Nnp3K51Fybrv
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.

3 participants