From 84c71fb2e42aedacc208939ddbdf4dd39e071502 Mon Sep 17 00:00:00 2001 From: Ruk Doe Date: Sat, 10 Oct 2026 12:09:03 +0900 Subject: [PATCH] avcodec/libaribcaption: only clear on CS in text and ass mode The text and ass paths treated every caption without regions as a clear and emitted an empty ("") subtitle. A statement containing only TIME also decodes to zero regions, without the clear-screen flag, so it erased the caption that was being displayed. Test ARIBCC_CAPTIONFLAGS_CLEARSCREEN as the bitmap path already does, and emit nothing for other regionless captions. Add text and ass mode tests on the existing aribcaption_clear.ts sample (visible caption, TIME-only statement, CS-only statement). Each reference has two events; before this change there was a third, empty one for the TIME-only statement. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DdDiDRusmi6eD7qSrKBjHb --- libavcodec/libaribcaption.c | 14 +++++++++++++- tests/fate/subtitles.mak | 8 ++++++++ tests/ref/fate/sub-aribcaption-clear-ass | 14 ++++++++++++++ tests/ref/fate/sub-aribcaption-clear-text | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/sub-aribcaption-clear-ass create mode 100644 tests/ref/fate/sub-aribcaption-clear-text diff --git a/libavcodec/libaribcaption.c b/libavcodec/libaribcaption.c index 9bad475f57..b8b5ad8a47 100644 --- a/libavcodec/libaribcaption.c +++ b/libavcodec/libaribcaption.c @@ -618,13 +618,19 @@ static int aribcaption_trans_ass_subtitle(ARIBCaptionContext *ctx) if (ctx->avctx->profile == AV_PROFILE_ARIB_PROFILE_C) single_rect = true; - sub->format = 1; /* text */ if (ctx->caption.region_count == 0) { + /* Only an explicit clear screen (CS) erases the previous caption; + a statement containing only TIME also has no region. */ + if (!(ctx->caption.flags & ARIBCC_CAPTIONFLAGS_CLEARSCREEN)) + return 0; /* clear previous caption for indefinite duration */ + sub->format = 1; /* text */ ff_ass_add_rect(sub, "", ctx->readorder++, 0, NULL, NULL); return 1; } + sub->format = 1; /* text */ + av_bprint_init(&buf, ARIBC_BPRINT_SIZE_INIT, ARIBC_BPRINT_SIZE_MAX); if (single_rect && ctx->avctx->profile != AV_PROFILE_ARIB_PROFILE_C) { @@ -814,6 +820,12 @@ static int aribcaption_trans_text_subtitle(ARIBCaptionContext *ctx) int ret = 0; const char *text; + /* Only an explicit clear screen (CS) erases the previous caption; + a statement containing only TIME also has no region. */ + if (ctx->caption.region_count == 0 && + !(ctx->caption.flags & ARIBCC_CAPTIONFLAGS_CLEARSCREEN)) + return 0; + sub->rects = av_calloc(1, sizeof(*sub->rects)); if (!sub->rects) { ret = AVERROR(ENOMEM); diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak index 200125f718..7dbc8b8316 100644 --- a/tests/fate/subtitles.mak +++ b/tests/fate/subtitles.mak @@ -172,6 +172,14 @@ FATE_SUBTITLES_PROBE-$(call DEMDEC, MPEGTS, LIBARIBCAPTION) += fate-sub-aribcapt fate-sub-aribcaption-clear: CMD = probeframes -sub_type bitmap $(TARGET_SAMPLES)/sub/aribcaption_clear.ts fate-sub-aribcaption-clear: CMP = diff +# same sample in text and ass mode: only CS must emit a clear event, which +# the ass dialogue shows as an empty text +FATE_SUBTITLES_PROBE-$(call DEMDEC, MPEGTS, LIBARIBCAPTION) += fate-sub-aribcaption-clear-text +fate-sub-aribcaption-clear-text: CMD = probeframes -sub_type text $(TARGET_SAMPLES)/sub/aribcaption_clear.ts +FATE_SUBTITLES_ASS-$(call DEMDEC, MPEGTS, LIBARIBCAPTION) += fate-sub-aribcaption-clear-ass +fate-sub-aribcaption-clear-ass: CMD = fmtstdout ass -sub_type ass -font sans-serif -i $(TARGET_SAMPLES)/sub/aribcaption_clear.ts +fate-sub-aribcaption-clear-text fate-sub-aribcaption-clear-ass: CMP = diff + FATE_SUBTITLES-$(call ENCMUX, ASS, ASS) += $(FATE_SUBTITLES_ASS-yes) FATE_SUBTITLES += $(FATE_SUBTITLES-yes) FATE_SUBTITLES := $(if $(CONFIG_PIPE_PROTOCOL), $(FATE_SUBTITLES)) diff --git a/tests/ref/fate/sub-aribcaption-clear-ass b/tests/ref/fate/sub-aribcaption-clear-ass new file mode 100644 index 0000000000..eaa595fd0b --- /dev/null +++ b/tests/ref/fate/sub-aribcaption-clear-ass @@ -0,0 +1,14 @@ +[Script Info] +ScriptType: v4.00+ +PlayResX: 960 +PlayResY: 540 +WrapStyle: 2 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Default,sans-serif,36,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,4,0,4,2,10,10,10,0 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:01.00,9:59:59.99,Default,,0,0,0,,{\an7}{\pos(200,300)}{\fsp4}{\3a&Hff&}{\4a&Hff&}〓 +Dialogue: 0,0:00:03.00,9:59:59.99,Default,,0,0,0,, diff --git a/tests/ref/fate/sub-aribcaption-clear-text b/tests/ref/fate/sub-aribcaption-clear-text new file mode 100644 index 0000000000..caa0d942b9 --- /dev/null +++ b/tests/ref/fate/sub-aribcaption-clear-text @@ -0,0 +1,18 @@ +[SUBTITLE] +media_type=subtitle +pts=2000000 +pts_time=2.000000 +format=1 +start_display_time=0 +end_display_time=4294967295 +num_rects=1 +[/SUBTITLE] +[SUBTITLE] +media_type=subtitle +pts=4000000 +pts_time=4.000000 +format=1 +start_display_time=0 +end_display_time=4294967295 +num_rects=1 +[/SUBTITLE]