PR #26263 opened by Baptiste Coudurier (bcoudurier)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26263
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26263.patch

With a copied stream mapped, the muxing sync queue dropped the last audio 
packet that the frame queue had just cut, as it ends a fraction of a sample 
after the limiting stream. It now accepts a packet ending at the limit rounded 
up in its time base.

Reported by Forgejo_Fairy on https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25952.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



From 582e725f2896db8b52ca76f00307e8944b5d3c55 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sat, 21 Nov 2026 12:06:45 -0800
Subject: [PATCH] fftools/sync_queue: keep the cut audio packet in the muxing
 queue

With a streamcopied stream, the packet queue dropped the last audio
packet cut by the frame queue, ending a fraction of a tick late.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 fftools/sync_queue.c                        |  6 ++++
 tests/fate/ffmpeg.mak                       |  7 ++++-
 tests/ref/fate/ffmpeg-frames-cut-audio-copy | 32 +++++++++++++++++++++
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/ffmpeg-frames-cut-audio-copy

diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c
index 20fa822e18a..f0ff12e8c07 100644
--- a/fftools/sync_queue.c
+++ b/fftools/sync_queue.c
@@ -549,6 +549,12 @@ static int receive_for_stream(SyncQueue *sq, unsigned int 
stream_idx,
                       av_rescale_q(peek.f->pts, st->tb, sample_tb);
                 cut = FFMIN(cut, peek.f->nb_samples);
             }
+
+            /* Packets cannot be cut; accept one ending at the final queue
+             * head rounded up, where a frame queue cut ends its audio. */
+            if (cmp > 0 && st_head->finished && sq->type == SYNC_QUEUE_PACKETS)
+                cmp = ts > av_rescale_q_rnd(st_head->head_ts, st_head->tb, 
st->tb,
+                                            AV_ROUND_UP);
         }
 
         /* We can release frames that do not end after the queue head.
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index e665b08bb9a..b93d039c669 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -131,7 +131,8 @@ FATE_FFMPEG-$(call ALLYES, LAVFI_INDEV COLOR_FILTER 
SINE_FILTER \
                            WRAPPED_AVFRAME_DECODER PCM_S16LE_DECODER \
                            RAWVIDEO_ENCODER PCM_S16LE_ENCODER FRAMECRC_MUXER \
                            PIPE_PROTOCOL) \
-                           += fate-ffmpeg-frames-cut-audio 
fate-ffmpeg-frames-cut-audio-round
+                           += fate-ffmpeg-frames-cut-audio 
fate-ffmpeg-frames-cut-audio-round \
+                              fate-ffmpeg-frames-cut-audio-copy
 fate-ffmpeg-frames-cut-audio: CMD = framecrc \
     -f lavfi -i 
"color=s=16x16:r=30000/1001:d=2[out0];sine=r=48000:samples_per_frame=4800:d=2[out1]"
 \
     -map 0:v -map 0:a -frames:v 10
@@ -139,6 +140,10 @@ fate-ffmpeg-frames-cut-audio: CMD = framecrc \
 fate-ffmpeg-frames-cut-audio-round: CMD = framecrc \
     -f lavfi -i 
"color=s=16x16:r=30000/1001:d=2[out0];sine=r=48000:samples_per_frame=1602:d=2[out1]"
 \
     -map 0:v -map 0:a -frames:v 1
+# the cut audio ending at 14715, after 14714.7, passes the muxing sync queue
+fate-ffmpeg-frames-cut-audio-copy: CMD = framecrc \
+    -f lavfi -i 
"color=s=16x16:r=30000/1001:d=2[out0];sine=r=44100:samples_per_frame=4410:d=2[out1]"
 \
+    -map 0:v -map 0:a -map 0:a -c:a:1 copy -frames:v 10
 
 # test interleaving video with a sparse subtitle stream
 FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MATROSKA,, COLOR_FILTER VOBSUB_DEMUXER \
diff --git a/tests/ref/fate/ffmpeg-frames-cut-audio-copy 
b/tests/ref/fate/ffmpeg-frames-cut-audio-copy
new file mode 100644
index 00000000000..ecde0b38ac7
--- /dev/null
+++ b/tests/ref/fate/ffmpeg-frames-cut-audio-copy
@@ -0,0 +1,32 @@
+#tb 0: 1001/30000
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 16x16
+#sar 0: 1/1
+#tb 1: 1/44100
+#media_type 1: audio
+#codec_id 1: pcm_s16le
+#sample_rate 1: 44100
+#channel_layout_name 1: mono
+#tb 2: 1/44100
+#media_type 2: audio
+#codec_id 2: pcm_s16le
+#sample_rate 2: 44100
+#channel_layout_name 2: mono
+0,          0,          0,        1,      384, 0x29e05000
+1,          0,          0,     4410,     8820, 0x9e493079
+2,          0,          0,     4410,     8820, 0x9e493079
+0,          1,          1,        1,      384, 0x29e05000
+0,          2,          2,        1,      384, 0x29e05000
+1,       4410,       4410,     4410,     8820, 0x9e493079
+2,       4410,       4410,     4410,     8820, 0x9e493079
+0,          3,          3,        1,      384, 0x29e05000
+0,          4,          4,        1,      384, 0x29e05000
+0,          5,          5,        1,      384, 0x29e05000
+1,       8820,       8820,     4410,     8820, 0x9e493079
+2,       8820,       8820,     4410,     8820, 0x9e493079
+0,          6,          6,        1,      384, 0x29e05000
+0,          7,          7,        1,      384, 0x29e05000
+0,          8,          8,        1,      384, 0x29e05000
+1,      13230,      13230,     1485,     2970, 0xd8a1bd39
+0,          9,          9,        1,      384, 0x29e05000
-- 
2.54.1

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

Reply via email to