Skip to content

fix(playback): restart Intel transcodes on CPU decode after a filter graph failure - #4105

Merged
Quick104 merged 3 commits into
mainfrom
fix/vaapi-qsv-transcode-2813
Nov 13, 2026
Merged

Quick104 merged 3 commits into
mainfrom
fix/vaapi-qsv-transcode-2813

Conversation

@Quick104

@Quick104 Quick104 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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 reached restart_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.restart now looks at why the previous FFmpeg process ended. When a QSV or VAAPI process that decoded on the GPU exited by itself with Error 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.

  • The switch is decided before the restart's tone-map source check, so a preflight validates the CPU route that will run.
  • FFmpeg rotates CPU-decoded frames by the source's display matrix but never hardware frames, and VAAPI passed no -noautorotate. The VAAPI fallback passes it, so a rotated source keeps the orientation of the segments already served. QSV always passed it.
  • On an integrated server the local exit monitor tore such a session down two seconds after the exit, before a segment request could restart it. The monitor now restarts the session itself, at the last segment the client downloaded, under the session lifecycle lock. If that restart can't start, the teardown runs as before.

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

  • Not reproduced on hardware. I had no Intel GPU, and the sandbox host can't run VAAPI or QSV. The defect is shown from the source (the restart rebuilt the same command, and the exit monitor tore the session down) and from the reporter's FFmpeg logs on [bug] Intel hardware transcodes die when the VAAPI decoder rebuilds its frames context mid-stream #2813.
  • Focused tests with a fake FFmpeg that fails the way the issue's node log shows: pass. On main at 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 on main too 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 in internal/playback (TestCopyRemuxSubtitleRenditionRealFFmpeg) and the rest in api/handlers, backup, ebookconvert, mediasample, and uploads. All 29 fail the same way on a clean checkout of main there, so CI is the check for those.
  • Web and generated-contract checks: not run. No web or contract file changes.

Evidence

No capture on real hardware, for the reason above. The evidence page has the tests' failing run on main and their passing run on this branch.

Restart command for a VAAPI session after the failure, trimmed to the decode and filter arguments:

Before (main at 5122f84):

-init_hw_device vaapi=hw:<device> -filter_hw_device hw -hwaccel vaapi -hwaccel_output_format vaapi ... -c:v h264_vaapi ... -vf scale_vaapi=format=nv12

After (this branch):

-init_hw_device vaapi=hw:<device> -filter_hw_device hw -noautorotate ... -c:v h264_vaapi ... -vf format=nv12,hwupload

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2813/

Risks

  • Unverified on real Intel hardware: that CPU decode with a GPU upload carries the reported file past the frame where GPU decode fails. The issue reports that software decode of the file is clean.
  • A different filter graph failure on QSV or VAAPI also moves that session to CPU decode, once. The session had already failed, so the cost is higher CPU use when the retry works.
  • A session that switched uses more CPU for the rest of playback, and Activity still shows the hardware encoder.
  • An integrated server now restarts such a session where it used to stop it. The restart encodes again the segments FFmpeg had produced beyond the client's last download.
  • For a tone-mapped source that needs a preflight, the CPU route's preflight runs inside the restart's 20-second budget. If it fails, a node fails the restart on each request and an integrated server tears the session down, which is what happened before this change.
  • Gaps this change leaves open:
    • A ready-gated start, reconstruct, or re-home that hits the failure before its first manifest still fails.
    • Download preparation still fails mid-file on these sources.
    • On a transcode node, recovery waits for a segment request, so a stream served from FFmpeg's own playlist (unknown duration) may not recover.

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, Codex, GitHub CLI
  • Model(s): claude-fable-5-2 (implementation and review), claude-sonnet-5-5 (review subagents), gpt-6.1-sol and claude-opus-5-5 (plan review)
  • Involvement: AI-assisted. An agent wrote and tested the change; the maintainer directed the work.
  • Adversarial review: Code review at high effort, two rounds (three finder subagents and a 1.0 validation check). Round one found that the integrated server's exit monitor tore the session down before a restart could reach it. Round two moved the monitor's restart to the client's position and closed a path that skipped the teardown after a failed restart. Plan review, two rounds: gpt-6.1-sol attacked the plan and added the orientation flag, the preflight ordering, and the monitor-initiated restart; claude-opus-5-5 cut a redundant copy-video condition, a doc paragraph, and a real-time wait in a test. A simplify pass ran before each commit. The Codex review on this pull request found that an audio-track switch could persist CPU decode without its orientation rule; the second commit keeps the fallback out of recorded recipes. The background adversarial review (gpt-6.1-sol, reviewed eb0b0ea) found that the exit monitor read a crashed session's state in two steps and could tear down a replacement a segment request had just started; the third commit reads it once.

🤖 Generated with Claude Code

Note

Add test for restarting Intel transcodes on CPU decode after filter graph failure

Adds TestLocalExitMonitorRestartsFilterReinitFailureOnCPUDecode in 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.

…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]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: dd597bf3-d456-4cb7-9e41-0c6e5a5e96cc
Commits

Reviewing files that changed from the base of the PR and between 2e05489 and d983d4e.

Files selected for processing: 4

  • internal/playback/restart_locked_test.go
  • internal/playback/transcode.go
  • internal/playback/transcode_hwdevice_test.go
  • internal/playback/transcode_manager.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:15:24.835112Z d983d4e New commits
🔒 Security Review ✅ Completed 2026-11-13T20:18:08.832985Z d983d4e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 labels Nov 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/playback/transcode.go Resolved
flight := &restartFlight{done: make(chan struct{})}
s.restarting = flight
opts := s.opts
decodeOnCPU := s.gpuDecodeFailedFilterSetupLocked()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (gpt-6.1-sol, reviewed eb0b0ea)

AI-generated review: Codex (gpt-6.1-sol), run by the maintainer's agent.

Comment thread internal/playback/transcode_manager.go Resolved
…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

silo-kody Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

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

silo-kody Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0 size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Intel hardware transcodes die when the VAAPI decoder rebuilds its frames context mid-stream

1 participant