summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-03-01 02:17:58 +0100
committerwm4 <wm4@nowhere>2014-03-01 02:18:03 +0100
commitbcceeec737844a4184c1256f6490acbd8a8d1611 (patch)
treef55a13c5a6544c65fcd3123452449615715e2fc5 /sub
parent32d18d77cd3afd49f8d221db50ab8fc23dbdd340 (diff)
downloadmpv-bcceeec737844a4184c1256f6490acbd8a8d1611.tar.bz2
mpv-bcceeec737844a4184c1256f6490acbd8a8d1611.tar.xz
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.
Diffstat (limited to 'sub')
-rw-r--r--sub/sd_ass.c27
1 files changed, 27 insertions, 0 deletions
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 {