header: implement frame_size_with_refs() #2520
Merged
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.
The spec has a code path in the uncompressed header named frame_size_with_refs(), defined in section 5.9.7, which an inter frame may use to infer its dimensions from one of the seven frames it uses as reference instead of inferring them from the sequence header or ultimately hardcoding them. This path is triggered on non error resilient encodings by signaling frame_size_override_flag == 1, a bit that means that either frame dimensions are coded in the frame, or that an attempt to infer both frame and render dimensions from a reference frame should be done.
For encodings using a SAR other than 1:1, rav1e is currently hardcoding the render sizes on every frame, which is an overhead of about 4 bytes. With this change, for inter frames the encoder will look at each of the seven reference frames and if it finds one where both frame and render sizes are the same as this frame, instead of writing the sizes it will write the bits needed to tell the decoder to infer them from it.
Here's a comparison of the uncompressed header written for inter frames before and after this PR when encoding a 720x480 sample with SAR 2:1.
Before
After
Currently, rav1e has fixed frame and render sizes for the entire video sequence, so it will always signal to use the very first reference frame, but with this change the frame header writing code is ready to handle both frame and render sizes changing in a per-frame basis, if it ever gets implemented.