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 c41155e614 libavcodec: support frame dropping in libvpxenc
c41155e614 is described below

commit c41155e614bec5891f9adb78c9d2ca43270d9e02
Author:     Dariusz Marcinkiewicz <[email protected]>
AuthorDate: Wed Nov 26 14:15:48 2025 +0100
Commit:     darekm <[email protected]>
CommitDate: Tue Dec 16 21:53:10 2025 +0000

    libavcodec: support frame dropping in libvpxenc
    
    vp8 encoder can be configured to drop frames, when e.g. bitrate
    overshoot is detected. At present the code responsible for
    managing an internal fifo assumes that we will get an output frame per
    each frame fed into encoder. That is not the case if the encoder can
    decide to drop frames.
    
    Running:
    ffmpeg -stream_loop 100 -i dash_video3.webm -c:v libvpx -b:v 50k
    -drop-threshold 20 -screen-content-mode 2 output.webm
    
    results in lots of warnings like:
    [libvpx @ 0x563fd8aba100] Mismatching timestamps: libvpx 2187 queued
    2185; this is a bug, please report it
    [libvpx @ 0x563fd8aba100] Mismatching timestamps: libvpx 2189 queued
    2186; this is a bug, please report it
    
    followed by:
    [vost#0:0/libvpx @ 0x563fd8ab9b40] [enc:libvpx @ 0x563fd8aba080] Error
    submitting video frame to the encoder
    [vost#0:0/libvpx @ 0x563fd8ab9b40] [enc:libvpx @ 0x563fd8aba080] Error
    encoding a frame: No space left on device
    [vost#0:0/libvpx @ 0x563fd8ab9b40] Task finished with error code: -28
    (No space left on device)
    [vost#0:0/libvpx @ 0x563fd8ab9b40] Terminating thread with return code
    -28 (No space left on device)
    
    The reason for the above error is that each dropped frame leaves an
    extra item in the fifo, which eventually overflows.
    
    The proposed fix is to keep popping elements from the fifo until the
    one with the matching pts is found. A side effect of this change is that
    the code no longer considers pts mismatch to be a bug.
    
    This has likely regressed around 5bda4ec6c3cb6f286bb40dee4457c3c26e0f78cb
    when fifo started to be universally used.
    
    Signed-off-by: Dariusz Marcinkiewicz <[email protected]>
---
 libavcodec/libvpxenc.c | 45 ++++++++++++++++++++++++++++++++++++++-------
 libavcodec/version.h   |  2 +-
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index ef529abcab..af73966141 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -352,6 +352,13 @@ static av_cold void fifo_free(AVFifo **fifo)
     av_fifo_freep2(fifo);
 }
 
+static int encoder_can_drop_frames(AVCodecContext *avctx)
+{
+    VPxContext *ctx = avctx->priv_data;
+
+    return (ctx->drop_threshold > 0) || (ctx->screen_content_mode == 2);
+}
+
 static int frame_data_submit(AVCodecContext *avctx, AVFifo *fifo,
                              const AVFrame *frame)
 {
@@ -383,6 +390,18 @@ static int frame_data_submit(AVCodecContext *avctx, AVFifo 
*fifo,
     }
 
     ret = av_fifo_write(fifo, &fd, 1);
+    if (ret == AVERROR(ENOSPC)) {
+        FrameData fd2;
+
+        av_log(avctx, AV_LOG_WARNING, "FIFO full, will drop a front 
element\n");
+
+        ret = av_fifo_read(fifo, &fd2, 1);
+        if (ret >= 0) {
+            frame_data_uninit(&fd2);
+            ret = av_fifo_write(fifo, &fd, 1);
+        }
+    }
+
     if (ret < 0)
         goto fail;
 
@@ -398,13 +417,25 @@ static int frame_data_apply(AVCodecContext *avctx, AVFifo 
*fifo, AVPacket *pkt)
     uint8_t *data;
     int ret = 0;
 
-    if (av_fifo_peek(fifo, &fd, 1, 0) < 0)
-        return 0;
-    if (fd.pts != pkt->pts) {
-        av_log(avctx, AV_LOG_WARNING,
-               "Mismatching timestamps: libvpx %"PRId64" queued %"PRId64"; "
-               "this is a bug, please report it\n", pkt->pts, fd.pts);
-        goto skip;
+    while (1) {
+        if (av_fifo_peek(fifo, &fd, 1, 0) < 0)
+            return 0;
+
+        if (fd.pts == pkt->pts) {
+            break;
+        }
+
+        if (!encoder_can_drop_frames(avctx)) {
+            av_log(avctx, AV_LOG_WARNING,
+                   "Mismatching timestamps: libvpx %"PRId64" queued %"PRId64"; 
"
+                   "this is a bug, please report it\n", pkt->pts, fd.pts);
+            goto skip;
+        }
+
+        av_log(avctx, AV_LOG_DEBUG, "Dropped frame with pts %"PRId64"\n",
+               fd.pts);
+        av_fifo_drain2(fifo, 1);
+        frame_data_uninit(&fd);
     }
 
     pkt->duration = fd.duration;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 3af30cdc3b..9d910cf848 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 #include "version_major.h"
 
 #define LIBAVCODEC_VERSION_MINOR  23
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \

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

Reply via email to