Skip to content

fix(playback): stop forcing a transcode for multi-PPS H.264 - #5144

Merged
Quick104 merged 8 commits into
mainfrom
fix/playback-multi-pps-copy-recovery
Nov 23, 2026
Merged

Quick104 merged 8 commits into
mainfrom
fix/playback-multi-pps-copy-recovery

Conversation

@CoffeeKnyte

@CoffeeKnyte CoffeeKnyte commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Four commits: one removes code, one fixes a scan that could be lost, one changes how these files are planned, and one restores a test. Review added three more: strict browsers stay on the transcode for flagged files, and docs and comments match the code. This replaces #3475, which tried the same thing with extra rules that newer planner code makes unnecessary.

Problem

Related issue: N/A
Validation tasks: changes #197 (Movies/Server playback criterion "remux/transcode fallback"), #199, Silo-Server/silo-apple#22, Silo-Server/silo-apple#23, Silo-Server/silo-android#7, Silo-Server/silo-android#8 (Movies playback); changes #1250 C5, #1252 C3, Silo-Server/silo-apple#337 C3, Silo-Server/silo-apple#338 C3, Silo-Server/silo-android#347 C3, Silo-Server/silo-android#348 C3 (Series playback). None has a recorded result yet.

Other clients: N/A (no client change needed: the Apple, Android, Roku and web apps already report a failed video and ask the server for another way to play it)

Some videos always got the expensive treatment. Some H.264 video files are built in an unusual way: they change their picture settings partway through. Some players show an error when they play them, like Safari and Chrome on a Mac. Most players handle them fine, like the Android apps and the Apple apps.

In #424 the server started converting every one of these files into a new video before sending it, unless the player could play the file exactly as it is on disk. That conversion is called a transcode. It is heavy work for the server on every play, and the picture loses some quality. So an Android TV that could not open the file's container, or needed different audio, got a transcode it did not need. A cheaper option was there: copy the video as it is into a container the player accepts. That copy is called a remux.

Why it was built that way. In July the web player stopped on its first error, and the server had no good way to move a player down to the next option. Blocking the remux up front was the only safe choice. #734 later added a background scan that finds these files, and code that pulled a remux away from a player in the middle of a play once the scan found one.

What changed since then. Every client app now tells the server when a video fails and asks for the next option. Since #3948, the server picks from an ordered list of ways to play a file, and it skips every way the player has already failed. So the server no longer has to guess ahead of time which players can handle these files. It can let the player try the cheap way and move on if the player says it failed.

What this change does. A flagged file is planned like any other file. A player that handles it gets a remux. A player that can't handle it reports the failure and moves down the list until it reaches the transcode. Browsers other than Firefox are the exception: they are the players that fail these files, so they still get the transcode on the first try.

Approach

For a flagged file, the server tries these in order, skipping any the player already failed:

  1. send the file as it is          (direct play)
  2. remux, progressive download     (video copied, container or audio changed)
  3. remux, HLS                      (video copied)
  4. transcode                       (video converted)

  Android TV, file it can open:       1 plays                        → nothing converted
  Android TV, needs different audio:  3 plays (1 and 2 not offered)  → only the audio converted
  Another player that can't decode it: 1 fails → 2 fails → 3 fails → 4 plays
  Safari, Chrome and other browsers except Firefox: 4 plays          (1, 2 and 3 not offered)

  Before this change: steps 2 and 3 were never offered for a flagged file.

Nothing new is stored and there is no migration. Downloads never remux these files, because a download can't recover from a failure: a download keeps the original when the device plays it, and is transcoded otherwise.

Technical detail

The flagged files are H.264 streams that redefine the same pic_parameter_set_id in-band with different content (multi-PPS). Decoders that apply in-band parameter sets (Media3 on Android) play a stream copy of them. Decoders that use only the sample entry's parameter sets (VideoToolbox, browser Media Source Extensions) fail on them, for direct play and every copy delivery alike.

