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
+46
-10
@@ -15,6 +15,7 @@
|
||||
#import "MP42SampleBuffer.h"
|
||||
#import "MP42AudioConverter.h"
|
||||
#import "MP42BitmapSubConverter.h"
|
||||
#import "MP42PgsToVobSubConverter.h"
|
||||
#import "MP42TextSubConverter.h"
|
||||
|
||||
#import "mp4v2.h"
|
||||
@@ -126,19 +127,54 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
}
|
||||
if ([track isMemberOfClass:[MP42SubtitleTrack class]] && track.conversionSettings &&
|
||||
(track.format == kMP42SubtitleCodecType_VobSub || track.format == kMP42SubtitleCodecType_PGS)) {
|
||||
MP42BitmapSubConverter *subConverter = [[MP42BitmapSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track
|
||||
error:outError];
|
||||
if (track.format == kMP42SubtitleCodecType_PGS &&
|
||||
track.conversionSettings.format == kMP42SubtitleCodecType_VobSub) {
|
||||
// PGS → VobSub (muxed as a real subp track): sup2vob derives one
|
||||
// global DVD palette/geometry for the whole track, and the subpic
|
||||
// branch needs both at track-creation time, so this converter
|
||||
// converts during init (re-reading the source itself) and the
|
||||
// live stream it receives is discarded.
|
||||
MP42PgsToVobSubConverter *pgsConverter = [[MP42PgsToVobSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track
|
||||
error:outError];
|
||||
|
||||
if (subConverter == nil) {
|
||||
if (outError && *outError) {
|
||||
[_logger writeErrorToLog:*outError];
|
||||
if (pgsConverter == nil) {
|
||||
if (outError && *outError) {
|
||||
[_logger writeErrorToLog:*outError];
|
||||
}
|
||||
[unsupportedTracks addObject:track];
|
||||
continue;
|
||||
}
|
||||
[unsupportedTracks addObject:track];
|
||||
continue;
|
||||
}
|
||||
|
||||
track.converter = subConverter;
|
||||
format = track.conversionSettings.format;
|
||||
track.converter = pgsConverter;
|
||||
format = track.conversionSettings.format;
|
||||
|
||||
// The converted subtitles live in the DVD frame (720x480/576),
|
||||
// not the PGS source video's frame — and an MKV-sourced track
|
||||
// carries no size at all — so steer the subpic branch's
|
||||
// trackWidth/trackHeight preference with it.
|
||||
MP42SubtitleTrack *subTrack = (MP42SubtitleTrack *)track;
|
||||
subTrack.trackWidth = pgsConverter.frameWidth;
|
||||
subTrack.trackHeight = pgsConverter.frameHeight;
|
||||
|
||||
NSData *convertedCookie = pgsConverter.magicCookie;
|
||||
if (convertedCookie.length >= sizeof(uint32_t) * 16) {
|
||||
magicCookie = convertedCookie;
|
||||
}
|
||||
} else {
|
||||
MP42BitmapSubConverter *subConverter = [[MP42BitmapSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track
|
||||
error:outError];
|
||||
|
||||
if (subConverter == nil) {
|
||||
if (outError && *outError) {
|
||||
[_logger writeErrorToLog:*outError];
|
||||
}
|
||||
[unsupportedTracks addObject:track];
|
||||
continue;
|
||||
}
|
||||
|
||||
track.converter = subConverter;
|
||||
format = track.conversionSettings.format;
|
||||
}
|
||||
} else if ([track isMemberOfClass:[MP42SubtitleTrack class]] && track.conversionSettings) {
|
||||
MP42TextSubConverter *subConverter = [[MP42TextSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track
|
||||
error:outError];
|
||||
|
||||
Reference in new issue
Block a user