PR #26374 opened by luoye-cpu URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26374 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26374.patch
Add a NONREF branch to the existing per-frame skip_frame check: when skip_frame >= AVDISCARD_NONREF, a frame with refresh_frame_flags == 0 and frame_type != AV1_FRAME_KEY is not decoded (no tile decode, no output). Per AV1 spec section 7.20 a frame becomes a reference iff refresh_frame_flags is non-zero, so skipping such frames before tile decode is a no-op for the reference slots; the frame_type check keeps delayed random access points out of the skip set, and show_existing_frame replays are handled earlier and stay exempt. The predicate matches dav1d's DAV1D_DECODEFRAMETYPE_REFERENCE mode, so the two AV1 decoders produce the same output sequence under NONREF. This fills in the NONREF level of the existing NONINTRA/NONKEY/ALL criteria chain rather than introducing new semantics. Note that the native AV1 decoder is a hardware-acceleration framework; the software decode path is libdav1d (PR-3 in this series makes its runtime window effective). FATE: fate-av1-svc-l1t2-noref on a layered fate-suite AV1 sample decoded through libdav1d; the noref output equals the even-subsequence window of the full decode, which fails if a reference frame is skipped. >From 0b93ef7de2701d6e287d3f5d5582cf32f01dd030 Mon Sep 17 00:00:00 2001 From: luoye-cpu <[email protected]> Date: Fri, 27 Nov 2026 01:48:05 +0800 Subject: [PATCH] avcodec/av1dec: implement AVDISCARD_NONREF skipping Skip decoding of frames that cannot be referenced by any later frame (refresh_frame_flags == 0 && frame_type != AV1_FRAME_KEY) when skip_frame >= AVDISCARD_NONREF. Per AV1 spec section 7.20 a frame is a reference iff refresh_frame_flags != 0, so skipping such frames before tile decode is a no-op for the reference slots; the frame_type check keeps delayed random access points (KEY frames with show_frame == 0 whose refresh_frame_flags can read as 0 from the bitstream) out of the skip set, and show_existing_frame replays are handled before this point and stay exempt. The predicate matches the REFERENCE frametype mode of dav1d, so the output sequence under NONREF is the same across the two AV1 decoders. Registered as fate-av1-svc-l1t2-noref on a layered fate-suite AV1 sample: the noref decode equals the even-subsequence window of the full decode, which fails if a reference frame is skipped or the reference chain is corrupted. Signed-off-by: luoye-cpu <[email protected]> --- libavcodec/av1dec.c | 11 +++++++++++ tests/fate/av1.mak | 31 ++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index e6512cd004d..7d711f59609 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -1210,6 +1210,17 @@ static int get_current_frame(AVCodecContext *avctx) return ret; } + /* AVDISCARD_NONREF: a frame is referenced by later frames only if + * refresh_frame_flags != 0 (AV1 spec, section 7.20 reference frame + * update process), so skipping frames with refresh_frame_flags == 0 + * never touches the reference slots. KEY frames are kept since a + * delayed RAP (show_frame == 0) may read refresh_frame_flags as 0 + * (section 7.6.2); matches dav1d's DAV1D_DECODEFRAMETYPE_REFERENCE. */ + if (avctx->skip_frame >= AVDISCARD_NONREF && + !s->raw_frame_header->refresh_frame_flags && + s->raw_frame_header->frame_type != AV1_FRAME_KEY) + return 0; + if ((avctx->skip_frame >= AVDISCARD_NONINTRA && (s->raw_frame_header->frame_type != AV1_FRAME_KEY && s->raw_frame_header->frame_type != AV1_FRAME_INTRA_ONLY)) || diff --git a/tests/fate/av1.mak b/tests/fate/av1.mak index 81072be5b8e..047cffc792a 100644 --- a/tests/fate/av1.mak +++ b/tests/fate/av1.mak @@ -4,4 +4,33 @@ fate-libaom-hdr10-plus: CMD = enc_external $(TARGET_SAMPLES)/mkv/hdr10_plus_vp9_ FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_AV1_FFMPEG_FFPROBE-yes) -fate-av1: $(FATE_AV1_FFMPEG_FFPROBE-yes) +# av1-1-b8-22-svc-L1T2.ivf interleaves reference frames (the leading KEY +# frame, then refresh_frame_flags in {4, 2, 1}) with non-reference inter +# frames carrying refresh_frame_flags == 0 (temporal layer T1); frames 1, 3, +# 5 and 7 (0-based) are skippable. All frames are shown (show_frame == 1 and +# no show_existing_frame), so a frame dropped before tile decode is a +# missing output frame, not a hidden one. With -skip_frame noref the output +# is therefore exactly the even-numbered subsequence of the full decode, and +# the parity is asserted on that subsequence instead of the whole stream. +# The native AV1 decoder is a hwaccel-only framework (libavcodec/av1dec.c), +# so the software decode path here is libdav1d (forced with -c:v libdav1d), +# which maps skip_frame=NONREF onto the decoder at init time; the static CLI +# option is therefore effective for the whole run. +# The window still locks the whole reference chain: per AV1 spec 7.20 a +# frame is a reference iff refresh_frame_flags != 0, so a wrongly skipped +# reference frame or a corrupted reference state would change the content or +# the number of the surviving frames and the comparison would fail. +FATE_AV1_FFMPEG-$(call ALLYES, IVF_DEMUXER LIBDAV1D_DECODER SELECT_FILTER FRAMECRC_MUXER FILE_PROTOCOL) += fate-av1-svc-l1t2-noref +fate-av1-svc-l1t2-noref: CMD = \ + cleanfiles="$${cleanfiles} $${outfile}.window $${outfile}.noref"; \ + ffmpeg -flags +bitexact -c:v libdav1d -i $(TARGET_SAMPLES)/av1/av1-1-b8-22-svc-L1T2.ivf \ + -vf "select=not(mod(n\,2))" -f framecrc -y "$$(target_path "$${outfile}.window")" && \ + ffmpeg -flags +bitexact -c:v libdav1d -skip_frame noref -i $(TARGET_SAMPLES)/av1/av1-1-b8-22-svc-L1T2.ivf \ + -f framecrc -y "$$(target_path "$${outfile}.noref")" && \ + { cmp -s "$${outfile}.window" "$${outfile}.noref" && echo "noref vs full decode: same" || echo "noref vs full decode: different"; } +fate-av1-svc-l1t2-noref: CMP = oneline +fate-av1-svc-l1t2-noref: REF = noref vs full decode: same + +FATE_SAMPLES_FFMPEG += $(FATE_AV1_FFMPEG-yes) + +fate-av1: $(FATE_AV1_FFMPEG_FFPROBE-yes) $(FATE_AV1_FFMPEG-yes) -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
