Repository navigation
fix(playback): stop forcing a transcode for multi-PPS H.264 - #5144
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
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_idin-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.
CopySafetyNotifier(internal/playback/copy_safety_notifier.go) and its handler adapter. A verdict that lands mid-play no longer sendsplan_invalidatedor stops the session.internal/api/handlers/playback_copy_safety.goand 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.CopySafetyRacenow only scans and persists the verdict, deduped per file and capped at four concurrent scans.plan_invalidated_v1protocol, itsvideo_copy_unsafereason and the client contract stay. No server path sends the command now; §6.1 ofdocs/architecture/playback-protocol-v3.mdsays 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
routeFactsininternal/playback/candidate_video_v3.gono longer turns off the remux routes forsource.VideoCopyUnsafe. That one condition was the gate from fix(playback): transcode H.264 sources with conflicting in-band PPS #424.plan_attempt_keyjoinsattempted_plan_keys, the candidate list skips those keys, and the walk ends at the encode (copy_routes_exhausted). Clients bound the walk withattempt_count(up to 8).playback.Resolve, used byinternal/downloads) and the surround-conversion route, which stays skipped for these sources.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.routeFactsnow setssourceFailsOnClientfor a copy-unsafe source whenstrictParameterSetWebV3holds (platformweb, 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-changedandmake lint-router-recoverywith 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, andTestCommittedArtifactMatchesRouter: pass.make test-go, with real-FFmpeg tests run against jellyfin-ffmpeg 8: pass. Tests ininternal/backup,internal/ebookconvert,internal/uploadsandinternal/api/handlersfailed at first because the test host's umask made their temp directories group-writable. They fail the same way onmain, and they pass when rerun with umask 022.TestPlanPlaybackV3CopyUnsafeSourceStillCopiesfails onmain(it planscopy_routes_exhausted), and its browser assertions fail on the head before each review fix.go test ./internal/playback/... ./internal/scanner/... ./internal/catalog/... ./internal/downloads/... ./internal/api/handlers/,make verify-playback-fixturesandmake lint-changed: pass, 0 issues.verify-settings-bindings-webwas skipped too).Evidence
Nothing changes on screen. These commits, on
mainfrom 2026-11-22, ran on a production deployment for 7 hours. Plays of flagged files in that window:copy_routes_exhausted0 times in those 7 hours, against 4 in the 24 hours before.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
maindoes for every client.Checklist
Council review
Rounds: 2, last reviewed 8a62ed0
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_v1stays 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