refactor(playback): stop ending stream copies on the copy-safety verdict

A copy that plays has shown that its decoder handles the source, so the verdict no longer ends a copy that is playing or refuses to rebuild one.

  • Removes CopySafetyNotifier (internal/playback/copy_safety_notifier.go) and its handler adapter. A verdict that lands mid-play no longer sends plan_invalidated or stops the session.
  • Removes the refusals in internal/api/handlers/playback_copy_safety.go and their call sites in the HLS serve path, the progressive remux path (stream.go) and the node rehome (errRehomeCopyUnsafe). A copy rebuilt after a replica restart, a node loss or a rehome is served like any other recipe. On feat(playback): try a remux of multi-PPS H.264 first and transcode only after it fails #3475 the maintainer review found these refusals ending copies that were playing fine.
  • CopySafetyRace now only scans and persists the verdict, deduped per file and capped at four concurrent scans.
  • The plan_invalidated_v1 protocol, its video_copy_unsafe reason and the client contract stay. No server path sends the command now; §6.1 of docs/architecture/playback-protocol-v3.md says so.

fix(playback): rescan a file whose scan request arrived mid-scan

The race used to drop a scan request for a file whose scan was already running. If the file was rewritten in place during that scan, the scan came back stale and saved nothing, so the new file stayed unscanned until a later play asked again. A request that arrives mid-scan now gets one more pass when the running scan ends (internal/playback/copy_safety_race.go). Kody raised this on #3475.

fix(playback): stop forcing a transcode for multi-PPS H.264

  • routeFacts in internal/playback/candidate_video_v3.go no longer turns off the remux routes for source.VideoCopyUnsafe. That one condition was the gate from fix(playback): transcode H.264 sources with conflicting in-band PPS #424.
  • Recovery is the existing walk: each failed route's plan_attempt_key joins attempted_plan_keys, the candidate list skips those keys, and the walk ends at the encode (copy_routes_exhausted). Clients bound the walk with attempt_count (up to 8).
  • The verdict now feeds only the download policy (playback.Resolve, used by internal/downloads) and the surround-conversion route, which stays skipped for these sources.
  • jellycompat never read the verdict and is unchanged.
  • §6.1.1 of the protocol doc describes the rule.

test(playback): keep the start-path copy-safety race covered

Restores the test that a start does not wait on the copy-safety scan, written against the remaining race API.

fix(playback): keep strict browsers encode-first, and off direct play (review)

A track, audio, subtitle or quality change, or a reconnect, is an intent replan, and it drops attempted_plan_keys (playback_v3.go, if !intentChange && !seekReanchor && !userIntentOperation). A browser that had walked to the transcode was offered the failed copies again in the middle of playback. routeFacts now sets sourceFailsOnClient for a copy-unsafe source when strictParameterSetWebV3 holds (platform web, not Firefox), and that keeps both the original and the remux candidates off. Those browsers get the transcode on the first plan. Firefox and the native apps keep direct play and the remux. §6.1.1 of the protocol doc describes the exception.

docs(playback): describe the copy-safety verdict as it now works (review)

Removes comments and docs that still described the withdrawn copy, and states precisely when a download keeps the original.

