PR #23132 opened by arch1t3cht
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23132
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23132.patch

Subtitle events with negative duration may be generated by some
authoring script like karoke templates, and are simply treated as hidden
by renderers.

Parsing such subtitle events normally will cause the negative duration
to get mangled by ff_subtitles_queue_finalize() and later
compute_pkt_fields(), causing rendering differences.

Hence, treat such events like comments instead by adding them to the
header so that they are preserved during remuxes, albeit in a different
order.

Signed-off-by: arch1t3cht <[email protected]>

---

Addresses the same issue ( https://github.com/mpv-player/mpv/issues/17935 ) as 
#23131 , me and llyyr started working on a fix simultaneously. Personally, I 
prefer this change since it still preserves such events on a remux, just like 
other non-dialogue entries like comments, Aegisub Project Garbage, or Aegisub 
Extradata are.


>From 11dcb86c4015c7caa33d700040cc6f44416f040d Mon Sep 17 00:00:00 2001
From: arch1t3cht <[email protected]>
Date: Sun, 17 May 2026 18:28:05 +0200
Subject: [PATCH] avformat/assdec: Treat negative-duration events as comments

Subtitle events with negative duration may be generated by some
authoring script like karoke templates, and are simply treated as hidden
by renderers.

Parsing such subtitle events normally will cause the negative duration
to get mangled by ff_subtitles_queue_finalize() and later
compute_pkt_fields(), causing rendering differences.

Hence, treat such events like comments instead by adding them to the
header so that they are preserved during remuxes, albeit in a different
order.

Signed-off-by: arch1t3cht <[email protected]>
---
 libavformat/assdec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/assdec.c b/libavformat/assdec.c
index 3a8353f4d3..2a9a87c2c9 100644
--- a/libavformat/assdec.c
+++ b/libavformat/assdec.c
@@ -72,6 +72,9 @@ static int read_dialogue(ASSContext *ass, AVBPrint *dst, 
const uint8_t *p,
         *start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
         *duration = end - *start;
 
+        if (*duration < 0)
+            return -1;
+
         av_bprint_clear(dst);
         av_bprintf(dst, "%u,%d,%s", ass->readorder++, layer, p + pos);
         if (!av_bprint_is_complete(dst))
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to