PR #25998 opened by Baptiste Coudurier (bcoudurier) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25998 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25998.patch
CCFifo queues were fixed at 128 tuples and `av_fifo_write()` failures were ignored, so captions were silently dropped once a filter queued more than that. This shows up with a deep `vpp_qsv` `async_depth` once captions are carried through the CCFifo (see https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25889, ~20 tuples per 29.97i frame). - Allocate both queues with `AV_FIFO_FLAG_AUTO_GROW`, starting at 128 and capped at 6000 tuples (10 s at the maximum CEA-708 rate of 600 tuples/s). - Check `av_fifo_write()`, warn once when a queue is full and return the error. Tested: FATE yadif/bwdif/fps/sub-cc tests pass; a direct check queuing 1000 tuples before injecting delivers 1000/1000 (228 before). 🤖 Generated with [Claude Code](https://claude.com/claude-code) From 5c1ebcc582f348993decf6bb6b72482d18072cfb Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Thu, 12 Nov 2026 14:04:14 -0800 Subject: [PATCH] avfilter/ccfifo: grow the caption queues instead of dropping tuples Let the queues grow up to 10 seconds of captions and warn when full. Captions were lost with a deep vpp_qsv async_depth, see https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/25889 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Baptiste Coudurier <[email protected]> --- libavfilter/ccfifo.c | 30 +++++++++++++++++++++++------- libavfilter/ccfifo.h | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libavfilter/ccfifo.c b/libavfilter/ccfifo.c index d76dbff149e..96ae6dbd64c 100644 --- a/libavfilter/ccfifo.c +++ b/libavfilter/ccfifo.c @@ -25,6 +25,9 @@ #include "libavutil/fifo.h" #define MAX_CC_ELEMENTS 128 +/* CEA-708 carries at most 600 cc_data tuples per second (cc_count 20 at + 30 fps), so this bounds each queue to 10 seconds of captions. */ +#define MAX_CC_ELEMENTS_LIMIT (600 * 10) struct cc_lookup { int num; @@ -58,12 +61,17 @@ int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx) ccf->log_ctx = log_ctx; ccf->framerate = framerate; - if (!(ccf->cc_708_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS, CC_BYTES_PER_ENTRY, 0))) + if (!(ccf->cc_708_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS, CC_BYTES_PER_ENTRY, + AV_FIFO_FLAG_AUTO_GROW))) goto error; - if (!(ccf->cc_608_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS, CC_BYTES_PER_ENTRY, 0))) + if (!(ccf->cc_608_fifo = av_fifo_alloc2(MAX_CC_ELEMENTS, CC_BYTES_PER_ENTRY, + AV_FIFO_FLAG_AUTO_GROW))) goto error; + av_fifo_auto_grow_limit(ccf->cc_708_fifo, MAX_CC_ELEMENTS_LIMIT); + av_fifo_auto_grow_limit(ccf->cc_608_fifo, MAX_CC_ELEMENTS_LIMIT); + /* Based on the target FPS, figure out the expected cc_count and number of 608 tuples per packet. See ANSI/CTA-708-E Sec 4.3.6.1. */ for (i = 0; i < FF_ARRAY_ELEMS(cc_lookup_vals); i++) { @@ -154,6 +162,7 @@ int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame) int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *cc_bytes, size_t len) { int cc_count = len / CC_BYTES_PER_ENTRY; + int err = 0; if (ccf->passthrough == 1) { av_log_once(ccf->log_ctx, AV_LOG_WARNING, AV_LOG_DEBUG, &ccf->passthrough_warning, @@ -168,13 +177,19 @@ int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *cc_bytes, size_t len) /* See ANSI/CTA-708-E Sec 4.3, Table 3 */ uint8_t cc_valid = (cc_bytes[CC_BYTES_PER_ENTRY*i] & 0x04) >> 2; uint8_t cc_type = cc_bytes[CC_BYTES_PER_ENTRY*i] & 0x03; + int ret = 0; if (cc_type == 0x00 || cc_type == 0x01) { - av_fifo_write(ccf->cc_608_fifo, &cc_bytes[CC_BYTES_PER_ENTRY*i], 1); + ret = av_fifo_write(ccf->cc_608_fifo, &cc_bytes[CC_BYTES_PER_ENTRY*i], 1); } else if (cc_valid && (cc_type == 0x02 || cc_type == 0x03)) { - av_fifo_write(ccf->cc_708_fifo, &cc_bytes[CC_BYTES_PER_ENTRY*i], 1); + ret = av_fifo_write(ccf->cc_708_fifo, &cc_bytes[CC_BYTES_PER_ENTRY*i], 1); + } + if (ret < 0) { + av_log_once(ccf->log_ctx, AV_LOG_WARNING, AV_LOG_DEBUG, &ccf->overflow_warning, + "cc_fifo full, dropping captions\n"); + err = ret; } } - return 0; + return err; } /* Read the A53 side data, discard padding, and put 608/708 into @@ -183,13 +198,14 @@ int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *cc_bytes, size_t len) int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame) { AVFrameSideData *side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC); + int ret = 0; if (side_data) { - ff_ccfifo_extractbytes(ccf, side_data->data, side_data->size); + ret = ff_ccfifo_extractbytes(ccf, side_data->data, side_data->size); /* Remove the side data, as we will re-create it on the output as needed */ if (!ccf->passthrough) av_frame_remove_side_data(frame, AV_FRAME_DATA_A53_CC); } - return 0; + return ret; } diff --git a/libavfilter/ccfifo.h b/libavfilter/ccfifo.h index d3f8a52cc18..9d9a10d7cc7 100644 --- a/libavfilter/ccfifo.h +++ b/libavfilter/ccfifo.h @@ -46,6 +46,7 @@ typedef struct CCFifo { int cc_detected; int passthrough; int passthrough_warning; + int overflow_warning; void *log_ctx; } CCFifo; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
