History

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.

nanahi committed 2 years ago

Commit 42e9f301 parent 8110bda1 file · +16 −2Browse files

Unified · Split

sub/sd_ass.c+16−2
@@ -470,6 +470,21 @@ static void decode(struct sd *sd, struct demux_packet *packet) · 469 unmodified lines
470470 }
471471 }
472472
473+// Calculate the height used for scaling subtitle text size so --sub-scale-with-window
474+// can undo this scale and use frame size instead. The algorithm used is the following:
475+// - If use_margins is disabled, the text is scaled with the visual size of the video.
476+// - If use_margins is enabled, the text is scaled with the size of the video
477+// as if the video is resized to "fit" the size of the frame.
478+static float get_libass_scale_height(struct mp_osd_res *dim, bool use_margins)
479+{
480+ float vidw = dim->w - (dim->ml + dim->mr);
481+ float vidh = dim->h - (dim->mt + dim->mb);
482+ if (!use_margins || vidw < 1.0)
483+ return vidh;
484+ else
485+ return MPMIN(dim->h, dim->w / vidw * vidh);
486+}
487+
473488 static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
474489 bool converted, ASS_Track *track)
475490 {
@@ -508,8 +523,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim, · 32 unmodified lines
508523 set_font_scale = opts->sub_scale;
509524 }
510525 if (set_scale_with_window) {
511− int vidh = dim->h - (dim->mt + dim->mb);
512− set_font_scale *= dim->h / (float)MPMAX(vidh, 1);
526+ set_font_scale *= dim->h / MPMAX(get_libass_scale_height(dim, set_use_margins), 1);
513527 }
514528 if (!set_scale_by_window) {
515529 double factor = dim->h / 720.0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t