PR #25177 opened by Marti2203
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25177
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25177.patch

`a64multi_encode_frame()` collects frames until `mc_lifetime` of them are 
stored. The frame that arrives once the buffer is full only triggers encoding 
of the stored frames and is then discarded, so it never appears in the output.

```
ffmpeg -f lavfi -i testsrc=s=320x200:r=10 -frames:v 10 -c:v a64multi -f 
framecrc -
```

gives two packets of 4 frames each (pts 0 and 5): the frames with pts 4 and 9 
are missing. With `-global_quality 118` (lifetime 1), 7 input frames give 4 
packets, i.e. every second frame is lost.

With the patch, the frame that completes a charset is stored as the first frame 
of the next one: 10 input frames give packets of 4, 4 and 2 frames (pts 0, 4, 
8), lifetime 1 gives 7 packets, and lifetime 2 gives 7 frames instead of 5. The 
frame is not stored when the lifetime is 0 (the buffer is then empty); that 
case produces no output before or after.

There is no FATE coverage for this encoder.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified 
manually.

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

https://claude.ai/code/session_01PJjAkXVedLvPoWWc6fokZ3



From cd855130f72b9506eb1150b8e4e5d6a2e11ef099 Mon Sep 17 00:00:00 2001
From: Martin Mirchev <[email protected]>
Date: Sun, 18 Oct 2026 17:30:26 +0800
Subject: [PATCH] avcodec/a64multienc: do not drop the frame that completes a
 charset

Frames are collected until mc_lifetime of them are stored, but the frame
that arrives once the buffer is full only triggers encoding of the stored
ones and is itself discarded. With the default lifetime of 4, every fifth
input frame was lost (10 frames in, 8 encoded); with lifetime 1, every
second one.

Store that frame as the first one of the next charset.

Signed-off-by: Martin Mirchev <[email protected]>
---
 libavcodec/a64multienc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index d81718dff5..bfe53da28b 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -386,6 +386,13 @@ static int a64multi_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
         pkt->pts = pkt->dts = c->next_pts;
         c->next_pts         = AV_NOPTS_VALUE;
 
+        /* the frame that completed the charset starts the next one */
+        if (p && c->mc_lifetime) {
+            to_meta_with_crop(avctx, p, meta);
+            c->mc_frame_counter = 1;
+            c->next_pts         = p->pts;
+        }
+
         av_assert0(pkt->size == req_size);
         *got_packet = !!req_size;
     }
-- 
2.54.0

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

Reply via email to