diff --git a/MP42/MP42Muxer.m b/MP42/MP42Muxer.m index fdcfdb4..5fdffa2 100644 --- a/MP42/MP42Muxer.m +++ b/MP42/MP42Muxer.m @@ -576,7 +576,27 @@ MP42_OBJC_DIRECT_MEMBERS continue; } - dstTrackId = MP4AddSubpicTrack(_fileHandle, timeScale, 640, 480); + MP42SubtitleTrack *subTrack = (MP42SubtitleTrack *)track; + // Prefer the user-editable scaled size (tkhd), fall back to the size + // declared by the source subtitle itself (e.g. the vobsub idx `size:` + // line), then to the historical 640x480 default. + uint16_t subpicWidth = 640, subpicHeight = 480; + if (subTrack.trackWidth >= 1 && subTrack.trackWidth <= UINT16_MAX && + subTrack.trackHeight >= 1 && subTrack.trackHeight <= UINT16_MAX) { + subpicWidth = (uint16_t)subTrack.trackWidth; + subpicHeight = (uint16_t)subTrack.trackHeight; + } else if (subTrack.width >= 1 && subTrack.width <= UINT16_MAX && + subTrack.height >= 1 && subTrack.height <= UINT16_MAX) { + subpicWidth = (uint16_t)subTrack.width; + subpicHeight = (uint16_t)subTrack.height; + } + + dstTrackId = MP4AddSubpicTrack(_fileHandle, timeScale, subpicWidth, subpicHeight); + + // Mirror the written display size back into the model, like the + // 3GText branch does, so the GUI shows what was actually muxed. + subTrack.trackWidth = subpicWidth; + subTrack.trackHeight = subpicHeight; uint32_t *subPalette = (uint32_t *) magicCookie.bytes; for (int ii = 0; ii < 16; ii++) { diff --git a/MP42/MP42VobSubImporter.m b/MP42/MP42VobSubImporter.m index 5636bec..b60ab4f 100644 --- a/MP42/MP42VobSubImporter.m +++ b/MP42/MP42VobSubImporter.m @@ -37,6 +37,8 @@ MP42_OBJC_DIRECT_MEMBERS NSString *language; int index; long duration; + int imageWidth; + int imageHeight; NSMutableArray *samples; } @@ -206,6 +208,13 @@ static NSArray * LoadVobSubSubtitles(NSURL *theDirectory, NSStr } } + // The `size:` line is global private data that appears before the + // first track header, so apply it to every parsed track. + for (SBVobSubTrack *track in tracks) { + track->imageWidth = imageWidth; + track->imageHeight = imageHeight; + } + return [tracks copy]; } bail: @@ -247,6 +256,17 @@ MP42_OBJC_DIRECT_MEMBERS newTrack.timescale = 1000; newTrack.duration = track->duration; + // Carry the frame size declared by the idx `size:` line into the + // model, so the muxer can mux the subpic track at the size the + // subtitle actually uses instead of a generic default. + // Note: trackWidth/trackHeight are intentionally left unset here: + // the tx3g conversion path reads them as the tx3g default text box + // size, which must keep its own 0.15-height fallback. + if (track->imageWidth > 0 && track->imageHeight > 0) { + newTrack.width = (uint64_t)track->imageWidth; + newTrack.height = (uint64_t)track->imageHeight; + } + [self addTrack:newTrack]; }