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>
This commit is contained in:
1 parent
e02f60b5f6
commit
57772086a5
9 files changed
+552
-52
No files matched your search
+32
-40
@@ -361,67 +361,59 @@ NSString * getFilenameLanguage(CFStringRef filename)
|
||||
// language (movie.eng.sdh.srt, movie.eng.forced.srt). Neither container has a
|
||||
// real SDH/CC flag — MP4 only has per-sample forced flags — so the community
|
||||
// convention is to put the type in the track *name*, which is what players
|
||||
// like VLC display. Returns nil when the filename carries no such token.
|
||||
// like VLC display. Any flag set names the track "SDH": the release-naming
|
||||
// crowd treats SDH/CC/forced/commentary/lyrics as one bucket of
|
||||
// not-plain-subtitles, and one recognizable name serves players better than
|
||||
// five. Returns nil when the text carries no such token.
|
||||
// Dashes are separators here (unlike getFilenameLanguage) so
|
||||
// "hearing-impaired" splits into hit-able tokens too.
|
||||
static NSString * subtitleTypeTokenFromFilename(CFStringRef filename)
|
||||
static NSString * subtitleTypeTokenFromString(NSString *text)
|
||||
{
|
||||
NSString *baseName = [(__bridge NSString *)filename lastPathComponent].stringByDeletingPathExtension;
|
||||
if (!text.length) {
|
||||
return nil;
|
||||
}
|
||||
NSArray<NSString *> *tokens =
|
||||
[baseName componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@". _-"]];
|
||||
[text componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@". _-"]];
|
||||
|
||||
BOOL forced = NO, lyrics = NO, commentary = NO, closedCaptions = NO, hearingImpaired = NO;
|
||||
BOOL anyFlag = NO;
|
||||
for (NSUInteger i = 0; i < tokens.count; i++) {
|
||||
NSString *lowercaseToken = tokens[i].lowercaseString;
|
||||
if ([lowercaseToken isEqualToString:@"sdh"] || [lowercaseToken isEqualToString:@"hearingimpaired"] ||
|
||||
[lowercaseToken isEqualToString:@"impaired"] || [lowercaseToken isEqualToString:@"deaf"]) {
|
||||
hearingImpaired = YES;
|
||||
} else if ([lowercaseToken isEqualToString:@"cc"]) {
|
||||
closedCaptions = YES;
|
||||
[lowercaseToken isEqualToString:@"impaired"] || [lowercaseToken isEqualToString:@"deaf"] ||
|
||||
[lowercaseToken isEqualToString:@"cc"] ||
|
||||
[lowercaseToken isEqualToString:@"commentary"] || [lowercaseToken isEqualToString:@"commentaries"] ||
|
||||
[lowercaseToken isEqualToString:@"forced"] ||
|
||||
[lowercaseToken isEqualToString:@"lyrics"] || [lowercaseToken isEqualToString:@"lyric"]) {
|
||||
anyFlag = YES;
|
||||
} else if ([lowercaseToken isEqualToString:@"closed"] && i + 1 < tokens.count &&
|
||||
[tokens[i + 1].lowercaseString hasPrefix:@"caption"]) {
|
||||
// "closed_caption"/"closed-caption" — the separator splits the
|
||||
// pair, so match it across two tokens. (Bare "captions" is NOT a
|
||||
// CC marker; naming like Movie.eng.Captions.srt stays unnamed.)
|
||||
closedCaptions = YES;
|
||||
} else if ([lowercaseToken isEqualToString:@"commentary"] || [lowercaseToken isEqualToString:@"commentaries"]) {
|
||||
commentary = YES;
|
||||
} else if ([lowercaseToken isEqualToString:@"forced"]) {
|
||||
forced = YES;
|
||||
} else if ([lowercaseToken isEqualToString:@"lyrics"] || [lowercaseToken isEqualToString:@"lyric"]) {
|
||||
lyrics = YES;
|
||||
anyFlag = YES;
|
||||
}
|
||||
}
|
||||
|
||||
// SDH outranks CC (they overlap in naming), and both outrank the
|
||||
// forced-only flag (SDH files typically flag many lines forced too).
|
||||
if (hearingImpaired) {
|
||||
return @"SDH";
|
||||
}
|
||||
if (closedCaptions) {
|
||||
return @"CC";
|
||||
}
|
||||
if (commentary) {
|
||||
return @"Commentary";
|
||||
}
|
||||
if (lyrics) {
|
||||
return @"Lyrics";
|
||||
}
|
||||
if (forced) {
|
||||
return @"Forced";
|
||||
}
|
||||
return nil;
|
||||
return anyFlag ? @"SDH" : nil;
|
||||
}
|
||||
|
||||
// Track name for any subtitle descriptor (a file path, or an MKV TrackEntry
|
||||
// name): "SDH" when it carries a community type token (sdh/cc/forced/
|
||||
// commentary/lyrics — any flag set means SDH), nil when it carries none.
|
||||
NSString * getSubtitleTypeTokenFromString(NSString *text)
|
||||
{
|
||||
return subtitleTypeTokenFromString(text);
|
||||
}
|
||||
|
||||
// Track name for a subtitle file, following the community convention of
|
||||
// naming the track after the type token the filename carries ("SDH", "CC",
|
||||
// "Forced", "Commentary", "Lyrics"). Deliberately NOT prefixed with the
|
||||
// language: the language rides its own element (MP4 elng/mdhd, MKV
|
||||
// Language/LanguageIETF) and players show it alongside the name. Returns nil
|
||||
// when the filename carries no type token.
|
||||
// naming the track after the type tokens the filename carries ("SDH").
|
||||
// Deliberately NOT prefixed with the language: the language rides its own
|
||||
// element (MP4 elng/mdhd, MKV Language/LanguageIETF) and players show it
|
||||
// alongside the name. Returns nil when the filename carries no type token.
|
||||
NSString * getFilenameSubtitlesTrackName(CFStringRef filename)
|
||||
{
|
||||
return subtitleTypeTokenFromFilename(filename);
|
||||
NSString *baseName = [(__bridge NSString *)filename lastPathComponent].stringByDeletingPathExtension;
|
||||
return subtitleTypeTokenFromString(baseName);
|
||||
}
|
||||
|
||||
NSString *guessStringLanguage(NSString *stringFromFileAtURL)
|
||||
|
||||
Reference in new issue
Block a user