Build sup2vob into the app bundle so it ships and stays fresh
A "Build sup2vob CLI" run-script phase on the Subler target runs the submodule's Makefile (incremental — a no-op unless the conversion sources changed) and installs the product to Contents/MacOS/sup2vob. Every Subler build refreshes the CLI; a terminal sup2vob can be a symlink into the bundle instead of a copied `make install`. extractsubs finds that bundle-internal sup2vob automatically: PATH first, then the script's own ../MacOS/sup2vob sibling, so running the copy inside Subler.app/Contents/Resources works with no install at all (verified with sup2vob absent from PATH: same 1920x1080 .sub/.idx). The phase walks the source tree, so it opts the Subler target out of ENABLE_USER_SCRIPT_SANDBOXING — a build-time shell-script file-access setting only, no effect on the app's runtime security posture. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
56d843c044
commit
51112947fb
3 files changed
+53
-9
No files matched your search
@@ -26,7 +26,7 @@ xcodebuild -project Subler.xcodeproj -scheme Subler -configuration Debug build
|
||||
|
||||
No deployment-target override is needed: the projects moved from upstream's 10.13 to `$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)` (recent toolchains refuse 10.13).
|
||||
|
||||
There is **no test target and no CI** — changes are verified by building and running the app manually. Of the `Utilities/` tools, MP4Dump (legacy ObjC debugging) is not part of the app build, but `ParseFilename/` **is** — it's copied into the app bundle and executed at runtime by `MetadataHelper.parseFilename` via `Process`. `extractsubs` is also copied into the bundle (Resources phase → `Contents/Resources/extractsubs`, exec bit preserved by the copy) but **nothing in the app invokes it** — it's a user-facing CLI helper shipped with the app: it extracts subtitle tracks from mkv/mp4 files via ffmpeg stream copy (named `<input>.<track>[.<type>].<lang>.<ext>` — the shape `getFilenameLanguage`/`getFilenameSubtitlesTrackName` probe, so results drag straight back in) and runs `sup2vob --full` on extracted PGS `.sup` files. It needs ffprobe/ffmpeg/sup2vob on PATH (sup2vob builds from `MP42Foundation/sup2vob/` with `make && sudo make install`), plus mkvtoolnix and python3 only for its `S_TEXT/WEBVTT` rescue path, and it skips extraction with a clear message rather than failing per-track mid-pipeline.
|
||||
There is **no test target and no CI** — changes are verified by building and running the app manually. Of the `Utilities/` tools, MP4Dump (legacy ObjC debugging) is not part of the app build, but `ParseFilename/` **is** — it's copied into the app bundle and executed at runtime by `MetadataHelper.parseFilename` via `Process`. `extractsubs` is also copied into the bundle (Resources phase → `Contents/Resources/extractsubs`, exec bit preserved by the copy) but **nothing in the app invokes it** — it's a user-facing CLI helper shipped with the app: it extracts subtitle tracks from mkv/mp4 files via ffmpeg stream copy (named `<input>.<track>[.<type>].<lang>.<ext>` — the shape `getFilenameLanguage`/`getFilenameSubtitlesTrackName` probe, so results drag straight back in) and runs `sup2vob --full` on extracted PGS `.sup` files. It needs ffprobe/ffmpeg on PATH; sup2vob comes from PATH **or from the bundle next to the script** (`Contents/MacOS/sup2vob`, built by the app — see the submodule section), so the bundled pair needs no install. mkvtoolnix and python3 are only needed for its `S_TEXT/WEBVTT` rescue path, and it skips extraction with a clear message rather than failing per-track mid-pipeline.
|
||||
|
||||
## Architecture
|
||||
|
||||
@@ -50,7 +50,7 @@ Referenced by the main project; `MP42Foundation.framework` is linked and copied
|
||||
|
||||
The app never parses MP4/atom data directly — codec, container, and subtitle-conversion work belongs in the submodule, not in `Classes/`. `Classes/MP42FileAdditions.swift` extends framework types with app-level conveniences.
|
||||
|
||||
PGS `.sup` subtitle import: `MP42VobSubImporter` claims both `idx` and `sup`. A `.sup` is converted up-front to a private temp `.idx/.sub` pair via `MP42SupConverter` (the `@objc` façade over the sup2vob Swift sources vendored in `MP42/Sup2Vob/` from https://git.technomancer.com/Scott-Files/sup2vob — upstream logic is kept identical so upstream fixes re-merge cleanly; upstream's CLI-only globals and `main.swift` are the framework's only adaptations), then the existing VobSub machinery handles everything: the track comes out as `kMP42SubtitleCodecType_VobSub` (muxable straight into MP4 as `subp` via `MP4AddSubpicTrack`, or tx3g-convertible via `MP42BitmapSubConverter`), the frame size rides the idx `size:` line into `track.width/height`, language comes from the source filename (`getFilenameLanguage`, since PGS carries none — the generated idx `id:` is just "en"), and `track.URL` stays the user's `.sup`. The façade always runs upstream's `--full` mode (`fullFramePassthrough = true`, set in the adaptation layer `MP42SupConverter.swift`): frames keep the geometry the PGS itself defines — the idx size line is the **PCS canvas** (e.g. 1920x1080) and nothing is downscaled to the 720x480/576 DVD frame, which now only survives as fallback for a stream with no usable canvas (the framework's output is byte-identical to `sup2vob --full`). The temp pair is deleted in the importer's `dealloc` — safe because tracks hold the importer strongly through export. The ObjC→Swift hop uses the existing `MP42-Shared-Swift.h` shim (generated header), new Swift files must join both targets' Sources phases like `SampleDescription.swift`. The **same vendored sources** also build the CLI: `MP42Foundation/sup2vob/` holds only upstream's `main.swift` (adapted once: the two CLI globals `debugFrames`/`fullFramePassthrough` belong to the vendored `Convert.swift`, so main.swift drops its re-declaration) plus a `Makefile` compiling against `../MP42/Sup2Vob/` — one upstream merge updates app and CLI together, nothing can drift, and the CLI's `--full` output doubles as the byte-identical oracle for the framework converter (`make && sudo make install` puts `sup2vob` on PATH for the app-bundled `extractsubs`).
|
||||
PGS `.sup` subtitle import: `MP42VobSubImporter` claims both `idx` and `sup`. A `.sup` is converted up-front to a private temp `.idx/.sub` pair via `MP42SupConverter` (the `@objc` façade over the sup2vob Swift sources vendored in `MP42/Sup2Vob/` from https://git.technomancer.com/Scott-Files/sup2vob — upstream logic is kept identical so upstream fixes re-merge cleanly; upstream's CLI-only globals and `main.swift` are the framework's only adaptations), then the existing VobSub machinery handles everything: the track comes out as `kMP42SubtitleCodecType_VobSub` (muxable straight into MP4 as `subp` via `MP4AddSubpicTrack`, or tx3g-convertible via `MP42BitmapSubConverter`), the frame size rides the idx `size:` line into `track.width/height`, language comes from the source filename (`getFilenameLanguage`, since PGS carries none — the generated idx `id:` is just "en"), and `track.URL` stays the user's `.sup`. The façade always runs upstream's `--full` mode (`fullFramePassthrough = true`, set in the adaptation layer `MP42SupConverter.swift`): frames keep the geometry the PGS itself defines — the idx size line is the **PCS canvas** (e.g. 1920x1080) and nothing is downscaled to the 720x480/576 DVD frame, which now only survives as fallback for a stream with no usable canvas (the framework's output is byte-identical to `sup2vob --full`). The temp pair is deleted in the importer's `dealloc` — safe because tracks hold the importer strongly through export. The ObjC→Swift hop uses the existing `MP42-Shared-Swift.h` shim (generated header), new Swift files must join both targets' Sources phases like `SampleDescription.swift`. The **same vendored sources** also build the CLI: `MP42Foundation/sup2vob/` holds only upstream's `main.swift` (adapted once: the two CLI globals `debugFrames`/`fullFramePassthrough` belong to the vendored `Convert.swift`, so main.swift drops its re-declaration) plus a `Makefile` compiling against `../MP42/Sup2Vob/` — one upstream merge updates app and CLI together, nothing can drift, and the CLI's `--full` output doubles as the byte-identical oracle for the framework converter. The Subler app build **invokes this same Makefile** (the "Build sup2vob CLI" run-script phase, `make -C MP42Foundation/sup2vob` — incremental, a no-op when unchanged) and installs the product into `Subler.app/Contents/MacOS/sup2vob`, so building Subler refreshes the CLI; a terminal `sup2vob` can just be a symlink to that bundle binary. The phase is why the Subler target sets `ENABLE_USER_SCRIPT_SANDBOXING = NO` (build-script file access within the source tree only — unrelated to the app's runtime security); the CLI itself also stays buildable standalone (`make && sudo make install`).
|
||||
|
||||
PGS-from-MKV → VobSub: a PGS track inside an MKV imports as a **real subp track**, not just OCR'd tx3g text. `FileImportController`'s subtitle action sheet gains a `VobSub` entry (tag 2, default follows `Prefs.subtitleConvertBitmap` like VobSub sources) for PGS-format tracks; selecting it sets `MP42ConversionSettings.subtitlesVobSubConversion`, and the muxer's bitmap-converter branch recognizes PGS-source + VobSub-target and uses `MP42PgsToVobSubConverter` instead of `MP42BitmapSubConverter`. That converter runs the whole sup2vob conversion synchronously in `initWithTrack:error:` (sup2vob derives one global palette/geometry for the track — the PGS canvas size — and the muxer needs `magicCookie` + `frameWidth/Height` before creating the subpic track); the live muxing stream is discarded and `copyEncodedSample` replays prepass-collected samples, ending on exactly one EOF-flagged buffer. **Matroska traps found empirically here:** mkvmerge stores each PGS segment with its 13-byte "PG" envelope removed (blocks are `type` + 2-byte-be `len` + payload repeated, blank frames are real blank presentations, everything zlib-compressed) — a plain concatenation of demuxed blocks is NOT a `.sup`; phase 1 must walk each block's stripped segments and rebuild `PG + pts:4(90kHz from the block's ns timestamp ×9/100000) + 4 zero bytes + type + len` (mkvextract reconstructs exactly this — the rebuilt stream is byte-identical to it; blocks that already carry envelopes pass through verbatim for other muxers). The rebuilt temp `.sup` is fed to a second `MP42VobSubImporter` (the same machinery as `.sup` drag-import) whose demux supplies the subpic samples/palette. The converter header isn't exported (matches `MP42BitmapSubConverter`'s non-Public Headers-phase convention), and it can't be exercised from outside the framework via `copyNextSample`/`MP42FileImporter+Private` — those are `objc_direct`/internal, so harnesses must stay in public API (see the `@selector`-on-direct-method constraint noted in the converter source).
|
||||
|
||||
|
||||
Reference in new issue
Block a user