Skip to content

fix(playback): play MPEG-TS files with AAC audio over the web remux - #2698

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
Rhainland:fix/remux-ts-aac-adtstoasc
Oct 21, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
Rhainland:fix/remux-ts-aac-adtstoasc

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1252 C3 and C6 (both not run yet)

MPEG-TS files with AAC audio do not play in the web app when the server remuxes them. The player flashes, then shows the "You've finished" screen. Stream captures such as Twitch VODs are the common case. Mobile clients that direct-play the file are unaffected. This change makes the remux convert the audio framing so these files play.

The progressive remux copies streams into fragmented MP4 with -movflags frag_keyframe+delay_moov+default_base_moof. MPEG-TS carries AAC as ADTS, which MP4 cannot hold. FFmpeg normally inserts aac_adtstoasc on its own, but not under delay_moov. The muxer stops on the first audio packet:

[mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it

The response is HTTP 200 with almost nothing in it: about 300 KB from the start of the file and 1.3 KB after a resume. The video element reports a duration of 0 or 0.18 s and ends. FFmpeg 8.0.1 and jellyfin-ffmpeg 8.1.3, the version the Docker image ships, both fail this way. The progressive remux discards FFmpeg's stderr, so nothing shows up in the server log.

Approach

The remux adds -bsf:a aac_adtstoasc when it copies an AAC track. The filter passes AAC that is already raw (MKV, MP4) through unchanged, but FFmpeg refuses to open the output if it is applied to any other codec. So it keys on the codec of the copied track, not on the container.

Every remux executor needs that codec. The integrated stream handler reads it from the session's planned audio codec, which for a copy is the source track's codec. Proxies and transcode nodes only see the stream token, so a new claim, cac (CopyAudioCodec), carries it on the recipe card and in the token. It is set only when audio is copied. The existing tca claim could not be reused because Jellycompat proxy tokens set it to aac for every remux, including AC-3 and E-AC-3 copies, and older servers mint those tokens too. A token without cac keeps the plain copy, so mixed-version fleets behave as before.

Jellycompat's local remux and its proxy tokens take the codec from the selected source track, using the same track index the remux maps.

This affects the native web app, Jellycompat clients whose remux uses the same path, and proxy or transcode-node deployments. Native clients need no change.

Validation

  • Web app, headless Chrome against a local server: an MPEG-TS file (H.264 1080p60, AAC stereo) chosen at Original quality plays from the start and after a resume on this branch. On main it shows the finished screen in both cases. The reporter's sample file behaves the same.
  • New FFmpeg-backed test runs the remux arguments on generated MPEG-TS (start and seek) and MKV files. It fails on main with the error above and passes here.
  • Unit tests cover when the filter is added (copied AAC only, not E-AC-3, LATM, transcoded audio, or an empty codec), the native token claim and its recipe-card round trip, and the Jellycompat proxy token for copied AC-3, copied AAC, and transcoded audio.
  • go build, go vet ./..., gofmt, make lint-changed, make lint-router-recovery, and the Go-side verify targets (local paths, route inventory, playback fixtures, apiv2 OpenAPI, contract, and fixtures, v1 route freeze, bidi, size ratchet, case collisions) pass.
  • make test-go: the touched packages pass. Local failures in DB-backed tests in other packages also fail on main with the same local database. CI is the reference for those.
  • Web checks were not run. The change has no web code. make verify-settings-bindings-all passed its Go half and could not run its web half without node_modules.

Evidence

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

Surface and build: web app, desktop, synthetic MPEG-TS test file at Original quality. Before is main at 365e3d4, after is this branch. Before: the player ends at once and shows the finished screen. After: the remux streams and plays.

Risks

  • A remux that copies a track whose recorded codec is aac but whose stream is something else would now fail at startup. The codec comes from the scan's probe of the same track the remux maps, so this needs a file that changed after its last scan.
  • Old tokens and old proxies or transcode nodes keep the previous behavior, so MPEG-TS AAC remuxes served by a proxy or node stay broken until both the server and that node run this build.
  • The same delay_moov behavior could affect other ADTS sources, such as raw .aac files. Those go through the same filter when their codec is AAC.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (Claude Agent SDK) in T3 Code
  • Tool(s): Claude Code; Codex CLI for one of two independent reviews
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two independent reviews of the full branch diff, one by claude-opus-5-5 and one by gpt-6.1-sol, at medium effort. Both found that Jellycompat proxy tokens set the target audio codec to aac for remuxes that copy non-AAC audio, which would have made a proxy fail AC-3 and E-AC-3 copies. The fix moved the codec to the dedicated cac claim. A second round on the revised diff by both reviewers found nothing.

Note

Apply AAC ADTS-to-ASC bitstream filter for copied AAC audio in remuxes

  • Fixes playback of MPEG-TS files with copied AAC audio by adding the AAC ADTS-to-ASC bitstream filter in buildRemuxArgsWithLeadingPictureDropV3 when the copied source codec is AAC, as documented in playback-protocol-v3.md
  • Carries the source audio codec through the full pipeline: a new CopyAudioCodec field on RecipeCard and RemuxServeOptions, a cac claim in token.go, and population at each call site in the API, proxy, transcode-node, and jellycompat handlers
  • Transcoded audio and non-AAC codecs get no audio filter; older tokens without the claim decode to an empty codec and keep plain-copy behavior
  • Adds unit tests for argument generation and proxy claims, plus an optional FFmpeg integration test covering MPEG-TS and Matroska AAC remuxes into fragmented MP4
  • Risk: AAC detection depends on the CopyAudioCodec value being present and correctly cased/trimmed; older executors ignore it and HLS playback of copied AAC remains a known limitation

Macroscope summarized 8650449.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 19, 2026
@silo-kody

silo-kody Bot commented Oct 19, 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 ❌

@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: P2 Limited scope, workaround exists, or polish labels Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
  • internal/playback/remux.go: the Evidence section identifies desktop web only. The linked page should show before/after playback from the start and after resume on desktop and phone-width web; include a short recording of that playback flow.
  • internal/jellycompat/streams.go and internal/jellycompat/handlers_playback.go: the linked evidence should also show before/after playback from an affected Jellycompat client.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 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
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ff8fff51-9a6c-4db2-ab4b-28de22c7c58e
📥 Commits

Reviewing files that changed from the base of the PR and between b5fc184 and 8650449.

📒 Files selected for processing: 14
  • docs/architecture/playback-protocol-v3.md
  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_copy_audio_codec_test.go
  • internal/api/handlers/stream.go
  • internal/jellycompat/handlers_playback.go
  • internal/jellycompat/streams.go
  • internal/jellycompat/streams_test.go
  • internal/playback/recipecard.go
  • internal/playback/remux.go
  • internal/playback/remux_aac_test.go
  • internal/playback/remux_leading_picture_test.go
  • internal/proxy/server.go
  • internal/streamtoken/token.go
  • internal/transcodenode/server.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 99006733-040c-4cf0-9a6b-ef2c80f1ed5e
📥 Commits

Reviewing files that changed from the base of the PR and between 76262fa and b5fc184.

📒 Files selected for processing: 1
  • docs/architecture/playback-protocol-v3.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The change carries copied-audio codec metadata through playback claims and remux serving. Remux argument construction adds aac_adtstoasc for copied AAC. Tests cover codec selection and remux output.

Changes: Copied Audio Remux

Layer / File(s) Summary
Capture copied-audio codec metadata
internal/streamtoken/token.go, internal/playback/recipecard.go, internal/api/handlers/playback.go, internal/api/handlers/playback_copy_audio_codec_test.go, internal/jellycompat/handlers_playback.go, internal/jellycompat/streams_test.go
Recipe cards and proxy redirect claims record the codec for copied audio. Claim conversion preserves the value. Tests check copied and transcoded cases.
Pass codec metadata to remux serving
internal/playback/remux.go, internal/api/handlers/stream.go, internal/jellycompat/streams.go, internal/proxy/server.go, internal/transcodenode/server.go
Remux options include the copied-audio codec. API, compatibility, proxy, and transcoding-node paths pass codec metadata into remux serving.
Select AAC remux filter
internal/playback/remux.go, internal/playback/remux_aac_test.go, internal/playback/remux_leading_picture_test.go, docs/architecture/playback-protocol-v3.md
Remux argument construction adds aac_adtstoasc for copied AAC. Tests cover codec selection and remux output. The protocol documentation records fallback behavior and excludes HLS copy paths.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant PlaybackHandler
  participant RecipeCard
  participant JellycompatHandler
  participant StreamTokenClaims
  participant ProxyServer
  participant TranscodeNode
  participant RemuxServeOptions
  participant RemuxArgBuilder
  PlaybackHandler->>RecipeCard: set copied target audio codec
  RecipeCard->>StreamTokenClaims: include CopyAudioCodec
  JellycompatHandler->>StreamTokenClaims: include selected source codec
  alt proxy remux
    StreamTokenClaims->>ProxyServer: provide CopyAudioCodec
    ProxyServer->>RemuxServeOptions: set CopyAudioCodec
  else progressive remux
    StreamTokenClaims->>TranscodeNode: provide CopyAudioCodec
    TranscodeNode->>RemuxServeOptions: set CopyAudioCodec
  end
  RemuxServeOptions->>RemuxArgBuilder: pass copied source codec
  RemuxArgBuilder->>RemuxArgBuilder: add aac_adtstoasc for copied AAC
Loading

Possibly related issues

  • Silo-Server/silo-server#2840 — The issue describes the same MPEG-TS AAC ADTS-to-fMP4 failure; this change fixes progressive remux handling while documenting that HLS copy paths remain excluded.

Suggested reviewers: quick104, blurbery

Merge Risk: ⚪ Minimal · up to b5fc1

The documentation change introduces no evidenced production or deployment risk and is mergeable with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 13 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the playback fix for MPEG-TS files with AAC audio during web remuxing.
Description check Passed The description directly explains the MPEG-TS AAC playback problem, the remux filter fix, codec propagation, testing, risks, and scope.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 57.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 13 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch fix/remux-ts-aac-adtstoasc
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 76262fa. The fix is sound. On this host's FFmpeg 6.1.1, the remux arguments built on main fail on an MPEG-TS file with AAC audio ("Malformed AAC bitstream" after about 6 KB). The arguments from this branch stream the whole file. I found one gap, in the docs, and I'm fixing it in a commit on this branch, so there's no need to change it yourself.

Comment thread internal/streamtoken/token.go Resolved
@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: b5fc184 (76262fa plus one docs commit from this review)

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

The fix is sound. On this host's FFmpeg 6.1.1, the remux arguments built on main fail on an MPEG-TS H.264/AAC file with "Malformed AAC bitstream" after about 6 KB of output. The arguments from this branch stream the whole file. A second reviewer reproduced the same result on jellyfin-ffmpeg 8.1.3.

Addressed

  • The new cac claim and its plain-copy fallback on older tokens and executors had no protocol doc, unlike the comparable rlpd claim. Added a paragraph to docs/architecture/playback-protocol-v3.md in b5fc184.

Checked and found correct

  • When audio is copied, session.TargetAudioCodec is the source track's codec on every progressive remux planner path. It becomes aac only on the branches that transcode. The HLS remux result uses copy, which never adds the filter.
  • Jellycompat's compatSourceAudioCodec uses the audio-relative index that the remux maps as 0:a:N.
  • cac survives every hop: token and recipe card in both directions, proxy grants, the node recipe store, and session restore. Jellycompat proxy tokens that set tca=aac for copied AC-3 can't reach the integrated /stream remux, because the egress guards reject them.
  • The remux maps one audio stream, so -bsf:a applies only to the track whose codec was recorded.

Tests

The new tests call the changed function signature, so they don't build on the base and can't show a failure there. The base failure above came from running the arguments each side builds. The new and changed tests pass on the head.

Left for maintainers

  • Pre-existing, not caused by this PR: the HLS copy path (buildFFmpegArgs with fMP4 segments) fails the same way on MPEG-TS AAC. Filed as [bug] HLS copy remux of MPEG-TS with AAC audio fails after the first segment #2840. Its fix should reuse this PR's cac field, so it should follow this PR.
  • Low risk, already in the PR's Risks: the filter depends on the scanned codec. A catalog row whose selected track has no codec name falls back to the file's first-track codec. That only happens when ffprobe can't identify the codec, and a plain copy of such a track is likely to fail anyway.

Validated features

No passed case on the v1.0 board reaches this code. #1252 C3 (resume across direct, remux and transcode) and C6 (mixed-format fixtures) exercise the remux path and haven't run yet. They should run on a build that includes this change. The PR body's Validation tasks: line names the right cases.

User manual: no setting, default, label, or documented behavior changes, so the manual is unaffected.

Apple/Android: server-only fix. Native clients that direct-play are unaffected and need no change.

Fit: a playback correctness fix in the executor that owns the FFmpeg arguments. It keys on the copied codec rather than the container, which is the narrowest correct condition.

Readiness: the base failure and the head fix were both reproduced by running the real argument builder. CI passed on 76262fa. The only new commit is docs.

Review method: three finder passes plus a validation-impact check and a verifier (Claude, claude-opus-5-5), and one cross-provider round (Codex, gpt-6.1-sol). The cross-provider round found no regressions and independently found the HLS gap.

@silo-kody

silo-kody Bot commented Oct 21, 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 ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

Rhainland and others added 3 commits October 21, 2026 12:08
A progressive remux of an MPEG-TS source with AAC audio failed on the
first audio packet. MPEG-TS carries AAC as ADTS, which MP4 cannot hold,
and under delay_moov FFmpeg does not insert aac_adtstoasc on its own. The
muxer stopped with "Malformed AAC bitstream", the browser received little
more than the file header, and the web player went straight to the
finished screen.

Add -bsf:a aac_adtstoasc when the remux copies an AAC track. The filter
passes raw AAC from MKV and MP4 through unchanged but rejects other
codecs, so it keys on the planned audio codec, which for a copy is the
source track's codec. The native stream handler, transcode nodes and
proxies read it from the session or stream token; Jellycompat reads the
selected track.
Jellycompat proxy tokens set the target audio codec to aac for every
remux, including ones that copy AC-3 or E-AC-3, so a proxy reading that
claim would add aac_adtstoasc to a non-AAC track and fail the stream.
Tokens minted by older servers carry the same value, so a new proxy
cannot trust it during a rolling upgrade.

Carry the codec of the copied track in a new cac claim instead. Native
remux tokens and Jellycompat proxy tokens set it only when audio is
copied; a token without it keeps the plain copy.
@Quick104
Quick104 force-pushed the fix/remux-ts-aac-adtstoasc branch from b5fc184 to 8650449 Compare October 21, 2026 16:11
@silo-kody

silo-kody Bot commented Oct 21, 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 ❌

@Quick104
Quick104 merged commit 4da1cd2 into Silo-Server:main Oct 21, 2026
16 checks passed
Quick104 added a commit that referenced this pull request Nov 9, 2026
* fix(playback): convert copied ADTS AAC for fMP4 HLS segments

An HLS copy remux of an MPEG-TS source with AAC audio stopped after
init.mp4: the HLS muxer's fMP4 segments can't hold ADTS framing and FFmpeg
does not insert aac_adtstoasc there on its own.

TranscodeOpts now carries the copied source audio codec (CopyAudioCodec),
and buildFFmpegArgs adds -bsf:a aac_adtstoasc when a copied AAC track goes
into fMP4 segments. MPEG-TS segments and other codecs are unchanged. The
filter check is shared with the progressive remux fix from #2698.

The codec reaches every executor: the v3 integrated and remote-node starts,
the recipe card and stream token (the existing cac claim), transcode
rehoming, and the jellycompat integrated, node and proxy paths. An older
node or token without the codec keeps the plain copy.

Closes #2840

* refactor(playback): reuse TranscodesAudio for the copied HLS codec

Drop a handler test that only checked its own fixture; the argument table,
recipe card round trip and jellycompat token rows cover the behaviour.

* fix(transcodenode): refuse nodes that ignore the copied audio codec

A node from before this change ignores copy_audio_codec, so it copies AAC
into fMP4 segments without aac_adtstoasc and the stream stops after the
first segment. Nodes now return the copied codec in their start receipt,
and the API rejects a node that doesn't confirm it, as a retryable start
failure like the other recipe receipts. The check applies only when a copied
AAC track goes into fMP4 segments, so older nodes still take MPEG-TS
sessions and other copied codecs.

The rule for when the filter applies is now one function,
playback.HLSCopiesAACIntoFMP4, shared by the argument builder and the check.

* fix(apiv2): regenerate OpenAPI for the copied audio codec receipt

The transcode node start request and response schemas in the v2 contract
gain the optional copy_audio_codec property. The node API doc describes
the field and when the API requires the node to confirm it.

* fix(playback): match copied audio in any case when adding aac_adtstoasc

appendAudioArgs copies audio for "COPY" or " copy " too, so the fMP4 rule
now uses TranscodesAudio rather than an exact "copy" match.

* docs(transcodenode): say which paths check the copied audio codec receipt

The receipt is checked only on POST /transcode/start. Jellycompat moves and
node-side reconstruction skip it, and the check also refuses older nodes for
MKV and MP4 AAC copies, so state that transcode nodes update first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Quick104 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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: P2 Limited scope, workaround exists, or polish 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.

2 participants