PR #24118 opened by AYOUB NABIL BOUBAGRAT (ayoubnabil) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24118 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24118.patch
when decoder outputs sharing a demuxer are throttled, the scheduler must keep accepting packets for the other decoders. the overflow fifo used the generic auto-grow limit, and reaching it returned ENOSPC. ffmpeg_dec then treated that scheduler error as EOF, silently truncating the affected stream while the other streams continued. a finite packet limit cannot provide a meaningful memory bound, while applying backpressure would also block the other decoders sharing the same demuxer. remove the packet-count limit from the decoder overflow fifo, propagate scheduler receive errors, and add a regression test that exceeds the old limit. this fixes the premature eof reported in #24008 and #23988. tested with the regression test and the original 600-second sample from #24008. >From 6d4c0cef2ef706f0e7c2589a1dcd9107f6acfa91 Mon Sep 17 00:00:00 2001 From: Ayoub Nabil Boubagrat <[email protected]> Date: Wed, 12 Aug 2026 22:24:35 +0200 Subject: [PATCH 1/3] avutil/container_fifo: add auto-grow limit setter Signed-off-by: Ayoub Nabil Boubagrat <[email protected]> --- doc/APIchanges | 3 +++ libavutil/container_fifo.c | 5 +++++ libavutil/container_fifo.h | 6 ++++++ libavutil/version.h | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 61e0d43735..9489f094b4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -7,6 +7,9 @@ API changes, most recent first: descriptors as bare metadata tag names is now opt-in through this flag, only the <tag>-<description>-<lang> tag is exported by default. +2026-08-12 - xxxxxxxxxx - lavu 61.6.100 - container_fifo.h + Add av_container_fifo_auto_grow_limit(). + 2026-07-04 - xxxxxxxxxx - lavc 63.7.100 - codec_id.h Add AV_CODEC_ID_PCM_DVDA. diff --git a/libavutil/container_fifo.c b/libavutil/container_fifo.c index 34a78e7ef3..1e6bde9a4c 100644 --- a/libavutil/container_fifo.c +++ b/libavutil/container_fifo.c @@ -98,6 +98,11 @@ fail: return NULL; } +void av_container_fifo_auto_grow_limit(AVContainerFifo *cf, size_t max_elems) +{ + av_fifo_auto_grow_limit(cf->fifo, max_elems); +} + void av_container_fifo_free(AVContainerFifo **pcf) { AVContainerFifo *cf; diff --git a/libavutil/container_fifo.h b/libavutil/container_fifo.h index ff9249311f..a9a4bb93c3 100644 --- a/libavutil/container_fifo.h +++ b/libavutil/container_fifo.h @@ -76,6 +76,12 @@ av_container_fifo_alloc(void *opaque, */ AVContainerFifo *av_container_fifo_alloc_avframe(unsigned flags); +/** + * Set the maximum size (in objects) to which the FIFO can be resized + * automatically. + */ +void av_container_fifo_auto_grow_limit(AVContainerFifo *cf, size_t max_elems); + /** * Free a AVContainerFifo and everything in it. */ diff --git a/libavutil/version.h b/libavutil/version.h index d5bf20cf89..94b5e920b9 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 61 -#define LIBAVUTIL_VERSION_MINOR 5 +#define LIBAVUTIL_VERSION_MINOR 6 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- 2.52.0 >From 7d6a2efcb83f882cf98b0830da720981e5ee6c0e Mon Sep 17 00:00:00 2001 From: Ayoub Nabil Boubagrat <[email protected]> Date: Wed, 12 Aug 2026 22:24:45 +0200 Subject: [PATCH 2/3] fftools/ffmpeg_sched: remove decoder overflow queue limit decoders sharing a demuxer must keep accepting packets when one output is throttled. applying backpressure there would also block packets for the other decoders. the generic packet-count limit returned ENOSPC on valid long inputs. it did not provide a meaningful memory bound because packet sizes vary. allow the overflow fifo to grow until allocation failure and add a regression test that exceeds the old limit. Signed-off-by: Ayoub Nabil Boubagrat <[email protected]> --- fftools/ffmpeg_sched.c | 6 ++ tests/fate/ffmpeg.mak | 13 ++++ tests/filtergraphs/decoder-overflow | 4 ++ tests/ref/fate/ffmpeg-decoder-overflow | 83 ++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 tests/filtergraphs/decoder-overflow create mode 100644 tests/ref/fate/ffmpeg-decoder-overflow diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index 88b3bf3177..b751552fa9 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -821,6 +821,12 @@ int sch_add_dec(Scheduler *sch, SchThreadFunc func, void *ctx, int send_end_ts) if (!dec->overflow) return AVERROR(ENOMEM); + // decoders feeding the same demuxer must keep accepting packets when one + // of them is throttled. a finite packet limit would reject valid inputs + // based on duration and packet rate without providing a meaningful memory + // bound, since packet sizes vary. let allocation failure be the limit + av_container_fifo_auto_grow_limit(dec->overflow, SIZE_MAX); + ret = waiter_init(&dec->waiter); if (ret < 0) return ret; diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index ad8e5c775f..5104c4f1d6 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -5,6 +5,19 @@ fate-ffmpeg-filter_complex: CMD = framecrc -filter_complex color=d=1:r=5 -fflags FATE_FFMPEG-$(call FILTERFRAMECRC, AEVALSRC ASETNSAMPLES ARESAMPLE, AC3_FIXED_ENCODER) += fate-ffmpeg-filter_complex_audio fate-ffmpeg-filter_complex_audio: CMD = framecrc -auto_conversion_filters -filter_complex "aevalsrc=0:d=0.1,asetnsamples=1537" -c ac3_fixed +# 288000 one-sample audio packets exceed the container FIFO's default +# auto-growth limit on both 32-bit and 64-bit builds. +FATE_FFMPEG-$(call ALLYES, LAVFI_INDEV TESTSRC2_FILTER SINE_FILTER ASETNSAMPLES_FILTER \ + TRIM_FILTER ATRIM_FILTER SETPTS_FILTER ASETPTS_FILTER \ + CONCAT_FILTER WRAPPED_AVFRAME_DECODER PCM_S16LE_DECODER \ + RAWVIDEO_ENCODER PCM_S16LE_ENCODER FRAMECRC_MUXER PIPE_PROTOCOL) \ + += fate-ffmpeg-decoder-overflow +fate-ffmpeg-decoder-overflow: tests/data/filtergraphs/decoder-overflow +fate-ffmpeg-decoder-overflow: CMD = ffmpeg -f lavfi \ + -i "testsrc2=s=16x16:r=1/6:d=6[out0];sine=r=48000:d=6,asetnsamples=n=1[out1]" \ + -/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/decoder-overflow \ + -map "[v]" -map "[aout]" -c:v rawvideo -c:a pcm_s16le -f framecrc - + # Ticket 6375, use case of NoX FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, PNG ALAC, ARESAMPLE_FILTER) += fate-ffmpeg-attached_pics fate-ffmpeg-attached_pics: CMD = threads=2 framecrc -i $(TARGET_SAMPLES)/lossless-audio/inside.m4a -threads 1 -max_muxing_queue_size 16 -af aresample diff --git a/tests/filtergraphs/decoder-overflow b/tests/filtergraphs/decoder-overflow new file mode 100644 index 0000000000..7d131d7f54 --- /dev/null +++ b/tests/filtergraphs/decoder-overflow @@ -0,0 +1,4 @@ +[0:v]trim=end=6,setpts=PTS-STARTPTS[v0]; +[0:a]atrim=end=6,asetpts=PTS-STARTPTS[a0]; +[v0][a0]concat=n=1:v=1:a=1[v][a]; +[a]asetnsamples=n=4096:p=0[aout] diff --git a/tests/ref/fate/ffmpeg-decoder-overflow b/tests/ref/fate/ffmpeg-decoder-overflow new file mode 100644 index 0000000000..7d08cf4c93 --- /dev/null +++ b/tests/ref/fate/ffmpeg-decoder-overflow @@ -0,0 +1,83 @@ +#software: Lavf63.6.100 +#tb 0: 6/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 16x16 +#sar 0: 1/1 +#tb 1: 1/48000 +#media_type 1: audio +#codec_id 1: pcm_s16le +#sample_rate 1: 48000 +#channel_layout_name 1: mono +0, 0, 0, 1, 384, 0x92e591ca +1, 0, 0, 4096, 8192, 0xba4ccfdb +1, 4096, 4096, 4096, 8192, 0x0ea8f228 +1, 8192, 8192, 4096, 8192, 0xf215da72 +1, 12288, 12288, 4096, 8192, 0x2566eba1 +1, 16384, 16384, 4096, 8192, 0x9ac0e286 +1, 20480, 20480, 4096, 8192, 0xff28e21e +1, 24576, 24576, 4096, 8192, 0x7f18e7a2 +1, 28672, 28672, 4096, 8192, 0xe2a9dd38 +1, 32768, 32768, 4096, 8192, 0x9466f14b +1, 36864, 36864, 4096, 8192, 0x12edd449 +1, 40960, 40960, 4096, 8192, 0xb176f78e +1, 45056, 45056, 4096, 8192, 0x49a7d481 +1, 49152, 49152, 4096, 8192, 0xfec9f060 +1, 53248, 53248, 4096, 8192, 0xc0f0da13 +1, 57344, 57344, 4096, 8192, 0x4455eb74 +1, 61440, 61440, 4096, 8192, 0xf0b5e1a8 +1, 65536, 65536, 4096, 8192, 0x0e4be63c +1, 69632, 69632, 4096, 8192, 0xbc06e533 +1, 73728, 73728, 4096, 8192, 0x7cc6dc3c +1, 77824, 77824, 4096, 8192, 0xe822f1db +1, 81920, 81920, 4096, 8192, 0x8635d3d6 +1, 86016, 86016, 4096, 8192, 0x6572f839 +1, 90112, 90112, 4096, 8192, 0x27fad063 +1, 94208, 94208, 4096, 8192, 0x0196f2fc +1, 98304, 98304, 4096, 8192, 0xa752dcff +1, 102400, 102400, 4096, 8192, 0xfba6e81c +1, 106496, 106496, 4096, 8192, 0x76e7e2f9 +1, 110592, 110592, 4096, 8192, 0x4034e306 +1, 114688, 114688, 4096, 8192, 0x42ccec39 +1, 118784, 118784, 4096, 8192, 0x74f4d8d3 +1, 122880, 122880, 4096, 8192, 0x4638f297 +1, 126976, 126976, 4096, 8192, 0x9cfed0b0 +1, 131072, 131072, 4096, 8192, 0x475cf7d1 +1, 135168, 135168, 4096, 8192, 0x5a9fd681 +1, 139264, 139264, 4096, 8192, 0x2cf5eddc +1, 143360, 143360, 4096, 8192, 0x345bde69 +1, 147456, 147456, 4096, 8192, 0xebcce64f +1, 151552, 151552, 4096, 8192, 0xd422e4e1 +1, 155648, 155648, 4096, 8192, 0x5fb4e30f +1, 159744, 159744, 4096, 8192, 0x8ea5e90d +1, 163840, 163840, 4096, 8192, 0xabd3dcb8 +1, 167936, 167936, 4096, 8192, 0x936ff1ba +1, 172032, 172032, 4096, 8192, 0x3a02d0bc +1, 176128, 176128, 4096, 8192, 0xe5bdfa3a +1, 180224, 180224, 4096, 8192, 0x98e9d318 +1, 184320, 184320, 4096, 8192, 0xea12f0c1 +1, 188416, 188416, 4096, 8192, 0xffa8dd99 +1, 192512, 192512, 4096, 8192, 0x0dd6e4b2 +1, 196608, 196608, 4096, 8192, 0x7cd6e5b0 +1, 200704, 200704, 4096, 8192, 0x93f2e223 +1, 204800, 204800, 4096, 8192, 0xc901ebdf +1, 208896, 208896, 4096, 8192, 0xf318d7b6 +1, 212992, 212992, 4096, 8192, 0xaf20f65e +1, 217088, 217088, 4096, 8192, 0x418ecffe +1, 221184, 221184, 4096, 8192, 0x8b54f77a +1, 225280, 225280, 4096, 8192, 0x811bd61f +1, 229376, 229376, 4096, 8192, 0x629aec8a +1, 233472, 233472, 4096, 8192, 0xc50de3cf +1, 237568, 237568, 4096, 8192, 0x506be304 +1, 241664, 241664, 4096, 8192, 0x799ee4b0 +1, 245760, 245760, 4096, 8192, 0x09aae1e0 +1, 249856, 249856, 4096, 8192, 0x36e9ec10 +1, 253952, 253952, 4096, 8192, 0x8166d890 +1, 258048, 258048, 4096, 8192, 0x6674f4aa +1, 262144, 262144, 4096, 8192, 0x5223d05b +1, 266240, 266240, 4096, 8192, 0xfc57f580 +1, 270336, 270336, 4096, 8192, 0x72d6d7dd +1, 274432, 274432, 4096, 8192, 0xabaaecdf +1, 278528, 278528, 4096, 8192, 0x3c1ddf5f +1, 282624, 282624, 4096, 8192, 0x16b8e7ed +1, 286720, 286720, 1280, 2560, 0xf55202f4 -- 2.52.0 >From a75faa7ad40f4afe853b40b33d4c8b537a3ee90f Mon Sep 17 00:00:00 2001 From: Ayoub Nabil Boubagrat <[email protected]> Date: Wed, 12 Aug 2026 22:24:53 +0200 Subject: [PATCH 3/3] fftools/ffmpeg_dec: propagate scheduler receive errors Signed-off-by: Ayoub Nabil Boubagrat <[email protected]> --- fftools/ffmpeg_dec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 1498afa880..52c41b9137 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -922,6 +922,14 @@ static int decoder_thread(void *arg) int flush_buffers, have_data; input_status = sch_dec_receive(dp->sch, dp->sch_idx, dt.pkt); + if (input_status < 0 && input_status != AVERROR_EOF) { + av_log(dp, AV_LOG_ERROR, + "Error receiving a packet from the scheduler: %s\n", + av_err2str(input_status)); + ret = input_status; + goto finish; + } + have_data = input_status >= 0 && (dt.pkt->buf || dt.pkt->side_data_elems || (intptr_t)dt.pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT || -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
