From 59fc8eecbc08d22368451b31fcf799aec557ab0d Mon Sep 17 00:00:00 2001 From: VincentVerdynanta Date: Thu, 8 Sep 2022 16:45:31 +0800 Subject: [PATCH] sd_ass: improve handling of subtitles with unknown duration Commit 740b701 introduced handling for subtitles with unknown duration, but it came with a minor flaw where a track event that shares identical start time with following track event will has its Duration value set to 0, we don't want this to happen since it will prevent simultaneous rendering of multiple track events. This commit aims to address this issue. --- sub/sd_ass.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 765b77822d..d7b1e479b7 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -359,10 +359,14 @@ static void decode(struct sd *sd, struct demux_packet *packet) filter_and_add(sd, &pkt2); } if (ctx->duration_unknown) { - for (int n = 0; n < track->n_events - 1; n++) { + for (int n = track->n_events - 2; n >= 0; n--) { if (track->events[n].Duration == UNKNOWN_DURATION * 1000) { - track->events[n].Duration = track->events[n + 1].Start - - track->events[n].Start; + if (track->events[n].Start != track->events[n + 1].Start) { + track->events[n].Duration = track->events[n + 1].Start - + track->events[n].Start; + } else { + track->events[n].Duration = track->events[n + 1].Duration; + } } } }