Validation

  • go build ./..., gofmt, go mod tidy -diff, go vet ./...: clean.
  • make lint-changed and make lint-router-recovery with golangci-lint v2.15.0 (CI's version): 0 issues.
  • make verify-route-inventory, verify-apiv2-openapi, verify-apiv2-contract, verify-apiv2-fixtures, verify-playback-fixtures, verify-settings-bindings, verify-local-paths, verify-size-ratchet, verify-migrations, and TestCommittedArtifactMatchesRouter: pass.
  • make test-go, with real-FFmpeg tests run against jellyfin-ffmpeg 8: pass. Tests in internal/backup, internal/ebookconvert, internal/uploads and internal/api/handlers failed at first because the test host's umask made their temp directories group-writable. They fail the same way on main, and they pass when rerun with umask 022.
  • Tests cover a flagged source still getting a copy route, a strict decoder's recovery walk reaching the transcode, Safari and Chrome getting the transcode on the first plan for an MKV and an MP4 source while Firefox keeps the copy and direct play, and a scan request that arrives mid-scan getting its own pass.
  • TestPlanPlaybackV3CopyUnsafeSourceStillCopies fails on main (it plans copy_routes_exhausted), and its browser assertions fail on the head before each review fix.
  • After the review fixes: go test ./internal/playback/... ./internal/scanner/... ./internal/catalog/... ./internal/downloads/... ./internal/api/handlers/, make verify-playback-fixtures and make lint-changed: pass, 0 issues.
  • Not run: the web half of the gate. No web files changed, and pnpm is not installed on the test host (so verify-settings-bindings-web was skipped too).

Evidence

Nothing changes on screen. These commits, on main from 2026-11-22, ran on a production deployment for 7 hours. Plays of flagged files in that window:

Outcome Plays
Played the file as it is (iPad, Apple TV, Android TV, Android phone, Firefox on macOS) 27
Remux over HLS (Android TV app 1.0.0) 1
Transcode because of the viewer's quality setting or a bandwidth limit 3
Stopped by the viewer 2 s in, before the first frame (they started the next episode right away) 1
  • The one remux reached its first frame in 2.1 s with no stalls. A subtitle change planned a second remux, which also played. The viewer then picked a fixed quality, which moved it to a transcode as expected. It stopped normally about 2 hours later. Before this change, that play would have been a transcode from the start.
  • No flagged play reported a failure or asked for a recovery replan.
  • The server logged copy_routes_exhausted 0 times in those 7 hours, against 4 in the 24 hours before.
  • Not seen yet: Safari or Chrome on a Mac playing a flagged file. After review they get the transcode up front for a file the scan has flagged, so the walk only matters for the first play of a file not scanned yet.

The evidence page from #3475 shows an iPad, Chrome and an Android TV playing one of these files. Those captures come from #3475's first implementation. That version skipped the HLS remux after the first failed copy, so Chrome reached the transcode in about 4 seconds there. With this change it fails one more remux first.

The planner tests for the review fixes are on this PR's evidence page.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5144/

Risks

  • Browsers other than Firefox are matched as a group. Failures were seen only in Safari and Chrome on a Mac. Chrome on Windows, Linux and Android, Edge, and embedded web views are treated the same way. For those, a wrong guess costs a transcode they may not need, which is what main does for every client.
  • A file the scan hasn't reached yet plans as safe. Its first play in Safari or Chrome can still walk the failures until the background scan lands. Whether those browsers report an error or stall hasn't been tested.
  • A player that breaks without saying so won't be caught. Some Android devices fall back to a built-in software decoder that shows a broken picture without reporting an error. The server never hears about it, so it never moves on. Those devices were already at risk when they played the file as it is.
  • Each new viewing starts over. The server doesn't remember which devices failed these files, so a non-browser player that can't decode them goes through the same failures on every viewing, and again after a track or quality change.
  • A remux that fails for another reason, such as the network, also moves the player down the list. That's no different from any other file.
  • No database change.

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.

Council review

Rounds: 2, last reviewed 8a62ed0

Member Round 1 Round 2
Sol (gpt-6.2-sol, medium) 6/10 7/10
Opus (claude-opus-5-5, medium) 6/10 7/10
Gemini (gemini-4-neon, medium) 6/10 7/10

Nothing changes on screen, so there was no visual review.

Fixed: strict browsers kept on the transcode across track, quality and reconnect replans, remux and direct play alike; download and withdrawal wording. Answered: plan_invalidated_v1 stays advertised as the wire contract; issues that main has for every file (an unavailable remux executor, stale-card revival, unscanned downloads) are out of scope here.

AI Disclosure

Loading
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 needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants