Commit c422dfdd67 for ffmpeg
commit c422dfdd677304ba2ba95c7bb046ff45a0b16e52
Author: Uraza Aru <271304759+urzaru@users.noreply.github.com>
Date: Wed Oct 14 02:14:02 2026 +0500
avcodec/vulkan_encode_av1: use PRIMARY_REF_NONE for key frames
primary_ref_frame is only set in the P and B branches, so key frames
keep the initial 0. A shown key frame is error resilient: its header
signals no primary reference and decoders start from the default CDFs
for the frame's base_q_idx. With primary_ref_frame = 0, NVIDIA's
encoder evidently starts from other CDFs; the two agree only while
base_q_idx <= 20 (the first coefficient CDF q context). Above that,
every key frame and everything after it is undecodable: dav1d reports
a symbol decoder overread in the first tile and hardware decoders show
garbage. This is why streams at modest bitrates (e.g. 1280x720 at 60
fps and 10 Mbit/s, key frame base_q_idx 39) failed while very high
bitrates worked.
Set primary_ref_frame to STD_VIDEO_AV1_PRIMARY_REF_NONE for key frames,
as NVIDIA's Vulkan Video samples do.
Tested on an RTX 4090 (Linux driver 615.78.08): CBR 2-60 Mbit/s and
CQP 40-200 now decode, up to 2560x1440 at 120 fps and 3840x2160 at 60
fps.
Fixes #25046.
Assisted-by: Claude Opus 5.5
Signed-off-by: Uraza Aru <271304759+urzaru@users.noreply.github.com>
diff --git a/libavcodec/vulkan_encode_av1.c b/libavcodec/vulkan_encode_av1.c
index 67d81d189b..379b9f2eb9 100644
--- a/libavcodec/vulkan_encode_av1.c
+++ b/libavcodec/vulkan_encode_av1.c
@@ -355,6 +355,7 @@ static int init_pic_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic,
av_assert0(pic->nb_refs[0] == 0 || pic->nb_refs[1]);
ap->av1pic_info.frame_type = STD_VIDEO_AV1_FRAME_TYPE_KEY;
ap->av1pic_info.refresh_frame_flags = 0xFF;
+ ap->av1pic_info.primary_ref_frame = STD_VIDEO_AV1_PRIMARY_REF_NONE;
quantization->base_q_idx = enc->q_idx_idr;
ap->slot = 0;
ap->last_idr_frame = pic->display_order;