Retag queued Matroska files in place instead of converting to MP4

The queue now mirrors the document window for .mkv/.mka/.mks sources.
The window's whole save branching (importer-order track snapshot, chapter
row snapshot, staleness guard, tag-writer-vs-remuxer choice) moved out of
Document into a shared MatroskaSaver used by both Document and QueueItem
so the two paths cannot drift. Queue items import tags-only, keep the
Matroska extension (in place, or stream-copy into a destination folder),
MP4-only actions no-op on them, and send-to-queue hands the item the
document's model plus its identity pairing baseline via attachMatroskaSaver.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
Scott GarrettandClaude Code committed 2026-11-29 20:33:47 -05:00
1 parent a1da1c8106
commit 80ca3970ec
7 files changed
+442 -195

No files matched your search

+27
View File
@@ -106,6 +106,14 @@ class QueueSubtitlesAction : NSObject, QueueActionProtocol {
for importer in subtitlesImporters {
for track in importer.tracks {
// Honor addTrack:'s conversion-settings invariant (see
// Document.readMatroska / importSubtitleTracksForMatroska):
// the MP4 path converts text subs to tx3g at mux time; a
// Matroska remux ignores the settings and re-parses the text
// from track.URL as S_TEXT/UTF8 instead.
if trackNeedConversion(track.format), let subtitleTrack = track as? MP42SubtitleTrack {
subtitleTrack.conversionSettings = MP42ConversionSettings.subtitlesConversion()
}
item.mp4File?.addTrack(track)
}
}
@@ -339,6 +347,12 @@ class QueueOrganizeGroupsAction : NSObject, QueueActionProtocol {
override init() {}
func runAction(_ item: QueueItem) -> Bool {
// Organize/infer must never touch a Matroska item: same rule as the
// window's didSelect/import paths — the tags-only model is the tag
// writer's positional diff baseline against the file's TrackEntry
// list — and language/characteristic inference has no Matroska
// equivalent to write into anyway.
guard item.isMatroska == false else { return true }
item.mp4File?.organizeAlternateGroups()
item.mp4File?.inferTracksLanguages()
item.mp4File?.inferMediaCharacteristics()
@@ -361,6 +375,9 @@ class QueueFixFallbacksAction : NSObject, QueueActionProtocol {
override init() {}
func runAction(_ item: QueueItem) -> Bool {
// Fallback tracks are an MP4 track-reference concept; a Matroska
// retag has nothing to link.
guard item.isMatroska == false else { return true }
item.mp4File?.setAutoFallback()
return true
}
@@ -540,6 +557,10 @@ class QueueColorSpaceAction : NSObject, QueueActionProtocol {
}
func runAction(_ item: QueueItem) -> Bool {
// Color atoms are not among the four track fields a Matroska retag
// writes (name/language/enabled/forced) — the window keeps the video
// tab read-only on MKV docs for the same reason.
guard item.isMatroska == false else { return true }
if let tracks = item.mp4File?.tracks(withMediaType: kMP42MediaType_Video) as? [MP42VideoTrack] {
for track in tracks {
if track.format == kMP42VideoCodecType_H264 ||
@@ -581,6 +602,12 @@ class QueueOptimizeAction: NSObject, QueueActionProtocol {
override init() {}
func runAction(_ item: QueueItem) -> Bool {
// On a Matroska item "optimize" is the forced full rebuild that the
// write pass already performed (QueueItem.process sees this action
// and forces the MatroskaSaver remux branch — the container-
// equivalent of atom reordering); MP4Optimize would have nothing to
// reorderBy on a tags-only model.
if item.isMatroska { return true }
return item.mp4File?.optimize() ?? false
}