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
470 }470 }
471}471}
472 472
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.
478static 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
473static void configure_ass(struct sd *sd, struct mp_osd_res *dim,488static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
474 bool converted, ASS_Track *track)489 bool converted, ASS_Track *track)
475{490{
@@ -508,8 +523,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim, · 32 unmodified lines
508 set_font_scale = opts->sub_scale;523 set_font_scale = opts->sub_scale;
509 }524 }
510 if (set_scale_with_window) {525 if (set_scale_with_window) {
511 int vidh = dim->h - (dim->mt + dim->mb);526 set_font_scale *= dim->h / MPMAX(get_libass_scale_height(dim, set_use_margins), 1);
512 set_font_scale *= dim->h / (float)MPMAX(vidh, 1);
513 }527 }
514 if (!set_scale_by_window) {528 if (!set_scale_by_window) {
515 double factor = dim->h / 720.0;529 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