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(playback): play Jellyfin streams and rebuilt transcodes when the GPU can't decode the source - #4097
Closes#4030
Related issue: N/A
Validation tasks: unblocks #1172 C2
Other clients: N/A (no client-visible change)
With Hardware acceleration set to an explicit backend such as NVENC, a GPU whose decoder can't take the source (HEVC on a GTX 970) makes FFmpeg exit at startup with Hardware is lacking required capabilities. #4057 made the starts that wait for a first manifest retry with CPU decoding. Four paths start FFmpeg without waiting, so they never saw the rejection and handed back a process that had already exited:
a Jellyfin-compatible start on the API server;
a Jellyfin-compatible start on a transcode node;
a rebuild of a lost transcode on the API server;
a rebuild of a lost transcode on a transcode node.
On such a server, Jellyfin clients could not start an HEVC transcode at all. A rebuild fails the same way when its recipe was written where the GPU does decode the source: after the operator switches Hardware acceleration from Auto or None to NVENC, or when a Jellyfin transcode moves off a dead node, which rebuilds on the new executor instead of starting fresh.
This change makes all four paths decode on the CPU when the decoder rejects the source, using the retry #4057 added.
Approach
A start under an explicit hardware backend that decodes on the GPU, without tone mapping, is now waited on until its first manifest or its exit. If FFmpeg exits with the decoder rejection, the path walks the same order as #4057: CPU decode with the hardware encoder, then software. One exported predicate, playback.HardwareDecodeRetryEligible, decides which starts are waited on, and NewSoftwareDecodeRetryPipeline now uses it for its own gate.
Only a decoder rejection changes what three of the paths do. A ready process, a slow one, and one that exits for any other reason are returned as they were, so the existing exit monitor and segment recovery still handle them.
The Jellyfin node start is the exception. The API server now sends RequireReady for an eligible start, which reuses the node behavior #4057 shipped and needs no node change. RequireReady also closes a process that has no manifest after 30 seconds. hw_accel=auto on this path and every native start already work that way.
On a transcode node, a rebuild whose backend already has its own software retry (VideoToolbox, or QSV/VAAPI without a render device) keeps that path unchanged, so no start is waited on twice. A rebuild's retry is launched on a context detached from the request that triggered it, because other requests wait on the same rebuild.
worker-http-protocol.md and restart-resilient-playback.md describe the new start and rebuild rules.
Validation
Focused tests, one per path, through entry points that exist before and after the change. Each fails on main for the reported reason (one GPU-decode attempt, then a dead or unwaited start) and passes here. The Jellyfin and node tests run a fake FFmpeg that prints the NVDEC line for any -hwaccel cuda command.
go build ./..., gofmt -l, go mod tidy -diff, go vet, make lint-changed, make lint-router-recovery, make verify-local-paths: clean.
make test-go: no test fails here that passes on main. On the machine I ran it on, main itself fails TestCopyRemuxSubtitleRenditionRealFFmpeg (stock FFmpeg 6.1.1) and tests in internal/ebookconvert, internal/mediasample, internal/uploads, internal/backup and internal/api/handlers; the same tests fail with this change. CI is the check for those.
Web gate and generated-contract checks: not run. The change touches no web code, API contract, or setting.
Not reproduced on real hardware. I had no NVIDIA card whose decoder rejects a source, so none of the four paths was run against one. The reporter confirmed fix(playback): decode on the CPU when the GPU decoder rejects the source #4057's retry on a GTX 970 for native playback and downloads; this change routes four more paths into that retry.
No capture: nothing visible changes, and no hardware here reproduces the rejection. The page holds the failing run on main and the passing run on this branch for the four tests.
A Jellyfin-compatible start on the API server under an explicit backend now answers the manifest request after FFmpeg's first manifest, at most 30 seconds later. Before, a bounded-length encode answered at once and the first segment request did the waiting. Time to first frame moves later by about the encode time of one or two segments.
A Jellyfin-compatible node start under an explicit backend that has no manifest after 30 seconds is now closed. The API server then tries another node or local execution, and answers 502 only when none is left. Such a start used to keep running.
A rebuild under an explicit backend now holds the session's lifecycle lock and a rebuild pacing slot until its first manifest (three segments), at most 30 seconds, and up to about 90 seconds when the decoder rejects the source. On a node it also holds the config reload read lock, so a reload, a stop, or a new start for that session waits behind it. hw_accel=auto already holds the same locks for the same wait.
Every start and rebuild on an affected card still makes one failed GPU-decode attempt first. A rebuild can't record the result: a native recipe travels in the client's stream token.
The wait also applies to a few starts that end up encoding in software after a probe, such as an unconstrained VideoToolbox request. They gain nothing from it.
A request whose Hardware acceleration value is empty skips the Jellyfin node change, and the node applies its own setting. The config default, the YAML import, and the admin setting never leave the value empty.
Follow-ups: the review turned up two defects that already exist on main, filed separately. #4098: a rebuild under hw_accel=auto launches its fallback attempts on the triggering request's context. #4099: a node rebuild with a software retry can accept a manifest left by an earlier process. The user manual needs no change; its playback and node pages don't describe how an explicit backend falls back.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: Claude Code (T3 Code)
Tool(s): Claude Code; OpenAI Codex (plan review)
Model(s): claude-fable-5-2 (implementation and review); gpt-6.1-sol and claude-opus-5-5 (plan review); claude-sonnet-5-5 (cleanup and validation checks)
Involvement: Fully AI-generated. The maintainer directed the work and reviews it on this pull request.
Adversarial review: Before any code, gpt-6.1-sol attacked the plan and claude-opus-5-5 cut it down. Sol found that a slow VideoToolbox rebuild on a node would be waited on twice, and that the rebuild's retry would launch on a request context that may have ended; both are fixed here. Opus kept all four paths and trimmed the tests and docs. A simplify pass and a multi-agent code review at high (three finders, a validation check, four verifiers) followed. The review found no correctness defect in the change. It led to one fix (MPEG-4 Part 2 sources are no longer waited on) and to the Risks above. A background adversarial review by gpt-6.1-sol of 1f2f62e, run after this pull request opened, found nothing and posted no review.
…GPU can't decode the source
With Hardware acceleration set to an explicit backend, a GPU whose decoder
rejects the source (HEVC on a GTX 970) made FFmpeg exit at startup. #4057
retried on the CPU for starts that wait for a first manifest. Four paths
started FFmpeg without waiting and handed back the exited process:
Jellyfin-compatible local and node starts, and local and node reconstructs.
These paths now wait for the first manifest when the start decodes on the GPU,
and walk the same CPU-decode retry on a decoder rejection. Any other outcome is
returned as before, except that a Jellyfin node start is now sent with
RequireReady.
Related issue: #4030
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Eligible reconstruction starts now retry GPU decoder capability rejections with CPU video decoding while retaining hardware encoding. Compatible transcode requests wait for readiness when that retry applies. Tests and architecture documentation describe the retry behavior.
Reconstruction retries eligible GPU decoder rejections with CPU video decoding. The retry preserves the output directory and uses a non-canceled context. The retry eligibility predicate excludes MPEG-4 Part 2, tone-map recipes, video-copy targets, software decoding, and non-hardware backends.
Applicable reconstruction starts use the retry-aware startup path unless a separate software-encode retry applies. Tests verify explicit NVENC reconstruction retries without CUDA decoding.
Compatible transcode readiness and retry internal/jellycompat/handlers_playback.go, internal/jellycompat/streams.go, internal/jellycompat/auto_transcode_fallback_test.go, docs/architecture/worker-http-protocol.md
Eligible explicit-hardware requests require readiness. Compatible startup retries eligible decoder rejections while preserving the existing automatic-pipeline fallback behavior. Tests cover readiness and retry behavior.
sequenceDiagram
participant Node as Transcode node
participant Startup as Reconstruction startup
participant FFmpeg as FFmpeg process
Node->>Startup: Start eligible hardware reconstruction
Startup->>FFmpeg: Decode on GPU and encode on GPU
FFmpeg-->>Startup: Hardware decoder capability rejection
Startup->>FFmpeg: Retry with CPU decode and GPU encode
FFmpeg-->>Startup: Produce first manifest
Startup-->>Node: Return ready reconstruction session
Loading
Suggested reviewers:blurbery, rhainland, rangodj
Merge Risk: Moderate · up to 1f2f6
After a restart or lost-transcode rebuild, a stream that needed the GPU-decoder CPU-decode retry under explicit NVENC can be rebuilt with CPU encoding instead of NVENC. Playback still works but uses much more CPU and may stutter on weaker hosts. Preserve the NVENC permission across reconstruction before relying on this path.
Security architecture risk: Minimal · up to 1f2f6
The change adds bounded decoder fallback to existing playback flows. The inspected authorization, process-cleanup, and session-ownership controls remain in place, with no material security or failure-containment regression established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The added work consumes CPU and potentially GPU capacity on the selected API server or worker. The retry retains the admitted session’s media input and output directory rather than granting access to another session or introducing a new executor authority.
Trust Boundaries and Controls
observed — The worker start and media routes remain behind node-signature verification. Fresh starts require approved input paths; reconstruction verifies a presented token and transport binding or obtains a complete transport-bound recipe from the control-plane store, then rechecks input authority and stop fences before spawning.
Resilience and Maintainability Implications
observed — Reconstruction deliberately detaches readiness waiting from the triggering request, extending lock and pacing-slot occupancy. Countervailing controls include 30-second per-attempt manifest waits, finite retry stages, reconstruction pacing, shutdown-aware manager publication, and worker stop serialization against in-flight reconstruction.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: Jellyfin-compatible streams and rebuilt transcodes now play when the GPU cannot decode the source. The raw summary and objectives confirm the four affected paths (Jell…
Linked Issues check
[#4030] The requirement is a CPU-decode retry for explicit hardware backends (for example NVENC) when FFmpeg reports "Hardware is lacking required capabilities". The diff implements this for the four …
Out of Scope Changes check
The changed hunks in internal/playback/transcode_startup.go, internal/jellycompat/streams.go, handlers_playback.go, and transcodenode/server.go connect to the four paths named in #4030 and the PR obje…
Description check
The description is specific and on-topic. It names the problem (an explicit NVENC backend whose GPU decoder rejects HEVC input, causing FFmpeg to exit with 'Hardware is lacking required capabilities')…
Full details: Title check
Explanation
The title names the main change: Jellyfin-compatible streams and rebuilt transcodes now play when the GPU cannot decode the source. The raw summary and objectives confirm the four affected paths (Jellyfin-compatible starts and lost-transcode rebuilds on the API server and transcode nodes) and the CPU-decode retry for explicit hardware backends. The title is specific and matches the changeset.
Full details: Linked Issues check
Explanation
[#4030] The requirement is a CPU-decode retry for explicit hardware backends (for example NVENC) when FFmpeg reports "Hardware is lacking required capabilities". The diff implements this for the four named paths. In internal/playback/transcode_startup.go, startReconstructOnce waits on eligible reconstructs and, on a decoder rejection, runs NewSoftwareDecodeRetryPipeline in the same output directory. HardwareDecodeRetryEligible gates eligibility. In internal/jellycompat/streams.go, awaitCompatAutoTranscode now runs the same retry for a disabled explicit-backend pipeline, and ensureTranscodeSessionWithToneMapMode waits on eligible explicit starts. The node-side spawnReconstruct in internal/transcodenode/server.go routes explicit backends through StartReconstructTranscode. The issue's download-preparation gap is covered by existing #4057 behavior, per the PR description, and the issue's scope is satisfied by the four paths named in the PR objective. Test coverage for each path is present in the diff (jellycompat, playback, transcodenode tests). Hardware reproduction is not a coding requirement and was not performed; that is a validation gap, not an unmet requirement. Limits: I read the diffs of transcode_startup.go and streams.go only, not the test bodies or the other changed files.
Full details: Out of Scope Changes check
Explanation
The changed hunks in internal/playback/transcode_startup.go, internal/jellycompat/streams.go, handlers_playback.go, and transcodenode/server.go connect to the four paths named in #4030 and the PR objective. The MPEG-4 Part 2 exclusion in HardwareDecodeRetryEligible is a narrowing of the same retry gate and is described in the PR. The NewSoftwareDecodeRetryPipeline refactor reuses the same predicate, so existing retry gating stays consistent. The comment and doc changes (restart-resilient-playback.md, worker-http-protocol.md, transcode_manager.go comment) describe the new rules and do not add behavior. Test changes support the new behavior. Behavior changes that the PR lists as risks (longer waits, RequireReady on node starts, lock holding during rebuild) follow directly from the in-scope fix and are not unrelated work. I did not find an unrelated change in the inspected hunks. Unread test and doc hunks were not inspected in detail.
Full details: Description check
Explanation
The description is specific and on-topic. It names the problem (an explicit NVENC backend whose GPU decoder rejects HEVC input, causing FFmpeg to exit with 'Hardware is lacking required capabilities'), lists the four affected startup and rebuild paths, and explains the approach (wait for a manifest or exit, then retry with CPU decode and the hardware encoder, then software). It also covers validation, risks, and follow-ups. These match the changeset, which touches the Jellyfin-compatible handlers, streams, transcode startup, transcode node server, and the related tests and docs.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Concurrent requests can observe the failed session before decoder fallback
A concurrent manifest request can receive the failed GPU-decode session and tear down playback while CPU fallback starts. Coordinate callers through awaitCompatAutoTranscode so they receive only a ready session or its successor.
Prompt for LLM
File internal/jellycompat/streams.go, lines 3287-3291:
Concurrent requests can observe the failed session before decoder fallback
A concurrent manifest request can receive the registered GPU-decode session after it has exited but before this wait replaces it, causing manifest handling to fail and tear down the playback session while the CPU fallback is starting. Coordinate concurrent callers with the in-progress startup and return only the ready session or its successor.
The reason will be displayed to describe this comment to others. Learn more.
This race is real, but it predates this change and this change doesn't make it worse.
On main, hw_accel=auto already runs this wait-and-replace loop. A second manifest request adopts the registered session at the two existing checks in ensureTranscodeSessionWithToneMapMode, which this pull request doesn't touch.
For an explicit backend, main fails this start every time. Here it fails only when a second manifest request lands between FFmpeg's exit and the replacement.
It needs the real-manifest path (unknown duration, or more than 50,000 segments). With the generated VOD manifest the second caller never touches the session.
Closing it means making concurrent callers wait on a startup that is still in progress, which changes the Auto path as well. I'm leaving that out of this change and raising it with the maintainer.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Given that the race already affects the Auto path and the explicit-backend path improves on the existing failure, it makes sense to raise it separately rather than expand this PR.
The follow-up should cover concurrent requests adopting a registered session before startup and fallback have completed, including the real-manifest conditions where the race can surface. Would you like me to create an issue to track it?
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Performance & Scalability · Heavy lift
Keep NVENC when a reconstruct restores a CPU-decode retry.
A CPU-decode retry can start NVENC with SoftwareVideoDecode set and nvencSoftwareDecode set. NewRecipeCard persists only SoftwareVideoDecode. Under explicit NVENC, a later reconstruct uses a disabled pipeline, so nvencSoftwareDecode stays false. Normalization then selects HWAccelNone, and the rebuilt session can use libx264 instead of NVENC. The reconstruct also skips the decoder retry, because HardwareDecodeRetryEligible requires SoftwareVideoDecode to be false.
The recipe must keep the mixed-stage NVENC permission across reconstruction. Persisting a marker for this case changes the rule documented on nvencSoftwareDecode, which keeps reconstruction tied to live configuration. Choose a design that preserves that rule for auto while fixing the explicit NVENC case.
This pull request doesn't change that path. It lets more sessions start, and the ones it adds never played before. A rebuilt session still plays, on the software encoder.
Keeping NVENC needs a new field on the recipe card, which also travels in the stream token. That is a design decision, so it belongs in its own change.
I'm raising it with the maintainer and leaving this thread open for them.
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: P1Core-path bug; painful workaround — next after P0size/L200–499 added + deleted lines (all files); change volume, not priority.
1 participant
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
Closes #4030
Related issue: N/A
Validation tasks: unblocks #1172 C2
Other clients: N/A (no client-visible change)
With Hardware acceleration set to an explicit backend such as NVENC, a GPU whose decoder can't take the source (HEVC on a GTX 970) makes FFmpeg exit at startup with
Hardware is lacking required capabilities. #4057 made the starts that wait for a first manifest retry with CPU decoding. Four paths start FFmpeg without waiting, so they never saw the rejection and handed back a process that had already exited:On such a server, Jellyfin clients could not start an HEVC transcode at all. A rebuild fails the same way when its recipe was written where the GPU does decode the source: after the operator switches Hardware acceleration from Auto or None to NVENC, or when a Jellyfin transcode moves off a dead node, which rebuilds on the new executor instead of starting fresh.
This change makes all four paths decode on the CPU when the decoder rejects the source, using the retry #4057 added.
Approach
A start under an explicit hardware backend that decodes on the GPU, without tone mapping, is now waited on until its first manifest or its exit. If FFmpeg exits with the decoder rejection, the path walks the same order as #4057: CPU decode with the hardware encoder, then software. One exported predicate,
playback.HardwareDecodeRetryEligible, decides which starts are waited on, andNewSoftwareDecodeRetryPipelinenow uses it for its own gate.Only a decoder rejection changes what three of the paths do. A ready process, a slow one, and one that exits for any other reason are returned as they were, so the existing exit monitor and segment recovery still handle them.
The Jellyfin node start is the exception. The API server now sends
RequireReadyfor an eligible start, which reuses the node behavior #4057 shipped and needs no node change.RequireReadyalso closes a process that has no manifest after 30 seconds.hw_accel=autoon this path and every native start already work that way.On a transcode node, a rebuild whose backend already has its own software retry (VideoToolbox, or QSV/VAAPI without a render device) keeps that path unchanged, so no start is waited on twice. A rebuild's retry is launched on a context detached from the request that triggered it, because other requests wait on the same rebuild.
worker-http-protocol.mdandrestart-resilient-playback.mddescribe the new start and rebuild rules.Validation
mainfor the reported reason (one GPU-decode attempt, then a dead or unwaited start) and passes here. The Jellyfin and node tests run a fake FFmpeg that prints the NVDEC line for any-hwaccel cudacommand.go build ./...,gofmt -l,go mod tidy -diff,go vet,make lint-changed,make lint-router-recovery,make verify-local-paths: clean.make test-go: no test fails here that passes onmain. On the machine I ran it on,mainitself failsTestCopyRemuxSubtitleRenditionRealFFmpeg(stock FFmpeg 6.1.1) and tests ininternal/ebookconvert,internal/mediasample,internal/uploads,internal/backupandinternal/api/handlers; the same tests fail with this change. CI is the check for those.hw_accel=auto. Under an explicit backend, the worker-loss cases Distributed transcode nodes — Server #1177 C3 and Distributed transcode nodes — Web admin #1178 C2 wait a few seconds longer on a rebuild; the build they passed on does not record its Hardware acceleration setting.Evidence
No capture: nothing visible changes, and no hardware here reproduces the rejection. The page holds the failing run on
mainand the passing run on this branch for the four tests.Evidence: https://evidence.siloserver.org/r/silo-server/issue-4030/
Risks
RequireReadywithout the retry. It now fails the start as soon as FFmpeg exits, and the API server tries elsewhere, where before it reported the dead process as started.hw_accel=autoalready holds the same locks for the same wait.Follow-ups: the review turned up two defects that already exist on
main, filed separately. #4098: a rebuild underhw_accel=autolaunches its fallback attempts on the triggering request's context. #4099: a node rebuild with a software retry can accept a manifest left by an earlier process. The user manual needs no change; its playback and node pages don't describe how an explicit backend falls back.Checklist
AI Disclosure
high(three finders, a validation check, four verifiers) followed. The review found no correctness defect in the change. It led to one fix (MPEG-4 Part 2 sources are no longer waited on) and to the Risks above. A background adversarial review by gpt-6.1-sol of 1f2f62e, run after this pull request opened, found nothing and posted no review.