PR #26005 opened by kennethvg72 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26005 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26005.patch
H.265 8.3.1 defines prevTid0Pic as the previous TemporalId 0 picture in decoding order that is not a RASL, RADL or sub-layer non-reference picture, whether or not it was decoded. When a picture is dropped by skip_frame, its slice header has already been parsed, but poc_tid0 was left at the POC of the last decoded picture. With -skip_frame nokey on open-GOP streams whose IRAPs are more than MaxPicOrderCntLsb / 2 pictures apart (x265 keyint=250 or 256), the next IRAP's POC MSB is then derived wrongly: keyframes are dropped with "Duplicate POC in a sequence" or output out of order. Update poc_tid0 from the skipped picture's slice header, with the same conditions as the regular path, for the base layer only. A full decode is unchanged: there the skip branch is reached only by RASL pictures, which are excluded. Fixes: #25990 >From b429866ffcaaa03d844f1802fc55fd095c1d3e67 Mon Sep 17 00:00:00 2001 From: Kenneth van Grinsven <[email protected]> Date: Thu, 12 Nov 2026 19:07:14 -0500 Subject: [PATCH] avcodec/hevc/hevcdec: track poc_tid0 for skipped pictures H.265 8.3.1 defines prevTid0Pic as the previous TemporalId 0 picture in decoding order that is not a RASL, RADL or sub-layer non-reference picture, whether or not it was decoded. When a picture is dropped by skip_frame, its slice header has already been parsed, but poc_tid0 was left at the POC of the last decoded picture. With -skip_frame nokey on open-GOP streams whose IRAPs are more than MaxPicOrderCntLsb / 2 pictures apart (x265 keyint=250 or 256), the next IRAP's POC MSB is then derived wrongly: keyframes are dropped with "Duplicate POC in a sequence" or output out of order. Update poc_tid0 from the skipped picture's slice header, with the same conditions as the regular path, for the base layer only. A full decode is unchanged: there the skip branch is reached only by RASL pictures, which are excluded. Fixes: #25990 --- libavcodec/hevc/hevcdec.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 0934f640966..59a69a1bdab 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -4397,8 +4397,23 @@ static int decode_slice(HEVCContext *s, unsigned nal_idx, GetBitContext *gb) (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) || ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) && s->no_rasl_output_flag)) { - if (s->sh.first_slice_in_pic_flag) + if (s->sh.first_slice_in_pic_flag) { s->skipping_frame = 1; + /* 8.3.1: a skipped picture is still prevTid0Pic for the next + * picture's POC (its slice header was read above); without this, + * skip_frame leaves poc_tid0 at the last decoded picture and a + * later IRAP's POC MSB comes out wrong once the gap passes + * MaxPicOrderCntLsb / 2 (out-of-order output, "Duplicate POC"). */ + if (s->nuh_layer_id == 0 && s->temporal_id == 0 && + s->nal_unit_type != HEVC_NAL_TRAIL_N && + s->nal_unit_type != HEVC_NAL_TSA_N && + s->nal_unit_type != HEVC_NAL_STSA_N && + s->nal_unit_type != HEVC_NAL_RADL_N && + s->nal_unit_type != HEVC_NAL_RADL_R && + s->nal_unit_type != HEVC_NAL_RASL_N && + s->nal_unit_type != HEVC_NAL_RASL_R) + s->poc_tid0 = s->sh.poc; + } return 0; } if (s->sh.first_slice_in_pic_flag) -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
