You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(jellycompat): size encodes by the source instead of the client ceiling - #3342
Related issue: N/A
Validation tasks: changes #1246 C1 (Jellyfin Web's HEVC-over-HLS encode now targets the source's rate instead of the client's ceiling; the playback criterion is unchanged, but the case needs a re-test on a build with this change)
A Jellyfin client's MaxStreamingBitrate becomes the encoder's target, however small the source is. Jellyfin Web's 120 Mbps limit gives a 113.8 Mbps target for every file, so a 2.9 Mbps source encodes at about 10 Mbps and a 6 Mbps source at about 29 Mbps. That wastes bandwidth and storage for no gain in quality. The reported stream bitrate is wrong too, so a session looks like it needs far more throughput than it does.
This change stops an encode at the source's rate, converted for the output codec.
Approach
buildPlaybackSource now fits the target to the lower of the client's ceiling and the source's video rate. That rate is the video track's own when the probe found one, as in the native planner (playback.SourceVideoKbps), so audio doesn't count. A track rate above the file's, or under a quarter of it, falls back to the file's rate: a target that is too high costs only bandwidth, while a bogus low one would ruin the picture. The rate then goes through playback.EncodeEquivalentKbps, which replaces H264EquivalentKbps and takes the output codec, so an HEVC source still gets H.264 headroom.
The ceiling alone still picks the frame size, so a low-bitrate source is not scaled down, and only a ceiling the source really exceeds reports VideoBitrateNotSupported. An unknown source rate targets the ceiling as before. This is a deliberate difference from Jellyfin, recorded in docs/jellycompat-api.md.
This only changes the Jellyfin-compatible surface, so silo-apple and silo-android need no follow-up.
Validation
Focused tests: internal/jellycompat passes except TestAttachmentServesActualFontAndRejectsWrongRoute, which also fails on main in my environment. internal/playback passes in full against the FFmpeg shipped in the Silo image.
make lint-changed reports 0 issues. go vet on both packages and make verify-local-paths are clean.
End to end, at 69e70d7: built that commit and main as images and ran each with a fresh database and a synthetic library. A scripted client called PlaybackInfo, read the FFmpeg arguments from the server log, and checked the first four segments with ffprobe. The later commits change only how the source rate is chosen and were checked through the PlaybackInfo handler, not end to end.
Not run: make test-go and the rest of the full gate locally, and hardware encoders. The end-to-end runs used libx264. No real client app was used.
Evidence
Same request on the same synthetic file: a TS-only H.264 profile with direct play off. Sizes are the first four segments, about 8 s.
Surface and build: jellycompat PlaybackInfo and HLS output, images built from main84cab92 and 69e70d7.
PlaybackInfo through the handler, same TS-only request on both builds, trimmed. The client-visible fields don't change, including TranscodeReasons; only the target the server stored for the encode does (server_target_kbps, not a response field).
A source whose stored bitrate is too low now gets a lower target than before. A client that wants a higher rate than the source can't force one.
A frame scaled down for a client's height or width limit still stops only at the full-frame source rate: a 4K 60 Mbps HEVC file for a 1080p-limited client at a 120 Mbps ceiling targets 100 Mbps, down from 113.8 Mbps. Applying the native planner's per-resolution ceiling here would also cut ordinary downscales below what main targets (4K H.264 at a 15 Mbps ceiling drops from 14 to 10 Mbps), so that belongs in its own change.
-b:v is 90% of the target, so a hardware H.264 encode of an H.264 source averages a little under the source's rate. Picture quality on hardware encoders hasn't been checked.
Checklist
Complete diff read by the author: pending, to be confirmed before review.
This pull request addresses one concern.
The added tests meet "Decide what to test": public jellycompat encode targets with real edge cases.
The Evidence section shows the server's output before and after.
AI Disclosure
Harness: Claude Code
Tool(s): Claude Code
Model(s): claude-opus-5-5
Involvement: AI-assisted. Claude Code wrote the code, tests and this description at the maintainer's direction.
Adversarial review: two read-only rounds by separate Claude Code agents (claude-opus-5-5) over the branch diff and its route, session-reload and fallback paths. They found implausible track rates and a track-less source codec (fixed here), inaccurate docs wording (fixed), and the frame-limited gap under Risks. A per-resolution ceiling added in response was reverted after the second round showed it lowered ordinary downscales.
Note
Fix jellycompat encode sizing to cap bitrate by source, not client ceiling
Encode targets are now capped at the source's codec-equivalent bitrate via new compatSourceEncodeKbps helper in handlers_playback.go, while output resolution still comes from the client/profile ceiling.
HEVC-to-H.264 fallback now carries the H.264 bitrate ceiling into the negotiated source, stored alongside the selected ceiling on PlaybackMediaSource (in-memory only).
compatEncodeTarget raises the target to a new shared 64 kbps minimum (compatMinEncodeKbps) when the source cap falls below it but the budget allows it; encodes below the minimum are not advertised.
compatTranscodeReasons now compares the source file bitrate against the stored encode ceiling, so a source-limited target no longer triggers VideoBitrateNotSupported on its own.
EncodeEquivalentKbps in prepare_file.go accepts a target codec instead of being H.264-only, and SourceVideoKbps in capabilities_v3.go centralizes track-then-file bitrate selection.
Behavioral Change: renegotiated playback info responses may advertise lower bitrates (source-limited) than before, and EncodeEquivalentKbps callers must pass a codec argument.
…iling
A client's MaxStreamingBitrate became the encoder's target and the reported
stream bitrate, so Jellyfin Web's 120 Mbps limit produced a 113.8 Mbps target
for a 27 Mbps file. Encodes now stop at the source's rate for the output codec.
The ceiling still picks the frame size and decides VideoBitrateNotSupported.
Files skipped from review as they are similar to previous changes: 1
docs/jellycompat-api.md
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Walkthrough
Encode bitrate targets now account for source rate and target codec. Playback handling tracks encode ceilings separately from selected targets, applies a 64 Kbps minimum, and uses the ceiling for bitrate-based transcode reasons.
Changes: Jellyfin-compatible encode bitrate
Layer / File(s)
Summary
Source bitrate and codec equivalence internal/playback/capabilities_v3.go, internal/playback/prepare_file.go, internal/jellycompat/deviceprofile.go, internal/playback/quality_ladder_test.go
Playback helpers select and normalize the source video rate and calculate its equivalent rate for a target codec. Uncapped H.264 encode facts use the source-aware rate.
Playback target and ceiling handling internal/jellycompat/handlers_playback.go, internal/jellycompat/playback_sessions.go
Target selection caps bitrate at the source-equivalent rate and tracks the available ceiling separately. The ceiling is carried through H.264 fallback and transcode-reason checks. Encode and subtitle-burning eligibility use a 64 Kbps minimum.
Behavior checks and documentation internal/jellycompat/playback_output_conditions_test.go, internal/jellycompat/roku_profile_test.go, docs/jellycompat-api.md
Tests cover source-rate caps, resolution, transcode reasons, and the Roku HEVC profile case. The API documentation describes the source-rate cap and its relationship to frame size.
Silo-Server/silo-server#2987: It changes the same playback negotiation path, including codec-specific limits and H.264 fallback behavior.
Silo-Server/silo-server#921: Its session telemetry records effective targets affected by this PR’s target-selection changes.
Silo-Server/silo-server#3341: It changes playback negotiation routes in the same handler where this PR changes encode ceilings and source-rate targets.
Suggested labels:impact: playback
Suggested reviewers:brady3035, tomislav
Merge Risk: Low · up to 847df
Audio-heavy files can receive higher encode targets than their video rate suggests, though client limits still apply. This is a bounded risk to note when merging.
Security architecture risk: Low · up to 847df
Playback bitrate selection changes within existing access checks and encoding limits. The reviewed paths show no new authority or data exposure. Recovery and deployment validation remains limited.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — The changed target propagates to local and remote encoders for negotiated playback. The inspected dependency path changes the selected numeric bitrate, not the credentials, destination selection, or executor authority supplied by that path.
Trust Boundaries and Controls
observed — Client bitrate preferences remain constrained by existing request, server, and profile limits. Source-rate fitting narrows the encode target within that budget rather than granting the client a new resource-control channel.
Resilience and Maintainability Implications
observed — Finalized targets are stored after fallback. Existing in-memory locking and durable transactional replacement continue to serialize repeated negotiations and preserve started sessions; the new ceilings do not become shared mutable runtime authority.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly summarizes the main change: Jellycompat encode targets are sized by the source rate instead of only the client ceiling.
Description check
The description directly explains the source-rate cap, codec conversion, resolution behavior, tests, evidence, and known risks described by the changeset.
Docstring Coverage
Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 8 files. (1 skipped: 1 unsupported.)
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
PlaybackInfo reports a source-capped target bitrate (internal/jellycompat/handlers_playback.go), but the table shows only FFmpeg maxrate and HLS segment sizes; add before-and-after PlaybackInfo response excerpts for the same request showing the changed target bitrate. TranscodingUrl's TranscodeReasons can also change (internal/jellycompat/handlers_playback.go), but no excerpt shows it; include its before-and-after value, including whether VideoBitrateNotSupported is reported.
Suggested fix: No diff — add trimmed response excerpts for both fields. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.
The recorded #1246 C1 run exercises Jellyfin Web's HEVC-over-HLS transcode on 31fabc723 with #2934/#2935/#2970. This PR changes that path's encode target to the source-equivalent rate and changes bitrate-reason reporting, so the prior result no longer covers the same stream behavior. The PR must explain why the validated behavior changes; #1246 C1 needs re-validation after merge, especially the HEVC transcode case.
Suggested fix: No diff — re-run #1246 C1 against the merged build and record the result.
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.
The changed TestEncodeEquivalentKbps always uses transcodeCodecH264. The Jellycompat tests select HEVC output in some cases, but they either use a VP9 source or assert only codec selection, resolution, or fallback behavior. No test asserts the target bitrate for an H.264 source converted to HEVC under a generous ceiling. An incorrect H.264-to-HEVC conversion could therefore pass the current tests.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 14fcab52-3537-417b-8be7-1b0721dd6995
Commits
Reviewing files that changed from the base of the PR and between 84cab92 and 69e70d7.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
…e rate
The file rate includes audio, so a 2.9 Mbps video track with lossless audio
was still encoded near 7 Mbps. The native planner already reads the video
track first; both surfaces now share SourceVideoKbps.
A track rate above the file's, or under a quarter of it, falls back to the
file's rate. A target that is too high only costs bandwidth, while a bogus low
one would ruin the picture. The source codec now also reads the track first,
as the native planner does.
The user-visible HLS output for a file whose video-track rate is below its file rate (for example, 7 Mbps file / 2.9 Mbps video) lacks matching end-to-end evidence: the segment results are from 69e70d7, while the current-head excerpt shows only server_target_kbps, which is not a response field. Please include before-and-after FFmpeg targets and HLS segment sizes for that same request, with the after capture from 847df19.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.
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
bugSomething isn't workinggoPull requests that update go codeimpact: playbackCan't play, stalls, or wrong mediapriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.
2 participants
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.
Problem
Related issue: N/A
Validation tasks: changes #1246 C1 (Jellyfin Web's HEVC-over-HLS encode now targets the source's rate instead of the client's ceiling; the playback criterion is unchanged, but the case needs a re-test on a build with this change)
A Jellyfin client's
MaxStreamingBitratebecomes the encoder's target, however small the source is. Jellyfin Web's 120 Mbps limit gives a 113.8 Mbps target for every file, so a 2.9 Mbps source encodes at about 10 Mbps and a 6 Mbps source at about 29 Mbps. That wastes bandwidth and storage for no gain in quality. The reported stream bitrate is wrong too, so a session looks like it needs far more throughput than it does.This change stops an encode at the source's rate, converted for the output codec.
Approach
buildPlaybackSourcenow fits the target to the lower of the client's ceiling and the source's video rate. That rate is the video track's own when the probe found one, as in the native planner (playback.SourceVideoKbps), so audio doesn't count. A track rate above the file's, or under a quarter of it, falls back to the file's rate: a target that is too high costs only bandwidth, while a bogus low one would ruin the picture. The rate then goes throughplayback.EncodeEquivalentKbps, which replacesH264EquivalentKbpsand takes the output codec, so an HEVC source still gets H.264 headroom.The ceiling alone still picks the frame size, so a low-bitrate source is not scaled down, and only a ceiling the source really exceeds reports
VideoBitrateNotSupported. An unknown source rate targets the ceiling as before. This is a deliberate difference from Jellyfin, recorded indocs/jellycompat-api.md.This only changes the Jellyfin-compatible surface, so
silo-appleandsilo-androidneed no follow-up.Validation
internal/jellycompatpasses exceptTestAttachmentServesActualFontAndRejectsWrongRoute, which also fails onmainin my environment.internal/playbackpasses in full against the FFmpeg shipped in the Silo image.make lint-changedreports 0 issues.go veton both packages andmake verify-local-pathsare clean.mainas images and ran each with a fresh database and a synthetic library. A scripted client calledPlaybackInfo, read the FFmpeg arguments from the server log, and checked the first four segments withffprobe. The later commits change only how the source rate is chosen and were checked through thePlaybackInfohandler, not end to end.make test-goand the rest of the full gate locally, and hardware encoders. The end-to-end runs usedlibx264. No real client app was used.Evidence
Same request on the same synthetic file: a TS-only H.264 profile with direct play off. Sizes are the first four segments, about 8 s.
main84cab92)-maxrate 113808k, 10.0 MB-maxrate 2898k, 3.7 MB-maxrate 113808k, 43.4 MB-maxrate 23057k, 27.1 MB-maxrate 113808k, 35.4 MB-maxrate 8490k, 9.8 MB-maxrate 113808k, 29.4 MB-maxrate 5917k, 7.2 MB-maxrate 8187k, 10.0 MB-maxrate 8187k, 9.9 MB (ceiling still wins)Surface and build: jellycompat
PlaybackInfoand HLS output, images built frommain84cab92 and 69e70d7.PlaybackInfothrough the handler, same TS-only request on both builds, trimmed. The client-visible fields don't change, includingTranscodeReasons; only the target the server stored for the encode does (server_target_kbps, not a response field).Before (84cab92):
{"case":"MPEG-2 2.9 Mbps, 120 Mbps ceiling","Bitrate":2900000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":113808} {"case":"MPEG-2 7 Mbps file, 2.9 Mbps video, 120 Mbps ceiling","Bitrate":7000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":113808} {"case":"HEVC 5 Mbps, 120 Mbps ceiling","Bitrate":5000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":113808} {"case":"H.264 6 Mbps, 120 Mbps ceiling, copy off","Bitrate":6000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":113808} {"case":"MPEG-2 23 Mbps, 8.82 Mbps ceiling","Bitrate":23000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoBitrateNotSupported","server_target_kbps":8187}After (847df19):
{"case":"MPEG-2 2.9 Mbps, 120 Mbps ceiling","Bitrate":2900000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":2900} {"case":"MPEG-2 7 Mbps file, 2.9 Mbps video, 120 Mbps ceiling","Bitrate":7000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":2900} {"case":"HEVC 5 Mbps, 120 Mbps ceiling","Bitrate":5000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":8333} {"case":"H.264 6 Mbps, 120 Mbps ceiling, copy off","Bitrate":6000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoCodecNotSupported","server_target_kbps":6000} {"case":"MPEG-2 23 Mbps, 8.82 Mbps ceiling","Bitrate":23000000,"TranscodingContainer":"ts","TranscodeReasons":"VideoBitrateNotSupported","server_target_kbps":8187}Risks
maintargets (4K H.264 at a 15 Mbps ceiling drops from 14 to 10 Mbps), so that belongs in its own change.-b:vis 90% of the target, so a hardware H.264 encode of an H.264 source averages a little under the source's rate. Picture quality on hardware encoders hasn't been checked.Checklist
AI Disclosure
Note
Fix jellycompat encode sizing to cap bitrate by source, not client ceiling
compatSourceEncodeKbpshelper in handlers_playback.go, while output resolution still comes from the client/profile ceiling.PlaybackMediaSource(in-memory only).compatEncodeTargetraises the target to a new shared 64 kbps minimum (compatMinEncodeKbps) when the source cap falls below it but the budget allows it; encodes below the minimum are not advertised.compatTranscodeReasonsnow compares the source file bitrate against the stored encode ceiling, so a source-limited target no longer triggersVideoBitrateNotSupportedon its own.EncodeEquivalentKbpsin prepare_file.go accepts a target codec instead of being H.264-only, andSourceVideoKbpsin capabilities_v3.go centralizes track-then-file bitrate selection.EncodeEquivalentKbpscallers must pass a codec argument.Macroscope summarized 847df19.