Commit 9a4111b1e0 for ffmpeg
commit 9a4111b1e0604fb0bbb78387b69f02030424fc3a
Author: Ruk Doe <info@doany.io>
Date: Mon Aug 10 13:42:57 2026 +0900
avcodec/libaribcaption: emit empty subtitle on clear in bitmap mode
An ARIB caption statement whose data units contain only CS (clear screen)
decodes to a caption with the ARIBCC_CAPTIONFLAGS_CLEARSCREEN flag set and
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) when the clear-screen flag is set,
which sub2video and the usual subtitle consumers already treat as "erase".
The flag is tested instead of region_count == 0 because a statement
containing only TIME also decodes to zero regions but must not erase the
currently displayed caption.
diff --git a/libavcodec/libaribcaption.c b/libavcodec/libaribcaption.c
index 66d18b9d38..e8f7cada73 100644
--- a/libavcodec/libaribcaption.c
+++ b/libavcodec/libaribcaption.c
@@ -310,7 +310,7 @@ static void clut_init(ARIBCaptionContext *ctx, aribcc_caption_region_t *region)
* Transfer decoded subtitle to AVSubtitle with corresponding subtitle type.
*
* @param ctx pointer to the ARIBCaptionContext
- * @return > 0 number of rectangles to be displayed
+ * @return > 0 subtitle event produced (possibly with zero rectangles for clear)
* = 0 no subtitle
* < 0 error code
*/
@@ -360,6 +360,17 @@ static int aribcaption_trans_bitmap_subtitle(ARIBCaptionContext *ctx)
case ARIBCC_RENDER_STATUS_NO_IMAGE:
ff_dlog(ctx, "no image\n");
+ /* A caption carrying an explicit clear screen (CS) produces no
+ image. Report an empty subtitle so that the previously displayed
+ bitmap is erased; the TEXT path already does this by emitting "".
+ Do not treat every regionless caption as a clear: a statement
+ containing only TIME also decodes to zero regions but must not
+ erase the display. */
+ if (ctx->caption.flags & ARIBCC_CAPTIONFLAGS_CLEARSCREEN) {
+ sub->format = 0; /* graphic */
+ sub->num_rects = 0;
+ return 1;
+ }
return 0;
case ARIBCC_RENDER_STATUS_ERROR:
@@ -377,6 +388,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.flags & ARIBCC_CAPTIONFLAGS_CLEARSCREEN) {
+ sub->format = 0; /* graphic */
+ sub->num_rects = 0;
+ return 1;
+ }
return 0;
}