Commit Graph
15 Commits
Author SHA1 Message Date
Scott GarrettandClaude Code 72e879e316 Add a slim sup2vob CLI built from the vendored Sup2Vob sources
The extractsubs helper shipped in the Subler app bundle needs sup2vob
on PATH, so the converter gets a CLI build beside the framework target.
Slim by design: this directory holds only upstream's main.swift and a
Makefile that compiles it against ../MP42/Sup2Vob/ — the exact files the
framework builds, so an upstream merge updates app and CLI in one pass
and the two can never silently disagree. The CLI's --full output is the
byte-identical oracle for the framework converter (verified: same
sub/idx bytes for a full movie track).

main.swift is upstream verbatim except for the documented globals seam:
the CLI's debugFrames/fullFramePassthrough declarations belong to the
vendored Convert.swift, so main.swift drops its re-declaration and only
assigns them (--debug/--full). The framework facade
(MP42SupConverter.swift) is deliberately not part of the CLI build.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 23:06:27 -05:00
Scott GarrettandClaude Code 837aa1c098 Keep the PGS source resolution through the sup2vob conversion
VobSub conversions of PGS material were downscaled to the 720x480/576
DVD frame — a 1080p source came out of the mux at one quarter of its
authored size. The framework's sup2vob façade now always runs the
upstream CLI's `--full` mode: fullFramePassthrough keeps every frame's
object geometry verbatim, and the idx size line (which the VobSub
importer carries into track.width/height and the muxer writes into the
subpic track) is the PGS's own PCS canvas, e.g. 1920x1080. The
frame-rate-derived DVD frame stays as fallback for streams that define
no usable canvas. The conversion output is byte-identical to running
`sup2vob --full` on the same .sup.

The vendored upstream sources stay untouched apart from one comment —
the passthrough is enabled in the adaptation layer, same as the CLI
does with its flag. This applies to both PGS paths, which share the
conversion: .sup drag-import and PGS-from-MKV via
MP42PgsToVobSubConverter.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 21:13:57 -05:00
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 e02f60b5f6 Import BLU-RAY PGS .sup files via vendored sup2vob
MP42VobSubImporter now claims "sup" alongside "idx": the file is converted up-front to a temp .idx/.sub pair, so the existing VobSub machinery (muxable subp passthrough, tx3g conversion, frame size from the idx size: line) carries everything downstream. The pair lives in a private temp directory until the importer's dealloc; tracks retain the importer through export, so demux can always reopen it.

The converter is sup2vob (https://git.technomancer.com/Scott-Files/sup2vob) vendored under MP42/Sup2Vob, kept identical to upstream apart from provenance headers; the CLI-only globals and main.swift are adapted in Convert.swift, and MP42SupConverter is the new @objc facade the importer calls over the MP42-Shared-Swift.h shim. Vendored output was verified byte-for-byte identical to the upstream CLI, and saved MP4s play back as dvd_subtitle tracks.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 18:18:16 -05:00
Scott GarrettandClaude Code 30dd96ff79 Recognize subtitle language and type tokens in filenames
getFilenameLanguage now tokenizes the name and scans right-to-left the way mkvmerge's own heuristics do, so a language code survives behind a trailing flag token ("...eng.hearing_impaired.srt" was read as "und"). Three-char tokens try ISO 639-2/T and the library's B codes; the dash stays out of the separator set so region subtags ("pt-BR") are not split into a bogus ISO 639-1 hit.

getFilenameSubtitlesTrackName maps community type tokens (sdh / hearing_impaired / deaf, cc / closed caption, forced, commentary, lyrics) to a bare conventional track name ("SDH"); the language rides its own element. MP4 has no SDH flag and the name-keyword pass in MP42File organizeMediaCharacteristicsForMediaType: turns these names into the real QuickTime tags (public.subtitles.forced-only, public.accessibility.*).

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 18:17:53 -05:00
Scott GarrettandClaude Code 7ff1ed4d0b Serve the contrib submodule URL over HTTPS
The repos are public; hardcoded gitea@ SSH URLs made recursive clones
fail for anyone without a key on the server. Contributors keep SSH via
a url.insteadOf rewrite on their own machines.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 14:00:19 -05:00
Scott GarrettandClaude Code a287ea6404 Adopt Xcode 27.2 project migration
Purely settings: deployment target raised to the toolchain-recommended
value, string-catalog symbols enabled, c11/c++11 module-verification
standards, LastUpgradeCheck bumped, and Xcode's cosmetic re-sort of the
Matroska file entries in the pbxproj (same files, same targets).

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 13:53:01 -05:00
Scott GarrettandClaude Code 79c251c6dc Move the contrib submodule to Gitea
Mirror of SublerApp/contrib now lives at Scott-Files/contrib on
git.technomancer.com so every dependency builds from the fork's own
server over SSH.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-28 13:46:00 -05:00
Scott GarrettandClaude Code e7c7b80e8f Mux VobSub subpic tracks at the frame size declared by the idx
LoadVobSubSubtitles parsed the global `size:` line into locals and threw
it away, and the muxer hardcoded MP4AddSubpicTrack(640, 480), so the
saved display size always read back as 640x480 regardless of what the
subtitle declared. Store the declared size on SBVobSubTrack, carry it
into the model's width/height, and let the muxer pick the subpic display
size with a precedence chain: user-edited trackWidth/trackHeight first,
then the size declared by the subtitle file, then the old 640x480
default. The chosen size is mirrored back into the model, like the
3GText branch does, so the GUI matches what was muxed.

trackWidth/trackHeight are intentionally not set at import time: the
tx3g conversion path reads trackHeight as the default text box height
and then offsets the track by 0.85x, which would push full-frame values
off screen.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-27 02:40:58 -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 8ba3f25a2c 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>
2026-11-26 11:53:17 -05:00
Scott GarrettandClaude Code e42855867d Fix SSA header parsing for files without a [V4+ Styles] section
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>
2026-11-26 11:53:01 -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