Repository navigation
fix(playback): choose the remux container instead of always writing MP4 - #153
Conversation
The progressive remux passed a literal "mp4" as its output format at every call site -- stream.go, jellycompat, and the proxy -- so the client's declared `containers` list had no effect on what it received. A Matroska source played by a client that declares mkv was still rewritten into fragmented MP4. That rewrite is not free. MP4 keeps its index in a moov box that a normal write patches at the end, which a pipe cannot do, so streaming MP4 means fragmenting it. And several codecs a remux copies are spec-legal in MP4 but unreliable in practice: AC-3, E-AC-3, DTS and TrueHD all sit in that category, which is why remuxAudioCopySafe already refuses to treat a bare codec claim as evidence for them. Matroska has neither problem -- it streams unfragmented and carries those codecs unambiguously. RemuxOutputContainer keeps the source container when the client declared it and falls back to MP4 otherwise. One rule covers both reasons a session remuxes: a client that cannot play the container never declared it, so it still gets MP4 -- which is what that session needed -- while a client that can play it but needs a specific audio track mapped keeps the container it already demuxes. Trusting the declared list adds no new trust. Resolve already serves that exact container byte-for-byte via direct play on the same claim (containerOK, Case 1), so a client that over-claims a container is already broken there and this does not make it more so. Verified against the real file rather than only in arg assertions: remuxing the AV1/TrueHD test source into Matroska with the AC-3 track mapped writes 22.7 MB to a pipe, exit 0, and probes as av1 video + ac3 5.1(side) audio -- both copied, surround intact. The same session as MP4 lands AC-3 in fragmented MP4, the combination flagged above. movflags are now emitted for MP4 only, since fragmentation is an MP4 workaround rather than a property of piped delivery. The container is carried on the session, recipe card and token claims so a reconstruct after a restart does not switch containers mid-stream, and the proxy reads it from the claims so the same token yields the same container wherever it is served. An empty value keeps the MP4 default, so existing sessions and older tokens behave exactly as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Warning Review limit reached
Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
Comment |
What
The progressive remux passed a literal
"mp4"as its output format at every call site —stream.go,jellycompat, and theproxy— so the client's declaredcontainerslist had no effect on what it received. A Matroska source played by a client that declaresmkvwas still rewritten into fragmented MP4.RemuxOutputContainernow keeps the source container when the client declared it, and falls back to MP4 otherwise.Why it matters
Rewriting into MP4 isn't free:
moovbox that a normal write patches at the end, which a pipe cannot do — so streaming MP4 means fragmenting it.remuxAudioCopySaferefuses to treat a bare codec claim as evidence for them.Matroska has neither problem: it streams unfragmented and carries those codecs unambiguously. #151 made AC-3 copy into the remux container on a plain claim, so without this change the common path lands AC-3 in fragmented MP4 — exactly the combination flagged above.
One rule, both cases
Trusting the declared list adds no new trust:
Resolvealready serves that exact container byte-for-byte via direct play on the same claim (containerOK, Case 1). A client that over-claims a container is already broken there, and this doesn't make it more so.Verification
Not just arg assertions — the real file. Remuxing the AV1/TrueHD test source into Matroska with the AC-3 track mapped:
exit=0, no stderrav1video +ac3/channels=6/5.1(side)audio — both copied, surround intactffmpeg -h encoder=ac3and container behavior were checked against the binary in our own image rather than documentation.Notes
movflagsare emitted for MP4 only — fragmentation is an MP4 workaround, not a property of piped delivery.webmis deliberately excluded: it's a Matroska subset that can't carry AC-3 or H.264, so choosing it would turn a stream copy into a re-encode.Pre-existing failures unrelated to this change (both fail at
maintoo):TestServeDirectPlayChangedEntityRejectsOldIfRange,TestHandleReplanPlaybackV3SeekFailureRecoveryNeverChangesMediaVersion.🤖 Generated with Claude Code