PR #24067 opened by 5ym
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24067
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24067.patch

An ARIB caption statement whose data units contain only CS (clear screen)
decodes to a caption with region_count == 0.  In SUBTITLE_TEXT mode this is
translated into a rect holding "" so that the previous caption is erased.
In SUBTITLE_BITMAP mode nothing is rendered, the function returns 0 and
*got_sub_ptr is left at 0, so the caller never learns that the caption ended.

Broadcasters send such a statement at the end of every caption segment (for
example when going to a commercial break).  Combined with wait_duration ==
ARIBCC_DURATION_INDEFINITE, which maps to end_display_time = UINT32_MAX, the
last caption of a segment stays on screen until the next one arrives - in a
real recording that was 22 minutes later.

Report an empty subtitle (num_rects = 0) in that case, which sub2video and
the usual subtitle consumers already treat as "erase".

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From db032398dd3ba29ecda20ad48f722cf72498dc15 Mon Sep 17 00:00:00 2001
From: Ruk Doe <[email protected]>
Date: Mon, 10 Aug 2026 13:42:57 +0900
Subject: [PATCH] libaribcaption: emit an empty subtitle for an explicit clear
 in BITMAP mode

An ARIB caption statement whose data units contain only CS (clear screen)
decodes to a caption with region_count == 0.  In SUBTITLE_TEXT mode this is
translated into a rect holding "" so that the previous caption is erased.
In SUBTITLE_BITMAP mode nothing is rendered, the function returns 0 and
*got_sub_ptr is left at 0, so the caller never learns that the caption ended.

Broadcasters send such a statement at the end of every caption segment (for
example when going to a commercial break).  Combined with wait_duration ==
ARIBCC_DURATION_INDEFINITE, which maps to end_display_time = UINT32_MAX, the
last caption of a segment stays on screen until the next one arrives - in a
real recording that was 22 minutes later.

Report an empty subtitle (num_rects = 0) in that case, which sub2video and
the usual subtitle consumers already treat as "erase".
---
 libavcodec/libaribcaption.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavcodec/libaribcaption.c b/libavcodec/libaribcaption.c
index 66d18b9d38..739e048842 100644
--- a/libavcodec/libaribcaption.c
+++ b/libavcodec/libaribcaption.c
@@ -360,6 +360,14 @@ static int 
aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx)
 
     case ARIBCC_RENDER_STATUS_NO_IMAGE:
         ff_dlog(ctx, "no image\n");
+        /* A caption carrying no region is an explicit clear screen (CS).
+           Report an empty subtitle so that the previously displayed bitmap
+           is erased; the TEXT path already does this by emitting "". */
+        if (ctx->caption.region_count == 0) {
+            sub->format = 0; /* graphic */
+            sub->num_rects = 0;
+            return 1;
+        }
         return 0;
 
     case ARIBCC_RENDER_STATUS_ERROR:
@@ -377,6 +385,11 @@ static int 
aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx)
     if (!ctx->render_result.image_count || ctx->render_result.images == NULL) {
         aribcc_render_result_cleanup(&ctx->render_result);
         ff_dlog(ctx, "no image (%d)\n", ctx->render_result.image_count);
+        if (ctx->caption.region_count == 0) {
+            sub->format = 0; /* graphic */
+            sub->num_rects = 0;
+            return 1;
+        }
         return 0;
     }
 
-- 
2.52.0

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

Reply via email to