Skip to content

Commit

Permalink
sd_ass: introduce sub-ass-prune-delay
Browse files Browse the repository at this point in the history
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 libass/libass@dcc9eb7
  • Loading branch information
llyyr committed Nov 3, 2024
1 parent aa66f0d commit caca230
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DOCS/interface-changes/sub-ass-prune-delay.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add `sub-ass-prune-delay` option to control libass automatica pruning of past
events
16 changes: 16 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<filename>``
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
Expand Down
2 changes: 2 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions sub/sd_ass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit caca230

Please sign in to comment.