Files
MP42Foundation/MP42/MP42PrivateUtilities.h
Scott GarrettandClaude Code 57772086a5 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>
2026-11-28 20:00:08 -05:00

80 lines
3.0 KiB
Objective-C

/*
* MP42Utilities.h
* Subler
*
* Created by Damiano Galassi on 30/01/09.
* Copyright 2022 Damiano Galassi. All rights reserved.
*
*/
#import <Foundation/Foundation.h>
#import "MP42Utilities.h"
#include "mp4v2.h"
#define MP42BundleIdentifier @"org.galad.MP42Foundation"
#define MP42LocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Localizable", (NSBundle *__nonnull)([NSBundle bundleWithIdentifier:MP42BundleIdentifier] ? [NSBundle bundleWithIdentifier:MP42BundleIdentifier] : [NSBundle mainBundle]), comment)
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { TRACK_DISABLED = 0x0,
TRACK_ENABLED = 0x1,
TRACK_IN_MOVIE = 0x2,
TRACK_IN_PREVIEW = 0x4,
TRACK_IN_POSTER = 0x8
} track_header_flags;
NSString * SRTStringFromTime( long long time, long timeScale , const char separator);
int MP4SetTrackEnabled(MP4FileHandle fileHandle, MP4TrackId trackId);
int MP4SetTrackDisabled(MP4FileHandle fileHandle, MP4TrackId trackId);
int updateTracksCount(MP4FileHandle fileHandle);
void updateMoovDuration(MP4FileHandle fileHandle);
void updateMajorBrand(MP42FileHandle fileHandle, NSURL *url);
uint64_t getTrackSize(MP4FileHandle fileHandle, MP4TrackId trackId);
MP4TrackId findChapterTrackId(MP4FileHandle fileHandle);
MP4TrackId findChapterPreviewTrackId(MP4FileHandle fileHandle);
void removeAllChapterTrackReferences(MP4FileHandle fileHandle);
MP4TrackId findFirstVideoTrack(MP4FileHandle fileHandle);
uint16_t getFixedVideoWidth(MP4FileHandle fileHandle, MP4TrackId videoTrack);
NSString * getTrackName(MP4FileHandle fileHandle, MP4TrackId videoTrack);
FourCharCode getTrackMediaType(MP4FileHandle fileHandle, MP4TrackId Id);
FourCharCode getTrackMediaSubType(MP4FileHandle fileHandle, MP4TrackId Id, uint32_t index);
NSString * getTrackLanguage(MP4FileHandle fileHandle, MP4TrackId Id);
NSString * getFilenameLanguage(CFStringRef filename);
// Community-convention track name from subtitle type tokens in the filename
// (sdh/cc/forced/commentary/lyrics): any flag set yields "SDH", nil when absent
NSString * getFilenameSubtitlesTrackName(CFStringRef filename);
// Same token recognition applied to arbitrary text (e.g. an MKV TrackEntry
// name carrying the source subtitle file's name)
NSString * getSubtitleTypeTokenFromString(NSString *text);
NSString * guessStringLanguage(NSString *string);
MP4Duration getTrackDuration(MP4FileHandle fileHandle, MP4TrackId trackId);
double getTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id);
void setTrackStartOffset(MP4FileHandle fileHandle, MP4TrackId Id, double offset);
int copyTrackEditLists (MP4FileHandle fileHandle, MP4TrackId srcTrackId, MP4TrackId dstTrackId);
NSError * MP42Error(NSString *description, NSString* recoverySuggestion, NSInteger code);
int yuv2rgb(int yuv);
int rgb2yuv(int rgb);
void *fast_realloc_with_padding(void *ptr, unsigned int *size, unsigned int min_size);
int DecompressZlib(uint8_t **sampleData, uint32_t *sampleSize);
int DecompressBzlib(uint8_t **sampleData, uint32_t *sampleSize);
#ifdef __cplusplus
}
#endif