Skip to content

Take a source's subtitles from their own input (fixes #266) - #291

Merged
StuartCameronCode merged 2 commits into
mainfrom
stuart/142-investigate-github-issue-266
Nov 28, 2026
Merged

StuartCameronCode merged 2 commits into
mainfrom
stuart/142-investigate-github-issue-266

Conversation

@StuartCameronCode

Copy link
Copy Markdown
Owner

Fixes #266.

Problem

When a source had subtitles, an untrimmed Passthrough encode into MKV or MP4 stored its sound far ahead of its picture in the file: about 38 s in the reported file. Players then dropped the sound in stretches, and a remux fixed it.

The cause: the subtitles were mapped from the same ffmpeg input as the sound. Between cues, the sparse subtitle stream is the stream FFmpeg's scheduler waits for, so the source's sound ran ahead of the picture vspipe was still making. Once the muxer's queue spanned max_interleave_delta (10 s), it wrote the sound out ahead of the picture. Trimmed encodes were never affected, because -shortest's sync queue holds the streams together.

Fix

  • pipeline_executor::subtitle_mapping is now the one place that decides the subtitle mapping. When the probe finds a subtitle stream, the encode takes the subtitles from a second -i of the source.
  • That input gets the same seek as input 1 and is added after every other input, so inputs 0–3 keep their numbers.
  • A source with no subtitles adds no input.
  • If the probe fails, MKV keeps the old 1:s? copy and MP4/MOV maps none, as before.
  • -max_interleave_delta 0 was rejected: it fixes the layout but buffers the sound until the next cue (265 vs 83 MB for a 7.1 PCM minute).

Tests

  • 7 new Rust unit tests. cargo test --lib (696) and filter_integration_test (253) pass.
  • New heavy test integration_subtitle_interleave_test.dart, with the fixture sparse_subs.mkv (cues 34 s apart) and its generator. Sound ahead of picture in file order: before the fix, MKV 22.7 s and MP4 23.3 s, and the test fails. After the fix, 0.10 s. Both cues keep their times, including in a trimmed encode.
  • Measured on macOS arm64 only. Only the file layout is measured; no player was tested.

Docs

Report docs/reports/issue-266-subtitle-interleave, plus an ENGINEERING_NOTES entry, a row in the reports index and a CLAUDE.md rule.

🤖 Generated with Claude Code

StuartCameronCode and others added 2 commits November 28, 2026 22:27
An untrimmed Passthrough of a source with subtitles stored its sound up to
~38 s ahead of its picture in the file (MKV and MP4), and players dropped
the sound in stretches; re-muxing fixed it. The subtitles shared input 1
with the sound: between cues the sparse subtitle stream is the one FFmpeg's
scheduler waits for, so the source's sound ran ahead of the picture vspipe
was still making and the muxer flushed it past max_interleave_delta.

The subtitles now come from a second -i of the source with input 1's own
seek, last of the inputs (subtitle_mapping), added only when the probe
finds a subtitle stream; a failed probe keeps Matroska's old 1:s?. Through
the worker: 22.7 s (MKV) / 23.3 s (MP4) ahead -> 0.10 s. Trimmed encodes
were never affected (-shortest's sync queue).

Report: docs/reports/issue-266-subtitle-interleave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@StuartCameronCode
StuartCameronCode force-pushed the stuart/142-investigate-github-issue-266 branch from 2ad9b5b to 372f69b Compare November 28, 2026 11:27
@StuartCameronCode
StuartCameronCode merged commit 47a71a9 into main Nov 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On Mac: Audio handling seems broken

1 participant