From ad5c00b0ce43c6c5bc4c2677699fb2876bf58379 Mon Sep 17 00:00:00 2001 From: Ruk Doe Date: Sat, 10 Oct 2026 15:05:16 +0900 Subject: [PATCH] avcodec/libaribcaption: keep the clear when ass mode skips every region as ruby With ignore_ruby=1 and ass_single_rect=0, a caption whose regions are all ruby skips every region and returned no event, even when it carries a clear screen (CS). The previous caption then stayed on screen. The bitmap path and ass_single_rect=1 already erase it in that case. Emit the empty clear event in that case too. Such captions do occur in broadcasts: among 2293 captions from 40 recent Japanese TV recordings, 3 carried CS with only ruby regions. With this change, ignore_ruby=1 output gains exactly those 3 clear events, and output with the default options is unchanged for all 40 recordings. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01DdDiDRusmi6eD7qSrKBjHb --- libavcodec/libaribcaption.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavcodec/libaribcaption.c b/libavcodec/libaribcaption.c index b9a7c2ff80..3e930d68a0 100644 --- a/libavcodec/libaribcaption.c +++ b/libavcodec/libaribcaption.c @@ -781,6 +781,15 @@ static int aribcaption_trans_ass_subtitle(ARIBCaptionContext *ctx) rect_idx++; } } + if (!single_rect && !rect_idx) { + /* Every region was skipped as ruby. A clear screen (CS) must still + erase the previous caption. */ + av_bprint_finalize(&buf, NULL); + if (!(ctx->caption.flags & ARIBCC_CAPTIONFLAGS_CLEARSCREEN)) + return 0; + ret = ff_ass_add_rect(sub, "", ctx->readorder++, 0, NULL, NULL); + return ret < 0 ? ret : 1; + } if (single_rect) { if (!av_bprint_is_complete(&buf)) { ret = AVERROR(ENOMEM);