diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 6461750062..fc8b778ac8 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -176,13 +176,18 @@ OPTIONS Using this option may lead to incorrect subtitle rendering. -``--ass-style-override=`` +``--ass-style-override=`` 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 diff --git a/options/options.c b/options/options.c index 835ff21f9f..30564ba018 100644 --- a/options/options.c +++ b/options/options.c @@ -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), diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 8b6f1f1554..e4428516b9 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -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 {