0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

sd_ass: add a very simple and evil way to override ASS subtitle styles

--ass-style-override=force now attempts to override the 'Default' style.
May or may not work. In some situations it will work, but also mess up
seemingly unrelated things like signs typeset with ASS.
This commit is contained in:
wm4 2014-03-01 02:17:58 +01:00
parent 32d18d77cd
commit bcceeec737
3 changed files with 38 additions and 6 deletions

View File

@ -176,13 +176,18 @@ OPTIONS
Using this option may lead to incorrect subtitle rendering.
``--ass-style-override=<yes|no>``
``--ass-style-override=<yes|no|force>``
Control whether user style overrides should be applied.
:yes: Apply all the ``--ass-*`` style override options. Changing the default
for any of these options can lead to incorrect subtitle rendering
(default).
:no: Render subtitles as forced by subtitle scripts.
:yes: Apply all the ``--ass-*`` style override options. Changing the default
for any of these options can lead to incorrect subtitle rendering
(default).
:no: Render subtitles as forced by subtitle scripts.
:force: Like ``yes``, but also override the style named ``Default`` to
make it look like the like text subtitle style implied by the
``--sub-text-...`` option. This won't always work, because the
dialogue style doesn't necessary use this name, and it might break
other advanced uses of the ASS format.
``--ass-use-margins``
Enables placing toptitles and subtitles in black borders when they are

View File

@ -449,7 +449,7 @@ const m_option_t mp_opts[] = {
OPT_CHOICE("ass-shaper", ass_shaper, 0,
({"simple", 0}, {"complex", 1})),
OPT_CHOICE("ass-style-override", ass_style_override, 0,
({"no", 0}, {"yes", 1})),
({"no", 0}, {"yes", 1}, {"force", 2})),
OPT_FLAG("osd-bar", osd_bar_visible, 0),
OPT_FLOATRANGE("osd-bar-align-x", osd_bar_align_x, 0, -1.0, +1.0),
OPT_FLOATRANGE("osd-bar-align-y", osd_bar_align_y, 0, -1.0, +1.0),

View File

@ -128,6 +128,16 @@ static void decode(struct sd *sd, struct demux_packet *packet)
event->Text = strdup(text);
}
static ASS_Style *find_style(ASS_Track *track, const char *name)
{
for (int n = track->n_styles - 1; n >= 0; n--) {
const char *style_name = track->styles[n].Name;
if (style_name && strcasecmp(style_name, name) == 0)
return &track->styles[n];
}
return NULL;
}
static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
struct sub_bitmaps *res)
{
@ -137,6 +147,18 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
if (pts == MP_NOPTS_VALUE || !sd->ass_renderer)
return;
ASS_Style prev_default_style;
ASS_Style *default_style = NULL;
if (opts->ass_style_override == 2) {
default_style = find_style(ctx->ass_track, "Default");
if (default_style) {
prev_default_style = *default_style;
default_style->FontName = NULL; // don't free this
mp_ass_set_style(default_style, ctx->ass_track->PlayResY,
opts->sub_text_style);
}
}
ASS_Renderer *renderer = sd->ass_renderer;
double scale = dim.display_par;
if (!ctx->is_converted && (!opts->ass_style_override ||
@ -166,6 +188,11 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
if (!ctx->is_converted)
mangle_colors(sd, res);
if (default_style) {
free(default_style->FontName);
*default_style = prev_default_style;
}
}
struct buf {