PR #25614 opened by Kilian (lusoris) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25614 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25614.patch
`av1_qsv` exports the chroma film grain parameters with their bitstream bias, so every consumer of `AVFilmGrainParams` gets values that are off by 128, 128 and 256. This PR subtracts the bias when the plane has scaling points. Found by the automated review of PR 24974, which fixes the same conversion elsewhere, and independent of it. Measured on 16 streams encoded with `libaom-av1 -aom-params film-grain-test=N`, N from 1 to 16, three frames each, comparing `showinfo` film grain output against `libdav1d`, on Intel Arc with the iHD driver: | Vector | `libdav1d` | Master `av1_qsv` | This PR | | --- | --- | --- | --- | | 1 | `uv_mult[0]=119 uv_mult_luma[0]=64 uv_offset[0]=-238` | `247 192 18` | matches `libdav1d` | | 2 | `0 64 0` | `128 192 256` | matches `libdav1d` | Master differs from `libdav1d` on the 12 vectors with chroma scaling points, in the 6 parameters of each of the 3 frames, and matches on the other 4. This PR matches on all 16. Without scaling points the runtime reports zero and the fields stay zero, as with `libdav1d`. Tested with GCC 16 on 17a4a474f4. FATE has no `av1_qsv` test; `fate-source` passes. >From 003f9ab865c5fac88368b09798c58c161ebe8636 Mon Sep 17 00:00:00 2001 From: lusoris <[email protected]> Date: Fri, 30 Oct 2026 13:20:03 +0100 Subject: [PATCH] avcodec/qsvdec: remove the bias from exported AV1 film grain chroma params The runtime returns cb_mult, cb_luma_mult, cb_offset and their Cr counterparts as the raw bitstream values, biased by 128, 128 and 256. AVFilmGrainParams.codec.aom stores them unbiased, as libdav1d and the native AV1 decoder export them, so every consumer of the side data got values that were off by the bias. Subtract the bias only when the plane has scaling points. Without points the syntax elements are absent from the bitstream, the runtime reports zero, and the fields stay zero as they do with libdav1d. Signed-off-by: lusoris <[email protected]> --- libavcodec/qsvdec.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index 990e46ea1d7..ca191abb6e1 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -680,12 +680,17 @@ static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam aom->ar_coeffs_uv[1][i] = ext_param->ArCoeffsCrPlus128[i] - 128; } - aom->uv_mult[0] = ext_param->CbMult; - aom->uv_mult[1] = ext_param->CrMult; - aom->uv_mult_luma[0] = ext_param->CbLumaMult; - aom->uv_mult_luma[1] = ext_param->CrLumaMult; - aom->uv_offset[0] = ext_param->CbOffset; - aom->uv_offset[1] = ext_param->CrOffset; + if (aom->num_uv_points[0]) { + aom->uv_mult[0] = ext_param->CbMult - 128; + aom->uv_mult_luma[0] = ext_param->CbLumaMult - 128; + aom->uv_offset[0] = ext_param->CbOffset - 256; + } + + if (aom->num_uv_points[1]) { + aom->uv_mult[1] = ext_param->CrMult - 128; + aom->uv_mult_luma[1] = ext_param->CrLumaMult - 128; + aom->uv_offset[1] = ext_param->CrOffset - 256; + } return 0; } -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
