115 Commits
Author SHA1 Message Date
Scott GarrettandClaude Code 57772086a5 Convert Matroska PGS tracks to VobSub and name flagged tracks SDH
A PGS track inside an MKV can now be muxed as a real subp track: the
muxer's bitmap-converter branch recognizes a PGS source with a VobSub
target (new MP42ConversionSettings subtitlesVobSubConversion) and uses
the new MP42PgsToVobSubConverter instead of MP42BitmapSubConverter.

The converter rebuilds the PGS elementary stream from the source
container up-front, because mkvmerge stores each PGS segment with its
13-byte "PG" envelope removed (type + 2-byte length + payload,
zlib-compressed) — a plain concatenation of demuxed blocks is not a
.sup. Each block is walked segment-by-segment and the envelope is
restored as PG + 90 kHz pts (from the block's nanosecond timestamp) +
four zero bytes + type + length, byte-identical to what mkvextract
writes; blocks that already carry envelopes pass through verbatim. The
rebuilt temp .sup then rides the existing MP42VobSubImporter wholesale
for palette, DVD geometry, and raw-SPU samples, which replay through
copyEncodedSample while the live muxing stream is discarded.

Subtitle type recognition now names any flagged track "SDH" (hearing
impaired, commentary, forced, lyrics, closed captions) instead of a
per-type name, and MKV container tracks get the same treatment on the
conversion path: the TrackEntry Name runs through the recognizer, or
the MKV's own filename when there is no Name element. tagsOnly mode
stays verbatim — that model is the tag writer's diff baseline.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 20:00:08 -05:00
Scott GarrettandClaude Code e8231dea59 Mirror the file's chapter atoms verbatim in tagsOnly mode
The importer's MP4 normalizations (force the first chapter start to 0,
drop non-first zero-timestamp chapters) belong to the conversion path
only. In tagsOnly mode the model is the baseline a later Chapters
rewrite rebuilds from, so those quirks silently corrupted real files:
mkvmerge happily writes a first chapter starting after 0 and atoms tied
at 0, and the first chapter edit would then shift or delete them. The
remuxer's strictly-ascending clamp already shifts tied starts by +1 ms
at write time, so nothing is lost by keeping every atom at read time.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-26 19:14:44 -05:00
Scott GarrettandClaude Code 10dcee30a6 Round trip the chapter language between model and Matroska
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>
2026-11-26 18:17:22 -05:00
Scott GarrettandClaude Code 0cf79eca1c Rebuild Matroska chapters on remux and recompute Info Duration
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>
2026-11-26 12:54:43 -05:00
Scott GarrettandClaude Code 1040f47542 Add Matroska tagging and track-removal support
- 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>
2026-11-25 19:48:09 -05:00
Damiano Galassi 57236970a3 Add two methods two return the supported UTIs 2026-09-22 18:50:05 +02:00
Damiano Galassi 2b36c035de Add a metadata overwrite option 2026-09-11 09:51:30 +02:00
Damiano Galassi 740fd075b3 Improve MKV LanguageBCP47 conversion 2026-08-27 16:51:13 +02:00
Damiano Galassi 3b5e78211d Read Matroska LanguageBCP47 field 2025-09-15 14:24:56 +02:00
Damiano Galassi f104a7c69a Make a MP42Chapter method clearer 2025-07-25 17:35:42 +02:00
Damiano Galassi 47aadecfff Improve metadata conversion from MKV 2025-03-13 16:54:57 +01:00
Damiano Galassi a3c2aa6968 Add VVC enums. 2024-06-25 12:10:48 +02:00
Damiano Galassi 10b9a7dae3 Update Matroska parser. 2022-02-24 10:16:59 +01:00
Damiano Galassi 027cb1f6ae Update copyright year. 2022-01-02 09:31:49 +01:00
Damiano Galassi deb2e3b0fe Fix a memory leak. 2021-12-09 12:02:52 +01:00
Damiano Galassi 83f7b29e13 Add support for hvcE and avcE boxes. 2021-12-08 11:56:28 +01:00
Damiano Galassi bfdb8964ac Read Dolby Vision metadata from mkv. 2021-12-07 21:30:25 +01:00
Damiano Galassi eb410ed7a4 Passthru the HDR10 metadata. 2021-05-28 14:56:10 +02:00
Damiano Galassi 3e2a9f4cc7 Improve color range passthru. 2021-05-22 10:22:48 +02:00
Damiano Galassi 0cf26cf3df Fix a regression in the matroska parser, do not fixup cue start times. 2021-05-22 10:11:53 +02:00
Damiano Galassi 799fdcc642 Update copyright year. 2021-02-02 10:55:04 +01:00
Damiano Galassi fff9f74230 Actually fix atmos. 2020-10-15 12:45:22 +02:00
Damiano Galassi 734ca33e2b Fix Atmos in MKV. 2020-10-15 09:24:30 +02:00
Damiano Galassi c8ff6a8a15 Fix some leaks. 2020-09-23 21:18:24 +02:00
Damiano Galassi bff7fa9ebc Read forced flaga in mkv. 2020-09-22 12:18:51 +02:00
Damiano Galassi b2394c7c3e Update copyright. 2020-09-22 11:38:15 +02:00
Damiano Galassi 86de20e308 Remove some superfluos MP42FileImporter methods. 2020-09-21 19:27:11 +02:00
Damiano Galassi df7555df8f Cosmetics. 2020-09-21 14:13:01 +02:00
Damiano Galassi 8235bfab97 Update matroska parser. 2020-09-21 13:09:46 +02:00
Damiano Galassi 0e421a6eef Enable and fixes more warnings. 2020-09-19 14:39:02 +02:00
Damiano Galassi 9ed0e2d992 Fix a infinite loop in mkv demuxer end routine. 2020-09-14 09:24:24 +02:00
Damiano Galassi f63e23f878 Adopt objc direct attributes where possible. 2020-07-01 19:48:11 +02:00
Damiano Galassi 9d7645ab3d Set the timescale in the samples. 2020-03-10 15:55:09 +01:00
Damiano Galassi ce4ee8e0f1 Reorganize headers. 2020-02-08 13:53:32 +01:00
Damiano Galassi 97e9323e6e Make sure to reset the seek point in mkv. 2019-03-07 15:40:59 +01:00
Damiano Galassi 3ccde22cd7 Improve eac3+atmos parser. 2019-01-05 10:23:58 +01:00
Damiano Galassi 3f0c6c85b6 Add support for old SSA in mkv and mov. 2018-10-15 18:56:59 +02:00
Damiano Galassi 0e19dccbdf Fixes a crash in the eac3 header parser, add some preliminary work to read atmos in AVFoundation. 2018-09-05 15:26:31 +02:00
Damiano Galassi 54f1e2b2d4 Improve the atmos parser. Patch by Priit Varik. 2018-08-12 11:39:48 +02:00
Damiano Galassi 4d969e91c0 Add some code to detect Atmos in EAC3, thanks to Priit Varik. 2018-08-07 14:22:51 +02:00
Damiano Galassi cd35f787e3 Read the WAVEFORMATEX info in mkv. 2017-10-28 08:38:50 +02:00
Damiano Galassi f0f7a0704b Add __autoreleasing to NSError 2017-10-09 12:34:55 +02:00
Damiano Galassi 8d8aaa0be6 Rename SBSubSerializer to MP42SubSerializer, remove some casts, fix SSA timestamp parsing. 2017-10-03 08:52:48 +02:00
Damiano Galassi 0908670715 Add a new SSA -> Text converter. 2017-10-02 19:10:14 +02:00
Damiano Galassi 1f65513c84 Init the FIFOs only when needed. 2017-10-01 16:35:39 +02:00
Damiano Galassi 972ead6f0b Convert MP42FileImporter to ARC, and clean up some imports. 2017-09-30 11:11:31 +02:00
Damiano Galassi 7a8cae556e Fix headers. 2017-09-29 22:10:09 +02:00
Damiano Galassi 646585be6f Port more classes to arc. 2017-09-29 18:10:59 +02:00
Damiano Galassi ea5fc13f87 Move some files to ARC. 2017-09-29 14:00:38 +02:00
Damiano Galassi 2991bb2f9b Do not use a implicit codec delay for now. 2017-09-19 12:35:17 +02:00