Demote scheduled B-frames without an L1 reference to P#2
Open
mprammer wants to merge 1 commit into
Open
Conversation
A Spiral exact-cadence schedule is computed per full keyint GOP and applied via frame_index % keyint, with no knowledge of stream length. In a partial final GOP a scheduled B frame can reference a forward anchor whose display position lies past end-of-stream; that anchor is never submitted, never decoded, and never enters the DPB. The B then reaches ratecontrol with an empty L1 list, and rate_estimate_qscale() unconditionally dereferences h->fref_nearest[1] / h->fref[1][h->i_ref[1]-1] for B slices -> SIGSEGV on flush. CRF only; fixed-QP frames skip rate_estimate_qscale, which is why the --x264-layer-qps / frame-IR path was unaffected. Mirror x264's normal end-of-stream behaviour: before deriving the slice type, demote a scheduled B/B-ref with no schedule-allowed future reference in the DPB to P. Its past/L0 anchor is always present, so P ratecontrol is defined. Verified on x86 Linux: the exact-cadence CRF encode of a clip with a partial final GOP SIGSEGV'd before and exits cleanly after; removing just the demote call reproduces the crash (A/B). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: mprammer <martin@spiraldb.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Spiral exact-cadence schedule is computed per full keyint GOP and applied modulo keyint, so in a partial final GOP a scheduled B-frame can reference a forward anchor whose display position is past end-of-stream. That anchor is never submitted, never decoded, and never enters the DPB, so the B reaches CRF ratecontrol with an empty L1 list — and rate_estimate_qscale() unconditionally dereferences fref_nearest[1] / fref[1][i_ref[1]-1] for B slices, SIGSEGV'ing on flush. (Fixed-QP frames skip rate_estimate_qscale, which is why only CRF transcodes crashed.) This demotes a scheduled B/B-ref with no schedule-allowed future reference in the DPB to P before the slice type is derived, mirroring x264's normal end-of-stream handling; its past/L0 anchor is always present, so P ratecontrol is well-defined.
Verified on x86 Linux: an exact-cadence CRF encode of a clip whose length isn't a multiple of keyint SIGSEGV'd before and exits cleanly after, and removing just the demote call reproduces the crash.
🤖 Generated with Claude Code