PR #26217 opened by Pu Cheng (GeekQAQ) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26217 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26217.patch
The decoder draws each frame on top of its reference frame and clears the palette only when avctx->frame_num is 0; each frame then only rewrites some palette entries. frame_num is not reset by avcodec_flush_buffers() and the decoder has no flush callback, so after a flush and a switch to another stream the palette entries the first frame does not rewrite keep the previous stream's colors, where a newly opened decoder has them black. Add a flush callback, and clear the palette on the first frame output after a flush as for the first frame of a stream. Signed-off-by: Pu Cheng <[email protected]> >From 7242ad3c7f6f5c3cc797dce52d60bbd389c3d42f Mon Sep 17 00:00:00 2001 From: Pu Cheng <[email protected]> Date: Fri, 20 Nov 2026 14:08:21 +0800 Subject: [PATCH] avcodec/yop: add a flush callback The decoder draws each frame on top of its reference frame and clears the palette only when avctx->frame_num is 0; each frame then only rewrites some palette entries. frame_num is not reset by avcodec_flush_buffers() and the decoder has no flush callback, so after a flush and a switch to another stream the palette entries the first frame does not rewrite keep the previous stream's colors, where a newly opened decoder has them black. Add a flush callback, and clear the palette on the first frame output after a flush as for the first frame of a stream. Signed-off-by: Pu Cheng <[email protected]> --- libavcodec/yop.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/yop.c b/libavcodec/yop.c index 225bc71f5d1..e6c886657eb 100644 --- a/libavcodec/yop.c +++ b/libavcodec/yop.c @@ -34,6 +34,7 @@ typedef struct YopDecContext { AVCodecContext *avctx; AVFrame *frame; + int flushed; ///< no frame was output since the last flush: clear the palette as for a first frame int num_pal_colors; int first_color[2]; @@ -126,6 +127,12 @@ static av_cold int yop_decode_init(AVCodecContext *avctx) return 0; } +static av_cold void yop_decode_flush(AVCodecContext *avctx) +{ + YopDecContext *s = avctx->priv_data; + s->flushed = 1; +} + /** * Paint a macroblock using the pattern in paint_lut. * @param s codec context @@ -207,7 +214,7 @@ static int yop_decode_frame(AVCodecContext *avctx, AVFrame *rframe, if ((ret = ff_reget_buffer(avctx, frame, 0)) < 0) return ret; - if (!avctx->frame_num) + if (!avctx->frame_num || s->flushed) memset(frame->data[1], 0, AVPALETTE_SIZE); s->dstbuf = frame->data[0]; @@ -259,6 +266,7 @@ static int yop_decode_frame(AVCodecContext *avctx, AVFrame *rframe, if ((ret = av_frame_ref(rframe, s->frame)) < 0) return ret; + s->flushed = 0; *got_frame = 1; return avpkt->size; } @@ -272,5 +280,6 @@ const FFCodec ff_yop_decoder = { .priv_data_size = sizeof(YopDecContext), .init = yop_decode_init, .close = yop_decode_close, + .flush = yop_decode_flush, FF_CODEC_DECODE_CB(yop_decode_frame), }; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
