1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-19 13:21:13 +00:00

sub: workaround braindead libass API

libass won't use embedded fonts, unless ass_set_fonts() (called by
mp_ass_configure_fonts()) is called. However, we call this function when
the ASS_Renderer is initialized, which is long before the .ass file is
actually loaded. (I'm not sure why it tries to keep 1 ASS_Renderer, but
it always did this.)

Fix by calling mp_ass_configure_fonts() after loading them. This also
means this function will be called multiple times - hopefully this is
harmless (it will reinit fontconfig every time, though).

While we're at it, also initialize the ASS_Renderer lazily.

Fixes #1244.
This commit is contained in:
wm4 2014-11-15 19:43:43 +01:00
parent a6694d2788
commit 2125e49422
3 changed files with 14 additions and 10 deletions

View File

@ -468,7 +468,6 @@ void uninit_sub(struct MPContext *mpctx, int order);
void uninit_sub_all(struct MPContext *mpctx);
void update_osd_msg(struct MPContext *mpctx);
void update_subtitles(struct MPContext *mpctx);
void init_sub_renderer(struct MPContext *mpctx);
void uninit_sub_renderer(struct MPContext *mpctx);
void get_osd_sub_state(struct MPContext *mpctx, int order,
struct osd_sub_state *out_state);

View File

@ -1079,8 +1079,6 @@ goto_reopen_demuxer: ;
"Displaying attached picture. Use --no-audio-display to prevent this.\n");
}
init_sub_renderer(mpctx);
#if HAVE_ENCODING
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_VIDEO])
encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_VIDEO);

View File

@ -92,11 +92,12 @@ static void add_subtitle_fonts_from_sources(struct MPContext *mpctx)
}
}
void init_sub_renderer(struct MPContext *mpctx)
static void init_sub_renderer(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
uninit_sub_renderer(mpctx);
if (mpctx->ass_renderer)
return;
if (!mpctx->ass_log)
mpctx->ass_log = mp_log_new(mpctx, mpctx->global->log, "!libass");
@ -109,10 +110,6 @@ void init_sub_renderer(struct MPContext *mpctx)
ass_set_style_overrides(mpctx->ass_library, opts->ass_force_style_list);
mpctx->ass_renderer = ass_renderer_init(mpctx->ass_library);
if (mpctx->ass_renderer) {
mp_ass_configure_fonts(mpctx->ass_renderer, opts->sub_text_style,
mpctx->global, mpctx->ass_log);
}
}
void uninit_sub_renderer(struct MPContext *mpctx)
@ -127,9 +124,12 @@ void uninit_sub_renderer(struct MPContext *mpctx)
#else /* HAVE_LIBASS */
void init_sub_renderer(struct MPContext *mpctx) {}
static void init_sub_renderer(struct MPContext *mpctx) {}
void uninit_sub_renderer(struct MPContext *mpctx) {}
void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts,
struct mp_osd_res *dim) {}
#endif
void uninit_stream_sub_decoders(struct demuxer *demuxer)
@ -306,11 +306,18 @@ static void reinit_subdec(struct MPContext *mpctx, struct track *track,
int h = sh_video ? sh_video->disp_h : 0;
float fps = sh_video ? sh_video->fps : 25;
init_sub_renderer(mpctx);
sub_set_video_res(dec_sub, w, h);
sub_set_video_fps(dec_sub, fps);
sub_set_ass_renderer(dec_sub, mpctx->ass_library, mpctx->ass_renderer);
sub_init_from_sh(dec_sub, track->stream);
if (mpctx->ass_renderer) {
mp_ass_configure_fonts(mpctx->ass_renderer, opts->sub_text_style,
mpctx->global, mpctx->ass_log);
}
// Don't do this if the file has video/audio streams. Don't do it even
// if it has only sub streams, because reading packets will change the
// demuxer position.