This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new 90c61d9ba9 avfilter/af_amix: preserve next_pts while waiting for the 
first input's EOF
90c61d9ba9 is described below

commit 90c61d9ba93af839a710562d69fdf1030d7f0104
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Fri Nov 6 18:11:45 2026 +0000
Commit:     Baptiste Coudurier <[email protected]>
CommitDate: Wed Nov 18 19:36:27 2026 +0000

    avfilter/af_amix: preserve next_pts while waiting for the first input's EOF
    
    After the last frame of input 0 is mixed, another input can trigger
    output_frame() before input 0's EOF is acknowledged. The empty frame
    list supplies AV_NOPTS_VALUE, overwriting the timestamp already advanced
    past the last mixed frame. Subsequent output then keeps missing PTS.
    
    Only update next_pts when the frame list is nonempty, as proposed in
    issue #25721. Add a deterministic buffersrc/buffersink FATE test.
    
    Fixes: #25721
    Assisted-by: Fairy
---
 libavfilter/Makefile           |   1 +
 libavfilter/af_amix.c          |   5 +-
 libavfilter/tests/amix.c       | 106 +++++++++++++++++++++++++++++++++++++++++
 tests/fate/filter-audio.mak    |   7 ++-
 tests/ref/fate/filter-amix-pts |   3 ++
 5 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 677e7be860..8f3c64459c 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -692,6 +692,7 @@ SKIPHEADERS-$(CONFIG_SCALE_CUDA_FILTER)      += 
vf_scale_cuda.h
 TOOLS     = graph2dot
 TESTPROGS = drawutils filtfmts formats integral
 
+TESTPROGS-$(CONFIG_AMIX_FILTER)   += amix
 TESTPROGS-$(CONFIG_DRAWVG_FILTER) += drawvg
 
 TOOLS-$(CONFIG_LIBZMQ) += zmqsend
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 082d69b97f..aef438aeab 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -316,7 +316,10 @@ static int output_frame(AVFilterLink *outlink)
             }
         }
 
