Repository navigation
Fix stale slice header bytes in the single SEI NAL unit - #988
Open
danielcamposramos wants to merge 1 commit into
Open
danielcamposramos wants to merge 1 commit into
danielcamposramos wants to merge 1 commit into
Conversation
With --single-sei the prefix SEI messages of an access unit are written into m_bs and serialized as one NAL unit. m_bs is reset before them only by the access unit delimiter or by the repeated stream headers, so with --no-aud, on a picture without repeated headers, it still holds the previous picture's slice header and those bytes are written in front of the first SEI message. FFmpeg's trace_headers then reports "Invalid SEI message: payload_size too large". On master this happens with --hrd --single-sei --no-aud --no-repeat-headers (47 of 48 SEI NAL units in a 48 picture encode), and with --frame-packing as reported on Multicorewareinc#986. Reset m_bs in that case. Streams that were already correct do not change: with --aud, without --single-sei, and on keyframes with --repeat-headers the output is byte-identical. Assisted-by: Claude Opus via Claude Code
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.
With
--single-sei, the prefix SEI messages of an access unit are written intom_bsand serialized as one NAL unit.m_bsis reset before them only by the access unit delimiter or by the repeated stream headers.With
--no-aud, on a picture without repeated headers, it still holds the previous picture's slice header, and those bytes are written in front of the first SEI message.@vunguyen1989 found it while reviewing #986 and asked for the fix as its own pull request, since it affects master on its own.
Reproducing it on master
FFmpeg reports
Invalid SEI message: payload_size too largefor 47 of the 48 SEI NAL units.Before POC 12, for example, the NAL unit is
4E 01 D0 59 FE 20 EC 00 07 80 ...: the five bytes after the NAL unit header are the start of the previous picture's slice header, and the buffering period SEI follows them.The fix
FrameEncoder::compressFrame()resetsm_bsbefore the SEI messages whenbSingleSeiNalis set, unless the picture is a keyframe with repeated headers.That exception is the first term of
isSei: there the stream headers have already resetm_bsand collected their own SEI messages in it, and those are kept.How it was tested
Built from master f2cf32d, 8 bit,
--frame-threads 1 --pools none, 48 pictures, keyint 12.--single-sei --no-aud --no-repeat-headers --hrd--single-sei --no-aud --repeat-headers --hrd --max-cll 1000,400--single-sei --no-aud --no-repeat-headers --eos --hrd--single-sei --aud --hrdEvery prefix SEI NAL unit in the fixed streams parses exactly, with the messages ending at the rbsp trailing bits.
With the frame packing option of #986 on top, the same holds for types 3, 4 and 5, with and without AUD and repeated headers, in 8 and 10 bit, and FFmpeg reads the frame packing message on every picture.
Notes
No primitives are touched, so I did not run TestBench.