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>
48 lines
1.8 KiB
Objective-C
48 lines
1.8 KiB
Objective-C
//
|
|
// MP42PgsToVobSubConverter.h
|
|
// MP42Foundation
|
|
//
|
|
// Converts a Blu-ray PGS subtitle track (demuxed from an MKV) into VobSub
|
|
// subpic samples, so a PGS-only-in-MKV subtitle can land in an MP4 as a
|
|
// real subp track instead of only as OCR'd tx3g text.
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import "MP42ConverterProtocol.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@class MP42SampleBuffer;
|
|
@class MP42SubtitleTrack;
|
|
|
|
// MP42ConverterProtocol for PGS → VobSub (subpic) muxing. PGS conversion is
|
|
// whole-track batch work (sup2vob derives one global 4-color DVD palette and
|
|
// needs later compositions to compute frame end-times), and the muxer needs
|
|
// the palette and frame size when it *creates* the subpic track — before any
|
|
// sample is pumped. So the conversion runs to completion in -initWithTrack:
|
|
// error:, and copyEncodedSample just replays the finished samples: the
|
|
// track's live input stream (whose bytes the prepass already re-read from
|
|
// disk) is discarded, and EOF is emitted once the input stream ends.
|
|
@interface MP42PgsToVobSubConverter : NSObject <MP42ConverterProtocol>
|
|
|
|
- (nullable instancetype)initWithTrack:(MP42SubtitleTrack *)track error:(NSError * __autoreleasing *)outError;
|
|
|
|
// DVD frame the converted subtitles were rendered at (720x480 NTSC /
|
|
// 720x576 PAL), from the generated idx `size:` line. The muxer sizes the
|
|
// subpic track with these — the PGS model track carries the source video's
|
|
// size (or 0 from an MKV), not the frame the VobSub was converted to.
|
|
@property (nonatomic, readonly) uint32_t frameWidth;
|
|
@property (nonatomic, readonly) uint32_t frameHeight;
|
|
|
|
// The idx palette as 16 UInt32 0x00RRGGBB entries — the subpic magic cookie.
|
|
- (nullable NSData *)magicCookie;
|
|
|
|
- (void)addSample:(MP42SampleBuffer *)sample;
|
|
- (nullable MP42SampleBuffer *)copyEncodedSample;
|
|
|
|
- (void)cancel;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|