Mux VobSub subpic tracks at the frame size declared by the idx
LoadVobSubSubtitles parsed the global `size:` line into locals and threw it away, and the muxer hardcoded MP4AddSubpicTrack(640, 480), so the saved display size always read back as 640x480 regardless of what the subtitle declared. Store the declared size on SBVobSubTrack, carry it into the model's width/height, and let the muxer pick the subpic display size with a precedence chain: user-edited trackWidth/trackHeight first, then the size declared by the subtitle file, then the old 640x480 default. The chosen size is mirrored back into the model, like the 3GText branch does, so the GUI matches what was muxed. trackWidth/trackHeight are intentionally not set at import time: the tx3g conversion path reads trackHeight as the default text box height and then offsets the track by 0.85x, which would push full-frame values off screen. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
e8231dea59
commit
e7c7b80e8f
2 files changed
+41
-1
No files matched your search
+21
-1
@@ -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++) {
|
||||
|
||||
@@ -37,6 +37,8 @@ MP42_OBJC_DIRECT_MEMBERS
|
||||
NSString *language;
|
||||
int index;
|
||||
long duration;
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
NSMutableArray<SBVobSubSample *> *samples;
|
||||
}
|
||||
|
||||
@@ -206,6 +208,13 @@ static NSArray<SBVobSubTrack *> * 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];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user