Repository navigation
feat(playback): use the shared ladder for automatic streaming quality - #1671
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b65015003
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
7b65015 to
e9c0f87
Compare
d69004f to
c480d51
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9c0f8742c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| class := ladderClassesFrom(targetHeight)[0] | ||
| width, effectiveHeight := FitLadderBox(source.Width, source.Height, class.Height) |
There was a problem hiding this comment.
Fit width before preserving the selected class
When the source height fits the selected class but its width does not, the earlier height-only return bypasses this box fitting. For example, a 2560x1080 source at 5 Mbps with a 7 Mbps estimate earns the 1080p class and is preserved at 2560x1080 instead of fitting the class's 1920x1080 box; a client whose decoder is limited to 1920-wide output can then receive or be offered an unsupported encode. Decide preservation by comparing both dimensions returned by FitLadderBox, rather than by source height alone.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this one as is on purpose. A source whose height fits the class is preserved even when it is wider than the 16:9 box: Silo catalogs a 2560x1080 file as 1080p (the scanner's class bounds run to 2560x1440), and box-fitting it would turn a file that direct-plays today into a 1920x810 transcode even on fast links, since reaching the 2160p class needs a 25 Mbps estimate. Bandwidth is still honored: with the fix in 97ed5df, a source whose bitrate exceeds the estimate's budget is re-encoded, and the transcode path box-fits whenever it runs.
e9c0f87 to
97ed5df
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97ed5df42c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e243f9c to
5d986b6
Compare
97ed5df to
f4c9334
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4c9334e41
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
f4c9334 to
ea1a8eb
Compare
5d986b6 to
50eaf90
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea1a8eb3e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
50eaf90 to
6983d96
Compare
ea1a8eb to
8b0969f
Compare
e0f46c2 to
d4068da
Compare
8b0969f to
ce780f6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce780f6ecb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ce780f6 to
2b692e9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b692e9cbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2b692e9 to
31f4faf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 31f4faf48b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
31f4faf to
6b84d4b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b84d4b576
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6b84d4b to
37d9c69
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37d9c69812
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 008c90c659
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f1d40071e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 725494e0b5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7638ee8c6b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| takes := func(decoder VideoDecodeCapabilityV3, width, height int) bool { | ||
| return (decoder.MaxWidth <= 0 || width <= decoder.MaxWidth) && (decoder.MaxHeight <= 0 || height <= decoder.MaxHeight) && | ||
| (decoder.MaxFrameRate <= 0 || source.FrameRate <= decoder.MaxFrameRate+0.01) |
There was a problem hiding this comment.
Check the H.264 level when fitting exact decoders
Fresh evidence beyond the earlier size and frame-rate fixes is an exact H.264 decoder with Levels: []int{31}: takes accepts it for a 1920×1080 target because it checks only dimensions and frame rate. With a 7 Mbps estimate, the new ladder can therefore return a 1080p H.264 encode that requires level 4.0 or higher, even though the authoritative decoder capability supports only level 3.1; the previous 720p target fit that level. Derive the output level with h264LevelFor and step down until an exact-tier decoder accepts it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this one out of this PR. HLS H.264 streams signal a fixed level: the libx264 recipe writes -level 4.1 on every HLS encode (appendVideoArgs, unchanged from main), and the hardware encoders pick their own. A level-3.1-only decoder therefore gets level 4.1 at 720p just as at 1080p, and stepping the size down would not make the stream match its level list. Honoring H.264 level lists in HLS needs the recipe to select and freeze a level per output. That is the same open item the planner already notes for HEVC (hlsHEVCOutputSupportedV3 keeps level-bound HEVC clients on H.264 until that exists). It belongs in its own change. Downloads do honor levels, because their encodes let libx264 choose the level and the resolver checks it (#1670).
4a51793 to
776f8ee
Compare
7638ee8 to
6c123e9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c123e9046
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if width == 0 { | ||
| width = class.Width | ||
| } | ||
| if anyTakes(width, height) || i == len(classes)-1 { |
There was a problem hiding this comment.
Reject H.264 output when no attested decoder accepts it
Fresh evidence beyond the earlier decoder-size fix is the i == len(classes)-1 fallback, which accepts the 480p candidate even when anyTakes is false. For an exact client whose only H.264 decoder is limited to 640×360, a required transcode is therefore returned as 854×480; the later delivery check validates only the codec, so the client receives a recipe outside its declared bounds. This also contradicts the changed invariant in docs/architecture/quality-ladder.md:34-38 that stepping down continues until a decoder takes the fitted size; return an unavailable result when even the smallest class is unsupported.
AGENTS.md reference: AGENTS.md:L109-L116
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping the smallest-class floor, for the reason I gave on the earlier thread about the 1280x962 decoder: H.264 is the universal HLS output, and no device the apps run on decodes below 480p. You are right that the ladder doc said otherwise. quality-ladder.md (3d68d37) now says streaming steps down until an attested H.264 decoder takes the frame and stops at the smallest class if none does. It also says downloads answer quality_unavailable in that case, because a download plays offline and cannot fall back. The same commit also checks the step-down against the even frame the encoder writes, so an odd-width source cannot pass a decoder limit by one pixel.
Automatic streaming quality, the plain resolution preferences, bandwidth caps and jellycompat each had their own bitrate-to-resolution table, and they disagreed with each other and with download presets. All of them now read the shared ladder: 80% of the bandwidth budget earns a class for the source's frame rate, the source is fit into that class's box so a scope film at 1080p streams at 1920x800, and a 540p class sits between 720p and 480p. The encode never targets more than that 80% budget, and a source that fits the class but exceeds the estimate's budget is re-encoded at its own size instead of sent as-is. Explicit menu rungs keep their own table. An original-quality route that still needs a video transcode labelled a 3840x1600 source "1080p", which scaled it to 2592x1080 while the plan reported 3840x1600. It now keeps the exact source height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… video budget An automatic transcode that only scales a low-bitrate source down could target the class bitrate even when the source used fewer bits; it now stays within the source's own bitrate, counted as H.264. jellycompat chose its class from the client's whole bitrate ceiling while encoding at the video share after audio and mux overhead; the class now follows that video budget. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… bitrates A route that keeps the source frame but still encodes labeled an odd source height such as 1081p, which the scale helpers reject, leaving an odd frame for a 4:2:0 encoder. Round the label down to the even height. Automatic quality sent a source of unknown bitrate as-is whenever its class fit the estimate, so a 7 Mbps estimate could stream a 1080p file of any bitrate. Count an unknown bitrate as the full bitrate of the class it would be sent at, so it goes as-is only when the budget covers that. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Automatic quality bounded the target by the source height before snapping to the ladder, so a 1920x800 film under a 1080p estimate snapped to 720p: over its budget it was scaled to about 1276x532 at 2 Mbps instead of being re-encoded at its own size, and with an unknown bitrate it was sized as a 2 Mbps stream. A target that keeps the source height now snaps into the class the source's frame belongs to by both dimensions, within the class the preference, device, bandwidth or cap allows. jellycompat no longer upscales a track known only by its height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An automatic transcode that keeps the source frame labeled an odd height such as 1079p, which the scale helpers reject, so the odd frame reached a 4:2:0 encoder. Round the fitted height down to even and report the width scale=-2 gives it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The quality policy caps a scaled encode at the source's bitrate counted as H.264, and the planner can choose HEVC afterwards without revisiting it, so a 3 Mbps HEVC source converted to 1080p HEVC could target 5 Mbps. Re-cap the bitrate at the source's bits counted as HEVC when HEVC output is chosen. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…64's on fallback The planner checked the HEVC decoder against the H.264-equivalent bitrate before capping it for HEVC, so a decoder limited to 4 Mbps refused a 3 Mbps HEVC encode and an HEVC-only delivery had no route. Cap first and check that candidate. A failed HEVC attempt now falls back to H.264 at the bitrate the policy chose for H.264 instead of the HEVC cap. Routes that keep the source size also report the even frame they encode (1918x1080 for a 1920x1081 source), so the HEVC decoder check sees the real output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With the shared ladder a 7 Mbps cap earns the 1080p class, so a 1080p source of unknown bitrate passed the cap check and was sent unchanged. The cap is a hard ceiling: treat an unknown video bitrate as over it, as the server bitrate cap already does, so the source is re-encoded within the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The planner checked the HEVC decoder against the video bitrate before a server bitrate cap reserved its AAC and mux share, so an HEVC-only client whose decoder took the capped rate was refused over the uncapped one and had no route. Reserve the share first; it does not depend on the video codec. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The protocol doc still promised height-only behavior for plain resolution labels, which now fit the source into the class box like auto, and said a cap re-encodes only a source known to exceed it. State both rules as the planner applies them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…rate A route that keeps the source size but still re-encodes it (a codec the client cannot play, or a subtitle burn) skipped the HEVC cap, so an 8 Mbps H.264 source was checked as an 8 Mbps HEVC output and an HEVC-only client with a 6 Mbps decoder had no route. Cap every HEVC encode; the cap only lowers the bitrate when HEVC is the more efficient codec. Document that a source whose height fits the class is sent as-is even when it is wider than the 16:9 box. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…bitrate HLS treats H.264 as the universal output and never checked its bitrate against the client's decoder. The shared ladder reaches 1080p at lower estimates, so a 7 Mbps estimate now targets 5.6 Mbps where the previous ladder chose 2 Mbps, past an H.264 decoder that attests a 4 Mbps limit. Lower an H.264 target to the limit of an attested decoder that takes the output size; HEVC output keeps its own decoder check. Qualify the ladder invariants for the streaming preservation exception and the H.264 bound. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s size A client whose attested H.264 decoders stop at 1280x720 received a 1080p H.264 target at a 7 Mbps estimate, where the previous ladder chose 720p. Size the H.264 candidate to the tallest class an attested H.264 decoder takes before bounding its bitrate; HEVC output keeps its own class, and the H.264 fallback after a failed HEVC attempt uses the H.264 size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ecoder Snapping an attested H.264 decoder's limits to a ladder box let a 1280x962 decoder count as 1080p, so a 1920x1080 target passed although it is wider than the decoder. Step down class by class until the fitted size itself fits an attested decoder, stopping at the smallest class since H.264 stays the universal HLS output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A source whose size fits the estimate but whose codec the client cannot play is converted at its own size, and that conversion skipped the H.264 decoder fit, so an H.264-only client with a 720p decoder received a 1080p H.264 stream. Fit any H.264 encode the attested decoders cannot take, scaled or not. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… too Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The decoder fit compared only width and height, so a 60 fps source was sent at 1080p to a client whose 1080p H.264 decoder stops at 30 fps and whose 60 fps decoder stops at 720p. The encode keeps the source frame rate, so a decoder must take it too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The H.264 decoder fit compared box-fit sizes that scale=-2 later evens, so an odd-width source could pass a decoder limit it then exceeded by a pixel. Check the encoded frame, sharing encodedFrame with downloads and the source-size routes. The ladder doc now states the smallest-class floor for streaming and the unavailable answer for downloads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
776f8ee to
e4197a0
Compare
6c123e9 to
3d68d37
Compare
* feat(downloads): pair download presets with a resolution ladder A download preset set only a bitrate. The output resolution came from the client's coarse max_resolution, so a 4K source downloaded at 1 Mbps by a client without caps was encoded at 2160p, and Apple's deliberate "1080p" ceiling capped every converted download at 1080p. Each preset now earns a resolution from one shared ladder (2160p at 20 Mbps, 1080p at 10 and 5, 720p at 2, 480p at 1 Mbps at <=30 fps; higher frame rates drop a class, HEVC stretches the budget). The encode never enlarges the source, box-fits cinema aspects, never exceeds the source's own bitrate, and steps down until the device's attested decoder takes it. HEVC is used when the server allows HEVC encoding and the caps attest an 8-bit HEVC decoder. When a preset would leave an SDR source unchanged and the device plays it, the source is served and the row still records the requested preset. Download encodes use a slower preset, let libx264 choose the level, and tag HEVC hvc1 so Apple players open it. The downloads capability adds quality_options with each preset's bitrate and maximum height for labels. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): honor decoder frame rate, profile and bitrate limits The download size choice read only a decoder's width and height. A decoder that cannot take the source's frame rate, or at the exact tier does not list the High profile the H.264 encode produces, is now skipped; a level-bound HEVC decoder keeps the encode on H.264, as HLS does; and the target bitrate stays within the chosen decoder's maximum. The ladder's comment and architecture note no longer claim that streaming and jellycompat read the table; they do not until they move onto it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): bound downloads by H.264 level and decoder bitrate At the exact tier an H.264 decoder's level list now bounds the output: each size is checked against the level libx264 would pick for it (including its doubled rate buffer), and the level also caps the bitrate. A decoder bitrate limit now lowers the budget the ladder class is chosen from, so a 3 Mbps decoder no longer gets a 1080p class. When frame-rate or profile checks leave no H.264 decoder, the largest decoder's size still bounds the output instead of leaving it unbounded. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): choose the decoder by achievable output and honor attested lists Pick the strict-tier decoder whose limits reach the tallest ladder class instead of the one with the largest frame, so a 4K decoder capped at a low bitrate no longer drags a download below what a second decoder plays. Check profile and level lists on platform-attested software decoders, as playback does; only platform-attested hardware decoders are exempt. When strict caps attest no decoder for any codec the server may encode, answer quality_unavailable rather than producing H.264 the device never listed. Label quality_options with the transcode ceiling a policy override sets, matching what Resolve produces. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): stop presets at 1080p without 4K and check levels at the encode bitrate With 4K transcoding off, quality_options advertised presets up to 1080p, but a 20 Mbps request could still serve a 4K original or keep a 1440p source at its size. Cap the preset class at 1080p in that case, which also matches the documented quality_unavailable answer for 4K titles. Check a decoder's H.264 level at the bitrate the encoder will get, which never exceeds the source's own, so a 3 Mbps 1080p source is not scaled down for a level-4.0 decoder. A decoder smaller than the 480p class no longer receives 480p output; with no decoder that takes a class, the preset is unavailable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep a source known only by its height within the class FitLadderBox returned zeros whenever the width was unknown, so a caller fell back to the class box and could enlarge a short source. Keep such a source's own height when it fits the class and the class height when it is taller, leaving the width unknown. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): give an odd source frame an even size when encoding it A download encode that keeps the source frame passed no scale, so an odd height or width reached a 4:2:0 encoder unchanged and could fail. Scale such a frame to the even height at or below it; scale=-2 evens the width. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): scale to any even height a box fit produces The scale parser rejected heights below 144, so a very wide source fitted into a small class (1280x100 into the 480p box is 844x66) was left unscaled while its recipe claimed the fitted size. Accept every even height up to 4320. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): cap preset targets at the account's quality ceiling quality_options already capped each preset at the account's max playback quality, but Resolve applied only a policy override's ceiling, so with 4K transcoding on a 1080p account could prepare a 2160p artifact that the serve-time access check then refused. Apply the narrower of the two. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): check decoder bounds against the frame the encoder writes A source that fits a class keeps its size, but an odd frame is evened by scale=-2, so a 1917x1080 source was checked against a 1917-wide decoder and then encoded 1918 wide. Check each class at the frame the encoder actually produces. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(playback): use the shared ladder for automatic streaming quality (#1671) * feat(playback): use the shared ladder for automatic streaming quality Automatic streaming quality, the plain resolution preferences, bandwidth caps and jellycompat each had their own bitrate-to-resolution table, and they disagreed with each other and with download presets. All of them now read the shared ladder: 80% of the bandwidth budget earns a class for the source's frame rate, the source is fit into that class's box so a scope film at 1080p streams at 1920x800, and a 540p class sits between 720p and 480p. The encode never targets more than that 80% budget, and a source that fits the class but exceeds the estimate's budget is re-encoded at its own size instead of sent as-is. Explicit menu rungs keep their own table. An original-quality route that still needs a video transcode labelled a 3840x1600 source "1080p", which scaled it to 2592x1080 while the plan reported 3840x1600. It now keeps the exact source height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): bound auto transcodes by the source and jellycompat by video budget An automatic transcode that only scales a low-bitrate source down could target the class bitrate even when the source used fewer bits; it now stays within the source's own bitrate, counted as H.264. jellycompat chose its class from the client's whole bitrate ceiling while encoding at the video share after audio and mux overhead; the class now follows that video budget. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep source-size labels even and budget unknown source bitrates A route that keeps the source frame but still encodes labeled an odd source height such as 1081p, which the scale helpers reject, leaving an odd frame for a 4:2:0 encoder. Round the label down to the even height. Automatic quality sent a source of unknown bitrate as-is whenever its class fit the estimate, so a 7 Mbps estimate could stream a 1080p file of any bitrate. Count an unknown bitrate as the full bitrate of the class it would be sent at, so it goes as-is only when the budget covers that. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep cropped sources in the class they earned Automatic quality bounded the target by the source height before snapping to the ladder, so a 1920x800 film under a 1080p estimate snapped to 720p: over its budget it was scaled to about 1276x532 at 2 Mbps instead of being re-encoded at its own size, and with an unknown bitrate it was sized as a 2 Mbps stream. A target that keeps the source height now snaps into the class the source's frame belongs to by both dimensions, within the class the preference, device, bandwidth or cap allows. jellycompat no longer upscales a track known only by its height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): re-encode an odd source frame at an even size An automatic transcode that keeps the source frame labeled an odd height such as 1079p, which the scale helpers reject, so the odd frame reached a 4:2:0 encoder. Round the fitted height down to even and report the width scale=-2 gives it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): bound HEVC stream output by the source's HEVC bitrate The quality policy caps a scaled encode at the source's bitrate counted as H.264, and the planner can choose HEVC afterwards without revisiting it, so a 3 Mbps HEVC source converted to 1080p HEVC could target 5 Mbps. Re-cap the bitrate at the source's bits counted as HEVC when HEVC output is chosen. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): check the HEVC target the planner encodes and keep H.264's on fallback The planner checked the HEVC decoder against the H.264-equivalent bitrate before capping it for HEVC, so a decoder limited to 4 Mbps refused a 3 Mbps HEVC encode and an HEVC-only delivery had no route. Cap first and check that candidate. A failed HEVC attempt now falls back to H.264 at the bitrate the policy chose for H.264 instead of the HEVC cap. Routes that keep the source size also report the even frame they encode (1918x1080 for a 1920x1081 source), so the HEVC decoder check sees the real output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): encode an unknown-bitrate source under a bandwidth cap With the shared ladder a 7 Mbps cap earns the 1080p class, so a 1080p source of unknown bitrate passed the cap check and was sent unchanged. The cap is a hard ceiling: treat an unknown video bitrate as over it, as the server bitrate cap already does, so the source is re-encoded within the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): reserve the server-cap audio share before checking HEVC The planner checked the HEVC decoder against the video bitrate before a server bitrate cap reserved its AAC and mux share, so an HEVC-only client whose decoder took the capped rate was refused over the uncapped one and had no route. Reserve the share first; it does not depend on the video codec. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): describe plain-label sizing and unknown bitrates The protocol doc still promised height-only behavior for plain resolution labels, which now fit the source into the class box like auto, and said a cap re-encodes only a source known to exceed it. State both rules as the planner applies them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): cap every HEVC encode at the source's HEVC-equivalent rate A route that keeps the source size but still re-encodes it (a codec the client cannot play, or a subtitle burn) skipped the HEVC cap, so an 8 Mbps H.264 source was checked as an 8 Mbps HEVC output and an HEVC-only client with a 6 Mbps decoder had no route. Cap every HEVC encode; the cap only lowers the bitrate when HEVC is the more efficient codec. Document that a source whose height fits the class is sent as-is even when it is wider than the 16:9 box. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep H.264 stream targets within the attested decoder bitrate HLS treats H.264 as the universal output and never checked its bitrate against the client's decoder. The shared ladder reaches 1080p at lower estimates, so a 7 Mbps estimate now targets 5.6 Mbps where the previous ladder chose 2 Mbps, past an H.264 decoder that attests a 4 Mbps limit. Lower an H.264 target to the limit of an attested decoder that takes the output size; HEVC output keeps its own decoder check. Qualify the ladder invariants for the streaming preservation exception and the H.264 bound. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): step H.264 stream targets down to an attested decoder's size A client whose attested H.264 decoders stop at 1280x720 received a 1080p H.264 target at a 7 Mbps estimate, where the previous ladder chose 720p. Size the H.264 candidate to the tallest class an attested H.264 decoder takes before bounding its bitrate; HEVC output keeps its own class, and the H.264 fallback after a failed HEVC attempt uses the H.264 size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): step H.264 targets down until the fitted size fits a decoder Snapping an attested H.264 decoder's limits to a ladder box let a 1280x962 decoder count as 1080p, so a 1920x1080 target passed although it is wider than the decoder. Step down class by class until the fitted size itself fits an attested decoder, stopping at the smallest class since H.264 stays the universal HLS output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): fit same-size H.264 conversions to an attested decoder A source whose size fits the estimate but whose codec the client cannot play is converted at its own size, and that conversion skipped the H.264 decoder fit, so an H.264-only client with a 720p decoder received a 1080p H.264 stream. Fit any H.264 encode the attested decoders cannot take, scaled or not. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): note that H.264 conversions are fitted to the decoder too Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): match H.264 decoders by frame rate as well as size The decoder fit compared only width and height, so a 60 fps source was sent at 1080p to a client whose 1080p H.264 decoder stops at 30 fps and whose 60 fps decoder stops at 720p. The encode keeps the source frame rate, so a decoder must take it too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): fit streamed H.264 to the frame the encoder writes The H.264 decoder fit compared box-fit sizes that scale=-2 later evens, so an odd-width source could pass a decoder limit it then exceeded by a pixel. Check the encoded frame, sharing encodedFrame with downloads and the source-size routes. The ladder doc now states the smallest-class floor for streaming and the unavailable answer for downloads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): size streamed H.264 by the decoder's bitrate and frame rate The streaming H.264 decoder fit chose the output size before looking at a decoder's bitrate limit, so a 1080p decoder limited to 3 Mbps got a 1080p stream at 3 Mbps where the shared ladder maps that budget to 720p. A decoder now takes a class only when its limit earns that class, the rule download targets already follow. It also used the hardware H.264 decoders whenever any were attested, even when none took the source's frame rate, so an opted-in 60 fps software decoder was ignored and a 60 fps source fell to 480p. Hardware decoders now win only when one takes the frame rate; otherwise the software ones that do are used. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): note the streamed H.264 bitrate and frame-rate rules Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…hardware encoders (#1659) * fix(playback): treat bitrate caps as ceilings on hardware encoders QSV and NVENC set -b:v equal to -maxrate, which QSV runs as CBR: a 4 Mbps source transcoded with a 10 Mbps cap grew to 10 Mbps. VAAPI passed -qp, which selects CQP and ignores -maxrate, so its cap was never enforced. A capped hardware encode now averages at 90% of the cap with the cap as -maxrate, and VAAPI switches to VBR when a cap is set. Uncapped encodes keep their constant-quality modes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): let VAAPI choose its capped rate-control mode Forcing -rc_mode VBR fails encoder initialization on a VAAPI driver that does not advertise VBR. Without -qp, FFmpeg's automatic selection picks VBR when the driver has it and CBR otherwise; both honor the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): force VBR on capped VAAPI encodes and probe for it FFmpeg's automatic VAAPI rate control tries AVBR before VBR, and AVBR does not honor -maxrate, so leaving the mode to FFmpeg could break the cap on drivers that offer AVBR. Capped VAAPI encodes force VBR again, and the VAAPI hardware probe now smoke-encodes in that mode, so automatic backend selection never picks a device without VBR. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): detect VAAPI VBR per device instead of requiring it Forcing VBR broke an explicitly configured VAAPI backend whose driver lacks it, and requiring VBR in the availability probe would have kept automatic selection from choosing a device that can still encode uncapped. Each start now checks, per device and cached, whether VAAPI offers VBR for the target encoder: capped encodes force VBR where it does (FFmpeg's automatic mode would try AVBR first, which ignores -maxrate) and otherwise leave the mode to FFmpeg, which falls back to CBR. The availability probe is unchanged from main. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): fall back to CBR on VAAPI devices without VBR The capped VAAPI encode forced VBR only on a device that passed the VBR probe and otherwise left the mode to FFmpeg, whose automatic choice can be AVBR, which ignores -maxrate. Probe VBR, then CBR, and force the first one the device accepts. A start whose context ends during the probe now returns that error instead of launching FFmpeg. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): encode in software when VAAPI verifies no capped mode A capped VAAPI encode on a device that accepted neither VBR nor CBR left the rate-control mode to FFmpeg, which can pick AVBR and ignore -maxrate. Move that encode to software instead, as a device without HEVC encoding already does, keeping a frozen GPU tone-map graph and downloading its frames to the software encoder. The field that carries that split is renamed from softwareHEVCEncode to softwareEncode now that it covers both codecs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): verify libx265 before a VAAPI HEVC software fallback A capped HEVC encode on a VAAPI device with no capped rate control moved to libx265 without checking the FFmpeg build has it, because a working hevc_vaapi had skipped the software probe. Run the same cached libx265 smoke the HEVC encoder choice uses and fail the start when it is missing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * test(handlers): answer VAAPI rate-control smoke encodes in the fake FFmpeg The shared fake FFmpeg slept on every command it did not recognize, so a capped VAAPI start waited out both rate-control probes and then, with the software fallback, reported a software encoder. Answer those one-frame smoke encodes at once, as a VBR-capable driver would. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): verify libx264 before a VAAPI H.264 software fallback The fallback for a VAAPI device with no capped rate control checked libx265 for HEVC targets but assumed libx264 for H.264, so a build with h264_vaapi and no libx264 failed at launch. Probe whichever software encoder the fallback needs, with the same cached one-frame smoke. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(downloads): pair download presets with a resolution ladder (#1670) * feat(downloads): pair download presets with a resolution ladder A download preset set only a bitrate. The output resolution came from the client's coarse max_resolution, so a 4K source downloaded at 1 Mbps by a client without caps was encoded at 2160p, and Apple's deliberate "1080p" ceiling capped every converted download at 1080p. Each preset now earns a resolution from one shared ladder (2160p at 20 Mbps, 1080p at 10 and 5, 720p at 2, 480p at 1 Mbps at <=30 fps; higher frame rates drop a class, HEVC stretches the budget). The encode never enlarges the source, box-fits cinema aspects, never exceeds the source's own bitrate, and steps down until the device's attested decoder takes it. HEVC is used when the server allows HEVC encoding and the caps attest an 8-bit HEVC decoder. When a preset would leave an SDR source unchanged and the device plays it, the source is served and the row still records the requested preset. Download encodes use a slower preset, let libx264 choose the level, and tag HEVC hvc1 so Apple players open it. The downloads capability adds quality_options with each preset's bitrate and maximum height for labels. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): honor decoder frame rate, profile and bitrate limits The download size choice read only a decoder's width and height. A decoder that cannot take the source's frame rate, or at the exact tier does not list the High profile the H.264 encode produces, is now skipped; a level-bound HEVC decoder keeps the encode on H.264, as HLS does; and the target bitrate stays within the chosen decoder's maximum. The ladder's comment and architecture note no longer claim that streaming and jellycompat read the table; they do not until they move onto it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): bound downloads by H.264 level and decoder bitrate At the exact tier an H.264 decoder's level list now bounds the output: each size is checked against the level libx264 would pick for it (including its doubled rate buffer), and the level also caps the bitrate. A decoder bitrate limit now lowers the budget the ladder class is chosen from, so a 3 Mbps decoder no longer gets a 1080p class. When frame-rate or profile checks leave no H.264 decoder, the largest decoder's size still bounds the output instead of leaving it unbounded. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): choose the decoder by achievable output and honor attested lists Pick the strict-tier decoder whose limits reach the tallest ladder class instead of the one with the largest frame, so a 4K decoder capped at a low bitrate no longer drags a download below what a second decoder plays. Check profile and level lists on platform-attested software decoders, as playback does; only platform-attested hardware decoders are exempt. When strict caps attest no decoder for any codec the server may encode, answer quality_unavailable rather than producing H.264 the device never listed. Label quality_options with the transcode ceiling a policy override sets, matching what Resolve produces. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): stop presets at 1080p without 4K and check levels at the encode bitrate With 4K transcoding off, quality_options advertised presets up to 1080p, but a 20 Mbps request could still serve a 4K original or keep a 1440p source at its size. Cap the preset class at 1080p in that case, which also matches the documented quality_unavailable answer for 4K titles. Check a decoder's H.264 level at the bitrate the encoder will get, which never exceeds the source's own, so a 3 Mbps 1080p source is not scaled down for a level-4.0 decoder. A decoder smaller than the 480p class no longer receives 480p output; with no decoder that takes a class, the preset is unavailable. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep a source known only by its height within the class FitLadderBox returned zeros whenever the width was unknown, so a caller fell back to the class box and could enlarge a short source. Keep such a source's own height when it fits the class and the class height when it is taller, leaving the width unknown. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): give an odd source frame an even size when encoding it A download encode that keeps the source frame passed no scale, so an odd height or width reached a 4:2:0 encoder unchanged and could fail. Scale such a frame to the even height at or below it; scale=-2 evens the width. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): scale to any even height a box fit produces The scale parser rejected heights below 144, so a very wide source fitted into a small class (1280x100 into the 480p box is 844x66) was left unscaled while its recipe claimed the fitted size. Accept every even height up to 4320. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): cap preset targets at the account's quality ceiling quality_options already capped each preset at the account's max playback quality, but Resolve applied only a policy override's ceiling, so with 4K transcoding on a 1080p account could prepare a 2160p artifact that the serve-time access check then refused. Apply the narrower of the two. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(downloads): check decoder bounds against the frame the encoder writes A source that fits a class keeps its size, but an odd frame is evened by scale=-2, so a 1917x1080 source was checked against a 1917-wide decoder and then encoded 1918 wide. Check each class at the frame the encoder actually produces. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * feat(playback): use the shared ladder for automatic streaming quality (#1671) * feat(playback): use the shared ladder for automatic streaming quality Automatic streaming quality, the plain resolution preferences, bandwidth caps and jellycompat each had their own bitrate-to-resolution table, and they disagreed with each other and with download presets. All of them now read the shared ladder: 80% of the bandwidth budget earns a class for the source's frame rate, the source is fit into that class's box so a scope film at 1080p streams at 1920x800, and a 540p class sits between 720p and 480p. The encode never targets more than that 80% budget, and a source that fits the class but exceeds the estimate's budget is re-encoded at its own size instead of sent as-is. Explicit menu rungs keep their own table. An original-quality route that still needs a video transcode labelled a 3840x1600 source "1080p", which scaled it to 2592x1080 while the plan reported 3840x1600. It now keeps the exact source height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): bound auto transcodes by the source and jellycompat by video budget An automatic transcode that only scales a low-bitrate source down could target the class bitrate even when the source used fewer bits; it now stays within the source's own bitrate, counted as H.264. jellycompat chose its class from the client's whole bitrate ceiling while encoding at the video share after audio and mux overhead; the class now follows that video budget. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep source-size labels even and budget unknown source bitrates A route that keeps the source frame but still encodes labeled an odd source height such as 1081p, which the scale helpers reject, leaving an odd frame for a 4:2:0 encoder. Round the label down to the even height. Automatic quality sent a source of unknown bitrate as-is whenever its class fit the estimate, so a 7 Mbps estimate could stream a 1080p file of any bitrate. Count an unknown bitrate as the full bitrate of the class it would be sent at, so it goes as-is only when the budget covers that. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep cropped sources in the class they earned Automatic quality bounded the target by the source height before snapping to the ladder, so a 1920x800 film under a 1080p estimate snapped to 720p: over its budget it was scaled to about 1276x532 at 2 Mbps instead of being re-encoded at its own size, and with an unknown bitrate it was sized as a 2 Mbps stream. A target that keeps the source height now snaps into the class the source's frame belongs to by both dimensions, within the class the preference, device, bandwidth or cap allows. jellycompat no longer upscales a track known only by its height. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): re-encode an odd source frame at an even size An automatic transcode that keeps the source frame labeled an odd height such as 1079p, which the scale helpers reject, so the odd frame reached a 4:2:0 encoder. Round the fitted height down to even and report the width scale=-2 gives it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): bound HEVC stream output by the source's HEVC bitrate The quality policy caps a scaled encode at the source's bitrate counted as H.264, and the planner can choose HEVC afterwards without revisiting it, so a 3 Mbps HEVC source converted to 1080p HEVC could target 5 Mbps. Re-cap the bitrate at the source's bits counted as HEVC when HEVC output is chosen. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): check the HEVC target the planner encodes and keep H.264's on fallback The planner checked the HEVC decoder against the H.264-equivalent bitrate before capping it for HEVC, so a decoder limited to 4 Mbps refused a 3 Mbps HEVC encode and an HEVC-only delivery had no route. Cap first and check that candidate. A failed HEVC attempt now falls back to H.264 at the bitrate the policy chose for H.264 instead of the HEVC cap. Routes that keep the source size also report the even frame they encode (1918x1080 for a 1920x1081 source), so the HEVC decoder check sees the real output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): encode an unknown-bitrate source under a bandwidth cap With the shared ladder a 7 Mbps cap earns the 1080p class, so a 1080p source of unknown bitrate passed the cap check and was sent unchanged. The cap is a hard ceiling: treat an unknown video bitrate as over it, as the server bitrate cap already does, so the source is re-encoded within the cap. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): reserve the server-cap audio share before checking HEVC The planner checked the HEVC decoder against the video bitrate before a server bitrate cap reserved its AAC and mux share, so an HEVC-only client whose decoder took the capped rate was refused over the uncapped one and had no route. Reserve the share first; it does not depend on the video codec. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): describe plain-label sizing and unknown bitrates The protocol doc still promised height-only behavior for plain resolution labels, which now fit the source into the class box like auto, and said a cap re-encodes only a source known to exceed it. State both rules as the planner applies them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): cap every HEVC encode at the source's HEVC-equivalent rate A route that keeps the source size but still re-encodes it (a codec the client cannot play, or a subtitle burn) skipped the HEVC cap, so an 8 Mbps H.264 source was checked as an 8 Mbps HEVC output and an HEVC-only client with a 6 Mbps decoder had no route. Cap every HEVC encode; the cap only lowers the bitrate when HEVC is the more efficient codec. Document that a source whose height fits the class is sent as-is even when it is wider than the 16:9 box. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep H.264 stream targets within the attested decoder bitrate HLS treats H.264 as the universal output and never checked its bitrate against the client's decoder. The shared ladder reaches 1080p at lower estimates, so a 7 Mbps estimate now targets 5.6 Mbps where the previous ladder chose 2 Mbps, past an H.264 decoder that attests a 4 Mbps limit. Lower an H.264 target to the limit of an attested decoder that takes the output size; HEVC output keeps its own decoder check. Qualify the ladder invariants for the streaming preservation exception and the H.264 bound. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): step H.264 stream targets down to an attested decoder's size A client whose attested H.264 decoders stop at 1280x720 received a 1080p H.264 target at a 7 Mbps estimate, where the previous ladder chose 720p. Size the H.264 candidate to the tallest class an attested H.264 decoder takes before bounding its bitrate; HEVC output keeps its own class, and the H.264 fallback after a failed HEVC attempt uses the H.264 size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): step H.264 targets down until the fitted size fits a decoder Snapping an attested H.264 decoder's limits to a ladder box let a 1280x962 decoder count as 1080p, so a 1920x1080 target passed although it is wider than the decoder. Step down class by class until the fitted size itself fits an attested decoder, stopping at the smallest class since H.264 stays the universal HLS output. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): fit same-size H.264 conversions to an attested decoder A source whose size fits the estimate but whose codec the client cannot play is converted at its own size, and that conversion skipped the H.264 decoder fit, so an H.264-only client with a 720p decoder received a 1080p H.264 stream. Fit any H.264 encode the attested decoders cannot take, scaled or not. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): note that H.264 conversions are fitted to the decoder too Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): match H.264 decoders by frame rate as well as size The decoder fit compared only width and height, so a 60 fps source was sent at 1080p to a client whose 1080p H.264 decoder stops at 30 fps and whose 60 fps decoder stops at 720p. The encode keeps the source frame rate, so a decoder must take it too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): fit streamed H.264 to the frame the encoder writes The H.264 decoder fit compared box-fit sizes that scale=-2 later evens, so an odd-width source could pass a decoder limit it then exceeded by a pixel. Check the encoded frame, sharing encodedFrame with downloads and the source-size routes. The ladder doc now states the smallest-class floor for streaming and the unavailable answer for downloads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): size streamed H.264 by the decoder's bitrate and frame rate The streaming H.264 decoder fit chose the output size before looking at a decoder's bitrate limit, so a 1080p decoder limited to 3 Mbps got a 1080p stream at 3 Mbps where the shared ladder maps that budget to 720p. A decoder now takes a class only when its limit earns that class, the rule download targets already follow. It also used the hardware H.264 decoders whenever any were attested, even when none took the source's frame rate, so an opted-in 60 fps software decoder was ignored and a 60 fps source fell to 480p. Hardware decoders now win only when one takes the frame rate; otherwise the software ones that do are used. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): note the streamed H.264 bitrate and frame-rate rules Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): keep streamed H.264 sizes for fast, tall, and wide sources Three streaming-ladder cases produced a smaller or larger encode than main did: - A 50/60 fps source whose attested H.264 decoders all report a lower rate (Android reports the rate at the decoder's largest size) fell to the 480p floor. The sizes alone now bound the encode, as they do for downloads. - An original-quality transcode of a source taller than 2160 lines encoded at its own height (4320p, or unscaled above 4320). It is now fitted into the 2160p box. - A same-size conversion of a wide source (2560x1080) was classed 2160p by its width, so a decoder bitrate limit below 20 Mbps stepped it down to 1920x810. It keeps the 1080p class its height earned. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * docs(playback): describe the capped VAAPI rate-control fallback Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(playback): bound a streamed H.264 frame by the decoder's pixel rate The previous commit let decoder sizes alone bound a high-frame-rate encode when no attested decoder listed the source rate, so a 1080p30 decoder could be sent 1080p60. A reported rate holds at the decoder's largest size, so a frame now fits when its pixel rate does: a 4K30 decoder takes 1080p60, and a 1080p30 decoder takes 720p60. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Problem
Related issue: N/A
Validation tasks: reaches #1246 C1 (Jellyfin clients' bitrate limits); no recorded result yet.
Stacked on #1670, which adds the shared ladder.
Streaming picked a resolution for a bitrate budget with its own table, jellycompat had another, and download presets now use a third (#1670). They disagreed: an 8 Mbps connection streamed at 720p automatically, while a Jellyfin client limited to 8 Mbps got 1080p, and so does a 5 Mbps download. Below 5 Mbps, automatic streaming dropped straight to 480p. Streaming also scaled cinema-aspect sources by height alone, so a 3840x1600 film at the 1080p class streamed at 2592x1080.
A related bug: when an original-quality stream still needs a video transcode (for example HEVC to H.264), its target was labelled with the resolution bucket, not the source height. A 3840x1600 source was labelled "1080p" and scaled to 2592x1080 while the plan reported 3840x1600.
This change moves automatic streaming quality and jellycompat onto the shared ladder and fixes the original-quality label.
Approach
auto, plain resolution preferences, and bandwidth caps) takes 80% of the bandwidth estimate or cap, as before, and asks the ladder for a class at the source's frame rate. It then fits the source into the class box and encodes at the class bitrate: 20000 kbps for 2160p, 6000 for 1080p, 2000 for 720p, 1800 for 540p, 1500 for 480p, never above the 80% budget. Explicit menu rungs (1080p-mediumand the rest) are user choices and are unchanged.MaxStreamingBitrate(after the audio and mux reserve it already made) into the same class and fitted height. 20 Mbps and above still means no downscale, and a track known only by its height is never enlarged.Behavior changes a reviewer will notice, for automatic quality at 30 fps or less:
Cinema-aspect sources keep their shape.
Validation
internal/playback(includingcontractandplanstore),internal/jellycompat,internal/downloads,internal/transcodenode,internal/apiv2: pass.internal/api/handlersshows only the two known DB-fixture failures that also fail onmain.make verify-playback-fixturesreports the golden fixtures unchanged;make lint-changedclean.scale=-2:720before, which gives 1728x720), capped at 2000 kbps. The HLS encode kept its real-time preset.Risks
HLS starts on an older transcode node would leave a box-fit height such as
800punscaled. Nodes ship with the server image, so a deployment updates them together.Checklist
AI Disclosure
ResolveQualityPolicyV3, the scale-label consumers (sessions, recipe cards, the auto-transcode cache key), and the jellycompat profile checks. It found that a class could be admitted at its floor and then encoded at the higher class bitrate, leaving almost no headroom (a 6.3 Mbps estimate got 1080p at 6 Mbps). Automatic quality now never encodes above the 80% budget, with tests at the class boundaries.🤖 Generated with Claude Code
Note
Use shared bitrate ladder for automatic streaming quality selection
ResolveQualityPolicyV3with the sharedLadderClassForBitrateladder, using 80% of bandwidth/cap as the video budget (plan_v3.go, quality_ladder.go)auto, plain labels, and cap-driven choices now fit encodes to the source aspect ratio, evenize dimensions, and cap bitrate by budget, cap, and source-equivalent H.264 bitrate. Sources that fit the earned class can stay unscaled (plan_v3.go)compatTargetResolutionForBitrate, resolving width and height instead of a nominal height label (handlers_playback.go)h264BoundedQualityV3andattestedH264DecodersV3; failed HEVC transcodes fall back to the retained H.264 recipeladderHeightForBandwidthV3andqualityDimensionsV3in plan_v3.go may affect other callersMacroscope summarized 3d68d37.