-        s->next_pts = frame_list_next_pts(s->frame_list);
+        /* Preserve the next timestamp if input 0 has no queued frames
+         * but its EOF has not been acknowledged yet. */
+        if (s->frame_list->nb_frames)
+            s->next_pts = frame_list_next_pts(s->frame_list);
     } else {
         /* first input closed: use the available samples */
         nb_samples = INT_MAX;
diff --git a/libavfilter/tests/amix.c b/libavfilter/tests/amix.c
new file mode 100644
index 0000000000..6f1af19a0c
--- /dev/null
+++ b/libavfilter/tests/amix.c
@@ -0,0 +1,106 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/error.h"
+#include "libavutil/frame.h"
+#include "libavutil/samplefmt.h"
+#include "libavutil/timestamp.h"
+#include "libavfilter/avfilter.h"
+#include "libavfilter/buffersink.h"
+#include "libavfilter/buffersrc.h"
+
+#define SRC 
"=sample_fmt=flt:sample_rate=48000:channel_layout=mono:time_base=1/48000"
+
+static int send_frame(AVFilterContext *src, int64_t pts)
+{
+    AVFrame *frame = av_frame_alloc();
+    int ret;
+
+    if (!frame)
+        return AVERROR(ENOMEM);
+    frame->format      = AV_SAMPLE_FMT_FLT;
+    frame->sample_rate = 48000;
+    frame->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    frame->nb_samples  = 1024;
+    frame->pts         = pts;
+    ret = av_frame_get_buffer(frame, 0);
+    if (ret >= 0) {
+        av_samples_set_silence(frame->extended_data, 0, frame->nb_samples,
+                               1, frame->format);
+        ret = av_buffersrc_add_frame(src, frame);
+    }
+    av_frame_free(&frame);
+    return ret;
+}
+
+static int drain(AVFilterContext *sink, AVFrame *frame)
+{
+    int ret;
+
+    while ((ret = av_buffersink_get_frame(sink, frame)) >= 0) {
+        printf("pts:%s samples:%d\n", av_ts2str(frame->pts), 
frame->nb_samples);
+        av_frame_unref(frame);
+    }
+    return ret == AVERROR(EAGAIN) || ret == AVERROR_EOF ? 0 : ret;
+}
+
+int main(void)
+{
+    AVFilterGraph *graph = avfilter_graph_alloc();
+    AVFrame *frame = av_frame_alloc();
+    AVFilterContext *in0, *in1, *sink;
+    int ret = AVERROR(ENOMEM);
+
+    if (!graph || !frame)
+        goto end;
+    graph->nb_threads = 1;
+    ret = avfilter_graph_parse_ptr(graph, "abuffer@in0" SRC "[a];abuffer@in1" 
SRC "[b];"
+                                   
"[a][b]amix=duration=longest,abuffersink@out",
+                                   NULL, NULL, NULL);
+    if (ret < 0 || (ret = avfilter_graph_config(graph, NULL)) < 0)
+        goto end;
+    in0  = avfilter_graph_get_filter(graph, "abuffer@in0");
+    in1  = avfilter_graph_get_filter(graph, "abuffer@in1");
+    sink = avfilter_graph_get_filter(graph, "abuffersink@out");
+
+    /* Input 1's second frame is consumed while input 0's frame list is
+     * empty, before input 0's EOF has been signalled. */
+    if ((ret = send_frame(in0, 48000)) < 0 ||
+        (ret = send_frame(in1, 0)) < 0 ||
+        (ret = drain(sink, frame)) < 0 ||
+        (ret = send_frame(in1, 1024)) < 0 ||
+        (ret = drain(sink, frame)) < 0 ||
+        (ret = av_buffersrc_add_frame(in0, NULL)) < 0 ||
+        (ret = drain(sink, frame)) < 0 ||
+        (ret = send_frame(in1, 2048)) < 0 ||
+        (ret = av_buffersrc_add_frame(in1, NULL)) < 0 ||
+        (ret = drain(sink, frame)) < 0)
+        goto end;
+
+end:
+    av_frame_free(&frame);
+    avfilter_graph_free(&graph);
+    if (ret < 0) {
+        fprintf(stderr, "%s\n", av_err2str(ret));
+        return 1;
+    }
+    return 0;
+}
diff --git a/tests/fate/filter-audio.mak b/tests/fate/filter-audio.mak
index f1035bba24..dd709d51a8 100644
--- a/tests/fate/filter-audio.mak
+++ b/tests/fate/filter-audio.mak
@@ -458,6 +458,10 @@ fate-filter-crazychannels: 
tests/data/filtergraphs/crazychannels
 fate-filter-crazychannels: CMD = framecrc -auto_conversion_filters 
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/crazychannels
 FATE_AFILTER-$(call FILTERFRAMECRC, ARESAMPLE SINE JOIN ATRIM CHANNELMAP 
CHANNELSPLIT, FILE_PROTOCOL) += fate-filter-crazychannels
 
+FATE_AFILTER_API-$(CONFIG_AMIX_FILTER) += fate-filter-amix-pts
+fate-filter-amix-pts: libavfilter/tests/amix$(EXESUF)
+fate-filter-amix-pts: CMD = run libavfilter/tests/amix$(EXESUF)
+
 FATE_AFILTER-yes += fate-filter-formats
 fate-filter-formats: libavfilter/tests/formats$(EXESUF)
 fate-filter-formats: CMD = run libavfilter/tests/formats$(EXESUF)
@@ -465,4 +469,5 @@ fate-filter-formats: CMD = run 
libavfilter/tests/formats$(EXESUF)
 FATE_AFILTER-yes := $(if $(call FRAMECRC), $(FATE_AFILTER-yes))
 FATE_SAMPLES_AVCONV += $(FATE_AFILTER_SAMPLES-yes)
 FATE_FFMPEG += $(FATE_AFILTER-yes)
-fate-afilter: $(FATE_AFILTER-yes) $(FATE_AFILTER_SAMPLES-yes)
+FATE-$(CONFIG_AVFILTER) += $(FATE_AFILTER_API-yes)
+fate-afilter: $(FATE_AFILTER-yes) $(FATE_AFILTER_SAMPLES-yes) 
$(FATE_AFILTER_API-yes)
diff --git a/tests/ref/fate/filter-amix-pts b/tests/ref/fate/filter-amix-pts
new file mode 100644
index 0000000000..de3009c999
--- /dev/null
+++ b/tests/ref/fate/filter-amix-pts
@@ -0,0 +1,3 @@
+pts:48000 samples:1024
+pts:49024 samples:1024
+pts:50048 samples:1024

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to