0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

sd_ass: fix sub scale with window when use_margins is enabled

By default, libass scales subtitle with video size.
When --sub-scale-with-window is enabled, mpv attempts to undo this scale
and use window size instead. However, the current bahavior is incorrect
when use_margins is enabled, because in this case libass uses the size
of video as if it's "fit" to the window, instead of the displayed size.
As a result, subtitle scale is broken when video-zoom is used in this case:
when zooming out video, the subtitle is scaled up.

Fix this by using the correct factor when use_margins is enabled.
This commit is contained in:
nanahi 2024-06-10 01:03:02 -04:00 committed by Kacper Michajłow
parent 8110bdac6d
commit 42e9f302df

View File

@ -470,6 +470,21 @@ static void decode(struct sd *sd, struct demux_packet *packet)
}
}
// Calculate the height used for scaling subtitle text size so --sub-scale-with-window
// can undo this scale and use frame size instead. The algorithm used is the following:
// - If use_margins is disabled, the text is scaled with the visual size of the video.
// - If use_margins is enabled, the text is scaled with the size of the video
// as if the video is resized to "fit" the size of the frame.
static float get_libass_scale_height(struct mp_osd_res *dim, bool use_margins)
{
float vidw = dim->w - (dim->ml + dim->mr);
float vidh = dim->h - (dim->mt + dim->mb);
if (!use_margins || vidw < 1.0)
return vidh;
else
return MPMIN(dim->h, dim->w / vidw * vidh);
}
static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
bool converted, ASS_Track *track)
{
@ -508,8 +523,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
set_font_scale = opts->sub_scale;
}
if (set_scale_with_window) {
int vidh = dim->h - (dim->mt + dim->mb);
set_font_scale *= dim->h / (float)MPMAX(vidh, 1);
set_font_scale *= dim->h / MPMAX(get_libass_scale_height(dim, set_use_margins), 1);
}
if (!set_scale_by_window) {
double factor = dim->h / 720.0;