Write added subtitle tracks during Matroska remux

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>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-26 11:53:17 -05:00
1 parent e42855867d
commit 8ba3f25a2c
3 files changed
+732 -35

No files matched your search

+5
View File
@@ -47,12 +47,17 @@ enum {
MP42MkvElementTrackLanguageIETF = 0x22B59D, // BCP-47 string, e.g. "en-US"
MP42MkvElementTrackFlagEnabled = 0xB9, // unsigned integer, default 1
MP42MkvElementTrackFlagForced = 0x55AA, // unsigned integer, default 0
MP42MkvElementTrackType = 0x83, // unsigned integer: 1 video, 2 audio, 17 subtitle
MP42MkvElementFlagLacing = 0x9C, // unsigned integer, default 1 (mkvmerge writes 0 for subtitles)
MP42MkvElementCodecID = 0x86, // ASCII string, e.g. "S_TEXT/UTF8"
MP42MkvElementChapters = 0x1043A770,
MP42MkvElementCluster = 0x1F43B675,
MP42MkvElementClusterTimeCode = 0xE7, // unsigned integer, cluster child
MP42MkvElementSimpleBlock = 0xA3, // cluster child; payload starts with the track-number vint
MP42MkvElementBlockGroup = 0xA0, // cluster child; the track comes from its Block child
MP42MkvElementBlock = 0xA1, // BlockGroup child (inside SimpleBlock it is 0xA3)
MP42MkvElementBlockDuration = 0x9B, // unsigned integer, BlockGroup child: display duration
// in TrackTimecodeScale units (default scale = 1 ms)
MP42MkvElementAttachments = 0x1941A469,
MP42MkvElementAttachedFile = 0x61A7,