From 2f6713bedeb77a7c058ce4954eb95ee7a2ca7119 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Oct 2012 02:23:22 +0200 Subject: sub: enable sub-pos with libass The --sub-pos option and sub-pos property control the vertical position of a subtitle. Also change how sub-pos is handled in the old subtitle renderer (used with -no-ass). The new behavior doesn't render subtitles out of the screen if the subtitle is located near the top screen border and has too many lines. --- sub/ass_mp.c | 3 +++ sub/osd_libass.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'sub') diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 202664578b..e2729df8ca 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -232,6 +232,9 @@ void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, ass_set_frame_size(priv, dim->w, dim->h); ass_set_margins(priv, dim->mt, dim->mb, dim->ml, dim->mr); ass_set_use_margins(priv, opts->ass_use_margins); +#if LIBASS_VERSION >= 0x01010000 + ass_set_line_position(priv, 100 - sub_pos); +#endif ass_set_font_scale(priv, opts->ass_font_scale); if (!unscaled && (opts->ass_hinting & 4)) hinting = 0; diff --git a/sub/osd_libass.c b/sub/osd_libass.c index e770215ce6..9b0bbb01ab 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -345,8 +345,10 @@ void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj) ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style; - style->MarginV = obj->osd_track->PlayResY * ((100 - sub_pos)/110.0); update_font_scale(obj->osd_track, style, text_font_scale_factor); +#if LIBASS_VERSION >= 0x01010000 + ass_set_line_position(osd->osd_render, 100 - sub_pos); +#endif char *text = talloc_strdup(NULL, ""); -- cgit v1.2.3 From c9df2c8bd83b31375a79ab2bc4f854a53ff019c1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Oct 2012 02:23:29 +0200 Subject: sub: add --ass-style-override option to disable style overrides There are a number of options which modify ASS subtitle rendering. Most of these do things that can interfere with the styling done by subtitle scripts, resulting in incorrect rendering. Add the --ass-style-override option to make it easy to disable all overrides. This helps trouble- shooting, and makes it more practical to use the override features. (You can simply toggle the ass-style-override property at runtime, should one of the style override options break subtitle rendering at a certain point.) This mainly affects whether most --ass-* options are applied, as well as --sub-pos. Some things, like explicit style overrides loaded with --ass-force-style, can't be changed at runtime using the ass-style-override property. --- sub/ass_mp.c | 38 ++++++++++++++++++++++++++------------ sub/sd_ass.c | 4 +++- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'sub') diff --git a/sub/ass_mp.c b/sub/ass_mp.c index e2729df8ca..908a552acf 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -47,7 +47,7 @@ ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts) track->PlayResY = 288; track->WrapStyle = 0; - if (opts->ass_styles_file) + if (opts->ass_styles_file && opts->ass_style_override) ass_read_styles(track, opts->ass_styles_file, sub_cp); if (track->n_styles == 0) { @@ -95,7 +95,9 @@ ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts) style->ScaleY = 1.; } - ass_process_force_style(track); + if (opts->ass_style_override) + ass_process_force_style(track); + return track; } @@ -228,20 +230,32 @@ ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, struct mp_eosd_res *dim, bool unscaled) { - int hinting; ass_set_frame_size(priv, dim->w, dim->h); ass_set_margins(priv, dim->mt, dim->mb, dim->ml, dim->mr); - ass_set_use_margins(priv, opts->ass_use_margins); + + int set_use_margins = 0; + int set_sub_pos = 0; + float set_line_spacing = 0; + float set_font_scale = 1; + int set_hinting = 0; + if (opts->ass_style_override) { + set_use_margins = opts->ass_use_margins; + set_sub_pos = 100 - sub_pos; + set_line_spacing = opts->ass_line_spacing; + set_font_scale = opts->ass_font_scale; + if (!unscaled && (opts->ass_hinting & 4)) + set_hinting = 0; + else + set_hinting = opts->ass_hinting & 3; + } + + ass_set_use_margins(priv, set_use_margins); #if LIBASS_VERSION >= 0x01010000 - ass_set_line_position(priv, 100 - sub_pos); + ass_set_line_position(priv, set_sub_pos); #endif - ass_set_font_scale(priv, opts->ass_font_scale); - if (!unscaled && (opts->ass_hinting & 4)) - hinting = 0; - else - hinting = opts->ass_hinting & 3; - ass_set_hinting(priv, hinting); - ass_set_line_spacing(priv, opts->ass_line_spacing); + ass_set_font_scale(priv, set_font_scale); + ass_set_hinting(priv, set_hinting); + ass_set_line_spacing(priv, set_line_spacing); } void mp_ass_configure_fonts(ASS_Renderer *priv) diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 9295cab07d..fcedc9fec5 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -135,7 +135,9 @@ static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, return; double scale = osd->normal_scale; - if (ctx->vsfilter_aspect && opts->ass_vsfilter_aspect_compat) + bool use_vs_aspect = opts->ass_style_override + ? opts->ass_vsfilter_aspect_compat : 1; + if (ctx->vsfilter_aspect && use_vs_aspect) scale = osd->vsfilter_scale; ASS_Renderer *renderer = osd->ass_renderer; mp_ass_configure(renderer, opts, &osd->dim, osd->unscaled); -- cgit v1.2.3 From 0ff7dd992fb06fa8a5cba0a895717787a615e7bb Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 13 Oct 2012 21:09:34 +0200 Subject: osd_libass: fix \n escapes Apparently libass can't be made to not interpret "\n" as escape. That means "\n" can't be printed literally. Use the same hack that was added to mplayer2 when that project merged osd_libass.c: add an invisible zero-width joiner character between "\" and "n". It seems U+FEFF is deprecated, because it has been redefined as BOM mark. Use U+2060, which seems to be the replacement. --- sub/osd_libass.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'sub') diff --git a/sub/osd_libass.c b/sub/osd_libass.c index 9b0bbb01ab..de9f31b2cb 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -233,14 +233,6 @@ static char *mangle_ass(const char *in) { char *res = talloc_strdup(NULL, ""); while (*in) { - if (in[0] == '\\' && strchr("nNh{}", in[1])) { - // Undo escaping, e.g. \{ -> \\{ - // Note that e.g. \\j still must be emitted as \\j - // (libass only understands the escapes listed in the strchr args) - res = talloc_asprintf_append_buffer(res, "\\\\%c", in[1]); - in += 2; - continue; - } // As used by osd_get_function_sym(). if (in[0] == '\xFF') { res = talloc_strdup_append_buffer(res, ASS_USE_OSD_FONT); @@ -252,6 +244,9 @@ static char *mangle_ass(const char *in) if (*in == '{') res = talloc_strdup_append_buffer(res, "\\"); res = talloc_strndup_append_buffer(res, in, 1); + // Break ASS escapes with U+2060 WORD JOINER + if (*in == '\\') + append_utf8_buffer(res, 0x2060); in++; } return res; -- cgit v1.2.3