ChapterDisplay/ChapterLanguage (0x437C) was read by the vendored parser
but never surfaced, and the remuxer's chapter builder never wrote it, so
any non-English chapter language silently degraded to the spec default
"eng" the first time Subler rewrote the Chapters element.
The importer now adopts the first ChapterDisplay language as the model
track's language (the model is one-language-per-track; MKV allows
per-atom but every common tool stamps one value). The remuxer stamps the
track language back into every atom as ISO-639-2/B, omitting it when nil
or eng so language-less files keep byte-identical rewrites. Unknown
extended tags map to "und" via MP42Languages and are written explicitly,
which is truthful rather than silently defaulting.
Co-Authored-By: Claude Code <noreply@anthropic.com>
MP42MkvRemuxer gains replacementChapters: when set, the Chapters element
is rebuilt from the model track instead of copied verbatim (chapterCount
0 removes the element and its SeekHead entry). Chapter timecodes are
written as absolute nanoseconds — libmatroska/mkvtoolnix/ffmpeg all
treat them as ns regardless of TimecodeScale, confirmed by hex-dumping
a mkvmerge-written file and reading it back with mkvinfo and ffprobe.
ChapterAtom is 0xB6 (0xB0 is PixelWidth), and mandatory EditionUID/
ChapterUID are derived deterministically from the content because
ffmpeg silently skips atoms without a ChapterUID. Starts are sorted
ascending with ties clamped to previous+1ms (mkvmerge rejects
non-ascending), empty titles get the importer's "Chapter N" fallback,
and the last atom's end rides the track duration only when known.
An existing Info Duration is recomputed as the greatest written block
start+1ms: the Info payload is rewritten with a fixed 8-byte double
slot patched after the clusters stream past, converted to TimecodeScale
units. Added blocks measure start+1 like source blocks so a second
no-op remux stays byte-identical (including BlockDuration broke
idempotence). Files without a source Duration keep having none.
The importer's chapter /1e6 needed no change (Start is already ns); a
comment now records that so it doesn't get "fixed" to scale-based math.
Co-Authored-By: Claude Code <noreply@anthropic.com>
MP42MkvRemuxer previously refused any track present in currentTracks
but not in sourceTracks; it now accepts added MP42SubtitleTracks whose
URL extension is srt/ssa/ass and muxes them into the rebuilt file as
S_TEXT/UTF8. The extension gate mirrors the app-side
DocumentWindowController.matroskaSubtitleExtensions list — the two
must stay in sync.
- Each added track gets an appended TrackEntry: TrackNumber = max of
all entries + 1 (refuse past 0x3FFF, the 2-byte unmarked-vint
limit), TrackType 17, FlagEnabled 1, FlagLacing 0, CodecID
S_TEXT/UTF8, ISO 0x22B59C + IETF 0x22B59D language, Name only when
it differs from the codec default.
- The model never holds subtitle text, so lines are re-parsed from
track.URL at save time: SRT via LoadSRTFromURL + serializer drain,
SSA/ASS via MP42SSAParser/MP42SSAConverter (styling stripped, same
lossy path the tx3g muxer takes). Zero parsed lines refuses.
- Blocks are written as BlockGroup{Block(unmarked-vint track number,
int16 BE relative timecode, UTF-8 text), BlockDuration(>=1 ms)}.
The BlockGroup wrapper is mandatory: a bare Block as a direct
Cluster child is silently ignored by libebml readers even though
ffmpeg tolerates it.
- Lines are assigned to the last existing Cluster whose Timecode is
<= the line's start time (inheriting missing cluster timecodes,
negative relative timecodes are legal); lines whose relative
timecode would exceed +32767 flush as synthesized Clusters right
after that cluster. Original clusters are copied verbatim and
never split.
- Added tracks join the existing per-track CueTrackPositions
bookkeeping, and the drop-all-remaining guard still fires before
additions, so drop-all-plus-add stays refused.
Adds TrackType/FlagLacing/CodecID/BlockDuration element ids to
MP42MatroskaTagMapping.h.
Co-Authored-By: Claude Code <noreply@anthropic.com>
Three latent bugs combined into a crash or silently-empty subtitle
import (surfaced by feeding conv.ass to the Matroska subtitle-add
path):
- parseHeader: used NSScanner scanUpToString: for the section
markers; a failed scanUpToString: returns YES and advances the
scan location to the end of the string, so a file lacking
"[V4+ Styles]" left the scanner exhausted and the [Events]
Format: line was never parsed. Locate the markers with
rangeOfString: instead.
- The Format line is split on commas but names are separated with
", " in the wild; the leading spaces made every field name fail
its isEqualToString: in MP42SSALine, so no line ever got
text/timestamps. Split on comma and trim whitespace.
- MP42SSALine's value loop looped to `count - 1` on an NSUInteger;
with an empty format array that underflows and appends forever
until the array traps. Guard count == 0.
Co-Authored-By: Claude Code <noreply@anthropic.com>
- MP42Ebml: EBML vint/ID primitives, flat Segment scanner, block track
number decoding, and element builders shared by all Matroska writers.
- MP42MkvImporter / MP42FileImporter: tagsOnly mode that mirrors the
file's own track flags instead of the MP4 conversion heuristics.
- MP42MatroskaTagMapping: read/write SimpleTag maps shared by importer
and writer, including community names for MP4-only movie fields.
- MP42MkvTagWriter: mkvpropedit-style in-place rewrite of Tags, cover
art, and per-track name/language/enabled/forced fields with a
size+mtime staleness guard; an untouched save is a byte-for-byte
no-op.
- MP42MkvRemuxer: stream-copy rebuild that drops the blocks of removed
tracks (TrackNumbers keep their gaps; block bytes are never
rewritten), regenerates SeekHead and Cues, carries metadata edits in
the same pass, and writes via temp file + atomic rename.
- MP42MkvTagWriter+Internal.h exposes the tag writer's scanning and
payload builders so the remuxer reuses them unchanged.
Verified with the external matrix harness: 241 assertions green across
layout fixtures (ffmpeg/mkvmerge/streamed), removal scenarios, cue
parity, and idempotency.
Co-Authored-By: Claude Code <noreply@anthropic.com>