Fix Sequence Header film-grain rewriting with padded AV1 OBUs - #44
Open
rampageX wants to merge 1 commit into
Open
Fix Sequence Header film-grain rewriting with padded AV1 OBUs#44rampageX wants to merge 1 commit into
rampageX wants to merge 1 commit into
Conversation
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.
Fix Sequence Header film-grain flag rewriting with padded AV1 OBUs
Summary
This fixes
grav1synth applycorrupting some AV1 streams whenfilm_grain_params_presentis not located in the final byte of the declaredSequence Header OBU payload.
Affected streams can fail with:
Reproduction
One reproducible NVENC AV1 stream used a 3840x1606 Sequence Header.
Before rewriting:
After the old write path:
The next OBU was then parsed at the wrong byte boundary and its
obu_forbidden_bitbecame 1.The clean AV1 stream validates before
grav1synth apply, so corruption occursduring Sequence Header rewriting.
Root cause
There are two related assumptions in the existing write path:
sequence.rsusesobu_out.last_mut()when togglingfilm_grain_params_present.This assumes the flag is always located in the last byte of the declared
Sequence Header payload. That is not true when trailing/alignment bytes are
present.
obu.rsadjusts the Sequence Headerobu_sizeby comparing the number ofbytes written with the number of syntax bytes consumed.
The syntax parser can stop before trailing/alignment bytes, even though the
complete declared payload is mirrored into the output. This can falsely make
the Sequence Header appear to have grown.
Fix
film_grain_params_presentusingTraceCtx::pos().obu_out.last_mut().obu_sizeunchanged.Validation
film_grain_params_key_frame_forces_update_and_uses_420_zero_luma_shortcuttest, whose fixture writes
grain_scaling_minus_8 = 2but expectsscaling_shift == 8instead of 10.fix.
Scope
The change is limited to:
No container, encoder, preset, or grain-model behavior is changed.