From 77239b87f1e72a3d24bbc6333b3508606545f7d9 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Mon, 14 Oct 2024 16:40:01 -0500 Subject: [PATCH] sub/sd_ass: handle subs with unknown durations on a per packet basis A packet with an unknown duration flagged the entire context and then this was saved forever throughout the entire lifetime of the object. This inherently doesn't work with the redecoding sub logic which will go through all the packets again. So the second time around, packets with known durations get treated as if they were unknown and things go awry. Rework this so it is per packet like it should be and not a global state. Note that f9cefbfec4d7bfec44991d4372aad4fc1b3167a5 originally added this for specifically eia-608 subtitles but their packets are all detected as unknown anyway due to the durations so this is not needed anymore and interferes with other things. --- sub/sd_ass.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 47b3109ec7..46327e14a6 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -60,7 +60,6 @@ struct sd_ass_priv { int *packets_animated; int num_packets_animated; bool check_animated; - bool duration_unknown; }; struct seen_packet { @@ -275,9 +274,6 @@ static int init(struct sd *sd) ctx->converter = lavc_conv_create(sd); if (!ctx->converter) return -1; - - if (strcmp(sd->codec->codec, "eia_608") == 0) - ctx->duration_unknown = 1; } assobjects_init(sd); @@ -433,10 +429,7 @@ static void decode(struct sd *sd, struct demux_packet *packet) &sub_duration); if (sd->opts->sub_stretch_durations || packet->duration < 0 || sub_duration == UINT32_MAX) { - if (!ctx->duration_unknown) { - MP_VERBOSE(sd, "Subtitle with unknown duration.\n"); - ctx->duration_unknown = true; - } + MP_VERBOSE(sd, "Subtitle with unknown duration.\n"); sub_duration = UNKNOWN_DURATION; } @@ -449,7 +442,7 @@ static void decode(struct sd *sd, struct demux_packet *packet) }; filter_and_add(sd, &pkt2); } - if (ctx->duration_unknown) { + if (sub_duration == UNKNOWN_DURATION) { for (int n = track->n_events - 2; n >= 0; n--) { if (track->events[n].Duration == UNKNOWN_DURATION * 1000) { if (track->events[n].Start != track->events[n + 1].Start) {