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>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-25 19:48:09 -05:00
1 parent bfa477b799
commit 1040f47542
18 files changed
+4397 -86

No files matched your search

+20 -1
View File
@@ -98,6 +98,11 @@ static NSArray<UTType *> *_supportedContentTypes API_AVAILABLE(macos(11.0));
return [[self supportedFileFormats] containsObject:fileType.lowercaseString];
}
+ (BOOL)isMatroskaFileType:(NSString *)fileType
{
return [[MP42MkvImporter supportedFileFormats] containsObject:fileType.lowercaseString];
}
+ (NSArray<UTType *> *)supportedContentTypes
{
return _supportedContentTypes;
@@ -116,13 +121,27 @@ static NSArray<UTType *> *_supportedContentTypes API_AVAILABLE(macos(11.0));
- (instancetype)initWithURL:(NSURL *)fileURL error:(NSError * __autoreleasing *)error
{
return [self initWithURL:fileURL tagsOnly:NO error:error];
}
- (instancetype)initWithURL:(NSURL *)fileURL tagsOnly:(BOOL)tagsOnly error:(NSError * __autoreleasing *)error
{
// Called on MP42FileImporter itself (the factory path, e.g. from the app):
// pick and allocate the subclass for the extension. Called on a subclass
// instance that ignores tagsOnly (it inherits this method), forward to
// its real designated initializer instead — MP42MkvImporter overrides this
// method outright, so it never lands here.
if (![self isMemberOfClass:[MP42FileImporter class]]) {
return [self initWithURL:fileURL error:error];
}
self = nil;
// Initialize the right file importer subclass
for (Class c in _fileImporters) {
if ([c canInitWithFileType:fileURL.pathExtension]) {
self = [[c alloc] initWithURL:fileURL error:error];
self = [[c alloc] initWithURL:fileURL tagsOnly:tagsOnly error:error];
if (self) {
for (MP42Track *track in _tracksArray) {
track.importer = self;