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 0000000000000..102bc17a037fb --- /dev/null +++ b/DOCS/interface-changes/sub-ass-prune-delay.txt @@ -0,0 +1,2 @@ +add `sub-ass-prune-delay` option to control libass automatica pruning of past +events diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index f2aa576ecaf49..693d62e4cd61f 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 dab194d6c5c43..7f35deb9e739d 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 8e9eee7de667d..afbbab92b5be3 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 46327e14a6ce0..9b3fc07caf472 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); }