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>