PR #26307 opened by Baptiste Coudurier (bcoudurier) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26307 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26307.patch
With -quantizer_noise_shaping, 4:4:4 chroma blocks 6/7 took their weights from the 4:2:2 position and blocks 8-11 used uninitialized weights, so output depended on stack contents. The new test gives different packets with zero and pattern stack initialization before the fix. Split out of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25368. Whichever lands second regenerates fate-ffmpeg-mjpeg-444-qns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) From bbacc843173f9095dc247fcd9d99506713616364 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Mon, 23 Nov 2026 14:31:32 -0800 Subject: [PATCH] avcodec/mpegvideo_enc: set noise-shaping weights for all 4:4:4 blocks Blocks 6/7 used the 4:2:2 position and 8-11 were left uninitialized. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Baptiste Coudurier <[email protected]> --- libavcodec/mpegvideo_enc.c | 9 ++++++++- tests/fate/ffmpeg.mak | 4 ++++ tests/ref/fate/ffmpeg-mjpeg-444-qns | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/ffmpeg-mjpeg-444-qns diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 0ada755264e..d027b497990 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -2543,13 +2543,20 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s, get_visual_weight(weight[4], ptr_cb , wrap_c); if (!skip_dct[5]) get_visual_weight(weight[5], ptr_cr , wrap_c); - if (!chroma_y_shift) { /* 422 */ + if (chroma_format == CHROMA_422) { if (!skip_dct[6]) get_visual_weight(weight[6], ptr_cb + uv_dct_offset, wrap_c); if (!skip_dct[7]) get_visual_weight(weight[7], ptr_cr + uv_dct_offset, wrap_c); + } else if (chroma_format == CHROMA_444) { + for (i = 6; i < 12; i++) { + const uint8_t *ptr = i & 1 ? ptr_cr : ptr_cb; + if (!skip_dct[i]) + get_visual_weight(weight[i], ptr + (i >= 8) * uv_dct_offset + + ((i >> 1) & 1) * 8, wrap_c); + } } memcpy(orig[0], s->block[0], sizeof(int16_t) * 64 * mb_block_count); } diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index 9a215503410..09c19938338 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -557,3 +557,7 @@ FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, HEVC, HEVC_PARSER SCALE_FILTER) += fat # alpha merging fate-ffmpeg-heif-merge-alpha: CMD = framecrc -auto_conversion_filters -i $(TARGET_SAMPLES)/heif/alpha.heic FATE_SAMPLES_FFMPEG-$(call FRAMECRC, MOV, HEVC, HEVC_PARSER SCALE_FILTER) += fate-ffmpeg-heif-merge-alpha + +# Exercise noise-shaping weights for all twelve 4:4:4 blocks. +FATE_FFMPEG-$(call ALLYES, TESTSRC2_FILTER FORMAT_FILTER NOISE_FILTER LAVFI_INDEV WRAPPED_AVFRAME_DECODER MJPEG_ENCODER FRAMECRC_MUXER PIPE_PROTOCOL) += fate-ffmpeg-mjpeg-444-qns +fate-ffmpeg-mjpeg-444-qns: CMD = framecrc -cpuflags 0 -f lavfi -i "testsrc2=s=32x32,format=yuvj444p,noise=alls=100:allf=t+u" -flags +bitexact -dct fastint -idct simple -threads 1 -c:v mjpeg -huffman default -q:v 3 -quantizer_noise_shaping 1 -frames:v 2 diff --git a/tests/ref/fate/ffmpeg-mjpeg-444-qns b/tests/ref/fate/ffmpeg-mjpeg-444-qns new file mode 100644 index 00000000000..bb9bb3c6cc4 --- /dev/null +++ b/tests/ref/fate/ffmpeg-mjpeg-444-qns @@ -0,0 +1,7 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: mjpeg +#dimensions 0: 32x32 +#sar 0: 1/1 +0, 0, 0, 1, 1957, 0xc0f86f6f, S=1, Quality stats, 8, 0x031b0064 +0, 1, 1, 1, 1990, 0xe8208929, S=1, Quality stats, 8, 0x031b0064 -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
