Repository navigation
fix(playback): restart Intel transcodes on CPU decode after a filter graph failure - #4105
Conversation
…graph failure On QSV and VAAPI, some HEVC sources make the VAAPI decoder replace its frames context mid-stream. FFmpeg cannot rebuild the filter graph for the hardware encoder that is already open and exits with "Error reinitializing filters!". A restart ran the same command again, so the transcode failed at the same frame every time. A restart that follows such an exit now decodes on the CPU and keeps the GPU tone mapper and encoder. The switch is decided before the restart's tone-map source check, and the VAAPI route passes -noautorotate so a rotated source keeps the orientation of the segments already served. On an integrated server the local exit monitor tore the session down before a segment request could restart it. It now restarts the session itself at the client's position and falls back to the teardown when that restart cannot start. Closes #2813 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 11 minutes. View limit details
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis 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: eb0b0ea303
ℹ️ 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".
| flight := &restartFlight{done: make(chan struct{})} | ||
| s.restarting = flight | ||
| opts := s.opts | ||
| decodeOnCPU := s.gpuDecodeFailedFilterSetupLocked() |
There was a problem hiding this comment.
Transcode nodes do not restart crashed sessions on CPU decode
For unknown-duration or oversized streams, FFmpeg's playlist can end before a missing segment triggers restart, leaving playback stalled after a GPU decode failure. Add an exit-triggered CPU restart for transcode-node sessions.
Prompt for LLM
File internal/playback/transcode.go, line 3662:
Transcode nodes do not restart crashed sessions on CPU decode
Transcode-node sessions never invoke this fallback when FFmpeg exits, because their restart hook only arms the throttler and their manifest handler serves the existing session without restarting it. For unknown-duration or oversized streams that use FFmpeg's real playlist, the playlist stops before the missing segment, so no segment request triggers `restart` and playback remains stalled; add an exit-triggered CPU restart for node sessions as well.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
This is real, and it is the same on main: a transcode node has no exit monitor, so any FFmpeg error exit on a session served from FFmpeg's own playlist (unknown duration, or too long for the synthetic playlist) stalls until a segment request arrives. This pull request doesn't change that path. For the common case, a synthetic playlist, the client requests the missing segment and the node's restart now decodes on the CPU.
An exit-triggered restart on nodes needs its own lifecycle handling in the node server, so I've left it out here. It is listed under Risks as an open gap.
🤖 Claude Code (claude-fable-5-2)
There was a problem hiding this comment.
Thanks for clarifying. The suggestion identifies a real, pre-existing gap, rather than a regression introduced by this PR. The synthetic-playlist path benefits from the CPU-decode fallback; sessions using FFmpeg’s own playlist may still stall because no missing-segment request triggers a restart.
Given the separate lifecycle handling required and the documented risk, a follow-up issue would be a reasonable way to track node-side exit-triggered recovery.
…om live options The fallback set SoftwareVideoDecode on the session, so a recipe written from its live options (the Jellyfin-compatible audio-track switch persists one) recorded CPU decode without the orientation rule that goes with it. A later reconstruct of a rotated VAAPI source would then rotate frames that earlier segments left unrotated. The fallback now lives in one unexported option that normalization turns into CPU decode, so recorded recipes still say GPU decode and a reconstruct produces the same orientation. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
The exit monitor read "exited with an error" and "the next restart decodes on the CPU" separately. A segment request that finished the CPU-decode restart between those reads made the second one false, and the monitor tore down the healthy replacement. Both facts now come from one read under the session lock, in the monitor and in its recheck under the lifecycle lock. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #2813
Related issue: N/A
Validation tasks: unblocks #1173 C3; unblocks #1174 C3
Other clients: N/A (no client-visible change)
On an Intel GPU (QSV or VAAPI), some HEVC files stop playing a few seconds into a transcode and never recover. The VAAPI decoder replaces its frames context mid-stream, FFmpeg can't rebuild the filter graph for the hardware encoder that is already open, and it exits with
Error reinitializing filters!. A transcode node then runs the same command again on every segment request (one session reachedrestart_count=31). An integrated server tears the transcode down, the client rebuilds it on GPU decode, and it dies at the same frame.With this change the restart decodes on the CPU and keeps the GPU tone mapper and encoder, so playback continues after one interruption.
Approach
TranscodeSession.restartnow looks at why the previous FFmpeg process ended. When a QSV or VAAPI process that decoded on the GPU exited by itself withError reinitializing filters!in its stderr, the replacement decodes on the CPU and uploads frames into the same graph. These backends already have CPU-decode graphs for plain scaling, subtitle burn-in, and hardware tone mapping (H.264 High 10 uses them today). The session stays on CPU decode until it ends. Transcode nodes, the native API, and the Jellyfin-compatible surface all restart through this function.-noautorotate. The VAAPI fallback passes it, so a rotated source keeps the orientation of the segments already served. QSV always passed it.FFmpeg runs at
-loglevel error, so its reason for the rebuild (an info line) is never captured and the error line is the only signal. That line also follows other filter graph failures. The switch therefore requires that the process exited by itself with an error, applies only to QSV and VAAPI, and happens once per session. NVENC is left out because an explicit NVENC setting with CPU decode encodes on libx264.The switch lives in the running session, in one private option that leaves the recorded decode mode alone. Recipe cards and stream tokens still record GPU decode, including a recipe the Jellyfin-compatible audio-track switch writes from the live session. A reconstruct or a re-home therefore starts on GPU decode, produces the same orientation, and recovers the same way.
Validation
mainat 5122f84 the restart test fails because the restart repeats-hwaccel vaapi(QSV and VAAPI rows), and the monitor test fails because the session is torn down. The restart test also checks that a recipe written from the live session still records GPU decode. One more case, where the monitor's restart can't start and the session is torn down, passes onmaintoo and guards the failure path.go build ./...,gofmt -l .,go mod tidy -diff,go vet ./...,make lint-changed,make lint-router-recovery,make verify-playback-fixtures: clean.make test-go: 29 tests fail on my host, one of them ininternal/playback(TestCopyRemuxSubtitleRenditionRealFFmpeg) and the rest inapi/handlers,backup,ebookconvert,mediasample, anduploads. All 29 fail the same way on a clean checkout ofmainthere, so CI is the check for those.Evidence
No capture on real hardware, for the reason above. The evidence page has the tests' failing run on
mainand their passing run on this branch.Restart command for a VAAPI session after the failure, trimmed to the decode and filter arguments:
Before (
mainat 5122f84):After (this branch):
Evidence: https://evidence.siloserver.org/r/silo-server/issue-2813/
Risks
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Add test for restarting Intel transcodes on CPU decode after filter graph failure
Adds
TestLocalExitMonitorRestartsFilterReinitFailureOnCPUDecodein restart_locked_test.go, a synctest-based test covering two cases: a replacement FFmpeg process starts, or FFmpeg is unavailable and the session is torn down. It builds a failed local QSV session whose stderr contains a filter-reinitialization failure, then runs the local exit monitor. It verifies session registration or teardown, that the restart uses CPU decoding, and that playback resumes at the last requested segment.Macroscope summarized d983d4e.