PR #21278 opened by Jack Lau (JackLau)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21278
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21278.patch

Fix #21260

The early code didn't reset the JxlDecoder. If the
caller re-send the same packet to JxlDecoder after
avcodec_flush_buffers() (free ctx->frame). It will
directly hit SUCCESS event (skip all EVENTs).

In this case, the ctx->frame already flushed by
avcodec_flush_buffers, so the received frame
will be invalid (has no private_ref) that causes
assertion in decode_receive_frame_internal().

MPV meet this issue because it seek the jxl image
(second read the same pkt) when it does crop
through config `C vf toggle crop=in_w:in_w/2.4`.

This patch make sure hit the entire SUCCESS event
(contains reset the JxlDecoder) when frame_complete
is true.

Signed-off-by: Jack Lau <[email protected]>


>From fedb4b905d7adb495aa65bc37cf11aa6153464bf Mon Sep 17 00:00:00 2001
From: Jack Lau <[email protected]>
Date: Tue, 23 Dec 2025 10:53:23 +0800
Subject: [PATCH] avcodec/libjxldec: goto SUCCESS when frame is completed

Fix #21260

The early code didn't reset the JxlDecoder. If the
caller re-send the same packet to JxlDecoder after
avcodec_flush_buffers() (free ctx->frame). It will
directly hit SUCCESS event (skip all EVENTs).

In this case, the ctx->frame already flushed by
avcodec_flush_buffers, so the received frame
will be invalid (has no private_ref) that causes
assertion in decode_receive_frame_internal().

MPV meet this issue because it seek the jxl image
(second read the same pkt) when it does crop
through config `C vf toggle crop=in_w:in_w/2.4`.

This patch make sure hit the entire SUCCESS event
(contains reset the JxlDecoder) when frame_complete
is true.

Signed-off-by: Jack Lau <[email protected]>
---
 libavcodec/libjxldec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index a43437fb10..2aada927b4 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -450,9 +450,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
                     av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL 
codestream\n");
                     return AVERROR_INVALIDDATA;
                 } else if (ctx->frame_complete) {
-                    libjxl_finalize_frame(avctx, frame, ctx->frame);
                     ctx->jret = JXL_DEC_SUCCESS;
-                    return 0;
+                    goto success;
                 }
                 return AVERROR_EOF;
             }
@@ -584,6 +583,7 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
                 continue;
             }
         case JXL_DEC_SUCCESS:
+success:
             av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");
             /*
              * this event will be fired when the zero-length EOF
-- 
2.49.1

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

Reply via email to