From 22116734e774a82dc5771c34f07a15924288407e Mon Sep 17 00:00:00 2001 From: llyyr Date: Wed, 30 Oct 2024 17:44:42 +0530 Subject: [PATCH] sd_ass: introduce sub-ass-prune-delay Disabled by default because it breaks sub-seek and playback in cases where the user changes play-dir from + to - during runtime and past "seen" events need to be re-rendered. Available since https://github.com/libass/libass/commit/dcc9eb722ebd485d2ed0e21c261b0a1b05497154 --- DOCS/interface-changes/sub-ass-prune-delay.txt | 2 ++ DOCS/man/options.rst | 16 ++++++++++++++++ options/options.c | 2 ++ options/options.h | 1 + sub/sd_ass.c | 4 ++++ 5 files changed, 25 insertions(+) create mode 100644 DOCS/interface-changes/sub-ass-prune-delay.txt diff --git a/DOCS/interface-changes/sub-ass-prune-delay.txt b/DOCS/interface-changes/sub-ass-prune-delay.txt new file mode 100644 index 0000000000..78c3a33ec9 --- /dev/null +++ b/DOCS/interface-changes/sub-ass-prune-delay.txt @@ -0,0 +1,2 @@ +add `sub-ass-prune-delay` option to control libass automatic pruning of past +events diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index a570991bdf..6c2f7e4e21 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2533,6 +2533,22 @@ Subtitles ``complex`` is the default. If libass hasn't been compiled against HarfBuzz, libass silently reverts to ``simple``. +``--sub-ass-prune-delay=<-1|seconds>`` + Set the delay for automatic pruning of events from memory in libass. When + enabled, subtitle events are removed from memory once their end timestamp is + older than the specified delay. + + :-1: disables automatic pruning (default). + :seconds: specify how many seconds after an event is no longer displayed + should the pruning occur. ``0`` prunes events as soon as they're + off screen. + + .. note:: + + This breaks sub-seek and subtitle rendering when changing play-direction + from forward to backward during runtime for events that were already + "seen" and need to be rendered again, if those events got pruned. + ``--sub-ass-styles=`` Load all SSA/ASS styles found in the specified file and use them for rendering text subtitles. The syntax of the file is exactly like the ``[V4 diff --git a/options/options.c b/options/options.c index 3a704f005a..c0c9da158c 100644 --- a/options/options.c +++ b/options/options.c @@ -336,6 +336,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { {"none", 0}, {"light", 1}, {"normal", 2}, {"native", 3})}, {"sub-ass-shaper", OPT_CHOICE(ass_shaper, {"simple", 0}, {"complex", 1})}, + {"sub-ass-prune-delay", OPT_DOUBLE(ass_prune_delay), M_RANGE(-1.0, DBL_MAX)}, {"sub-ass-justify", OPT_BOOL(ass_justify)}, {"sub-scale-by-window", OPT_BOOL(sub_scale_by_window)}, {"sub-scale-with-window", OPT_BOOL(sub_scale_with_window)}, @@ -355,6 +356,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { .sub_scale_by_window = true, .sub_use_margins = true, .sub_scale_with_window = true, + .ass_prune_delay = -1.0, .teletext_page = 0, .sub_scale = 1, .ass_vsfilter_color_compat = 1, diff --git a/options/options.h b/options/options.h index 35354f07f9..347746f7c8 100644 --- a/options/options.h +++ b/options/options.h @@ -118,6 +118,7 @@ struct mp_subtitle_opts { char *ass_styles_file; int ass_hinting; int ass_shaper; + double ass_prune_delay; bool ass_justify; bool sub_clear_on_seek; int teletext_page; diff --git a/sub/sd_ass.c b/sub/sd_ass.c index c01b7af720..2d837e8bf7 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -247,6 +247,10 @@ static void assobjects_init(struct sd *sd) ass_set_check_readorder(ctx->ass_track, sd->opts->sub_clear_on_seek ? 0 : 1); #endif +#if LIBASS_VERSION >= 0x01703010 + ass_configure_prune(ctx->ass_track, sd->opts->ass_prune_delay * 1000.0); +#endif + enable_output(sd, true); }