1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-19 18:05:21 +00:00

sd_lavc: implement --sub-pos for bitmap subtitles

Simple enough to do. May have mixed results. Typically, bitmap subtitles
will have a tight bounding box around the rendered text. But if for
example there is text on the top and bottom, it may be a single big
bitmap with a large transparent area between top and bottom. In
particular, DVD subtitles are really just a single screen-sized
RLE-encoded bitmap, though libavcodec will crop off transparent areas.

Like with sd_ass, you can't move subtitles _down_ if they are already in
their origin position. This could probably be improved, but I don't want
to deal with that right now.
This commit is contained in:
wm4 2019-05-22 23:15:34 +02:00
parent ccc14e6560
commit 30e99a600c
2 changed files with 20 additions and 0 deletions

View File

@ -1995,6 +1995,9 @@ Subtitles
:strip: Radically strip all ASS tags and styles from the subtitle. This :strip: Radically strip all ASS tags and styles from the subtitle. This
is equivalent to the old ``--no-ass`` / ``--no-sub-ass`` options. is equivalent to the old ``--no-ass`` / ``--no-sub-ass`` options.
This also controls some bitmap subtitle overrides, as well as HTML tags in
formats like SRT, despite the name of the option.
``--sub-ass-force-margins`` ``--sub-ass-force-margins``
Enables placing toptitles and subtitles in black borders when they are Enables placing toptitles and subtitles in black borders when they are
available, if the subtitles are in the ASS format. available, if the subtitles are in the ASS format.

View File

@ -447,6 +447,23 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format,
w = priv->video_params.w; w = priv->video_params.w;
h = priv->video_params.h; h = priv->video_params.h;
} }
if (opts->sub_pos != 100 && opts->ass_style_override) {
int offset = (100 - opts->sub_pos) / 100.0 * h;
for (int n = 0; n < res->num_parts; n++) {
struct sub_bitmap *sub = &res->parts[n];
// Decide by heuristic whether this is a sub-title or something
// else (top-title, covering whole screen).
if (sub->y < h / 2)
continue;
// Allow moving up the subtitle, but only until it clips.
sub->y = MPMAX(sub->y - offset, 0);
}
}
osd_rescale_bitmaps(res, w, h, d, video_par); osd_rescale_bitmaps(res, w, h, d, video_par);
} }