From dcd7c01b2eb05da1fe1081097f481e33f0324046 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Thu, 1 May 2025 21:51:07 +0200 Subject: [PATCH 41/44] avcodec/h263dec: Always output next, not current pic when flushing It is the last picture in display order. Signed-off-by: Andreas Rheinhardt --- libavcodec/h263dec.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index cbcd719859..33dccfad2c 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -439,22 +439,19 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, /* no supplementary picture */ if (buf_size == 0) { /* special case for last picture */ - if (s->low_delay == 0 && s->next_pic.ptr) { + if ((!s->low_delay || s->skipped_last_frame) && s->next_pic.ptr) { if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0) return ret; - ff_mpv_unref_picture(&s->next_pic); + if (s->skipped_last_frame) { + /* If the stream ended with an NVOP, we output the last frame + * in display order, but with the props from the last input + * packet so that the stream's end time is correct. */ + ret = ff_decode_frame_props(avctx, pict); + if (ret < 0) + return ret; + } - *got_frame = 1; - } else if (s->skipped_last_frame && s->cur_pic.ptr) { - /* Output the last picture we decoded again if the stream ended with - * an NVOP */ - if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0) - return ret; - /* Copy props from the last input packet. Otherwise, props from the last - * returned picture would be reused */ - if ((ret = ff_decode_frame_props(avctx, pict)) < 0) - return ret; - ff_mpv_unref_picture(&s->cur_pic); + ff_mpv_unref_picture(&s->next_pic); *got_frame = 1; } -- 2.45.2