Skip to content

libvmaf/psnr: cap APSNR at psnr_max when a plane has no error - #1726

Open
lusoris wants to merge 1 commit into
Netflix:masterfrom
vidiko:fix/psnr-apsnr-zero-sse
Open

lusoris wants to merge 1 commit into
Netflix:masterfrom
vidiko:fix/psnr-apsnr-zero-sse

Conversation

@lusoris

@lusoris lusoris commented Nov 17, 2026

Copy link
Copy Markdown

When every frame of a plane is identical, the summed squared error is 0, log10(0) gives -inf, and flush() in integer_psnr.c publishes the max_apsnr ceiling instead of a score: 93 dB luma and 87 dB chroma for the identical 64x64 8-bit clip in the table below, where every frame reads 60 dB. The per-frame psnr_y, psnr_cb and psnr_cr of the same plane are capped at psnr_max (6 * bpc + 12, or the value derived from min_sse), so the aggregate disagrees with every frame. This is one of the two concerns PR 1666 mixed together; the luma-only plane count goes in a separate PR.

Fix

A scored plane (n_pixels > 0) with sse == 0 publishes psnr_max[i], as psnr() and psnr_hbd() do for a zero per-frame error. Every other input goes through the existing expressions unchanged.

Before and after

Identical 64x64 4:2:0 reference and distorted clips, --feature psnr=enable_apsnr=true --json, release build, Y / Cb / Cr:

per frame master cf677baa aggregate this branch aggregate
8 bit 60 / 60 / 60 93 / 87 / 87 60 / 60 / 60
10 bit 72 / 72 / 72 105 / 99 / 99 72 / 72 / 72
8 bit, min_sse=0.5 88 / 82 / 82 93 / 87 / 87 88 / 82 / 82

Tests

Four new cases in test_psnr, built on flush():

  • test_apsnr_zero_sse: zero error at 8, 10, 12 and 16 bits; each aggregate equals the plane cap 6 * bpc + 12.
  • test_apsnr_zero_sse_min_sse: zero error with min_sse set; luma and chroma caps differ and each aggregate equals its own.
  • test_apsnr_mixed_sse: zero chroma error next to a non-zero luma error.
  • test_apsnr_one_sse: the smallest non-zero error still takes the existing expression.

Without the fix, test_psnr fails.

Validation

  • x86-64 Linux, GCC 16.2.1, release build on master cf677baa: the libvmaf unit suite passes 25 of 25, test_psnr included.
  • CI on a fork branch with this commit plus one fork-only commit that pins the workflow actions to commit SHAs (the fork requires pinned actions): libvmaf, checkasm, ffmpeg, Windows and Docker all pass.

Overlap with PR 1618

Both change flush(). PR 1618 fixes the integer overflow in the max_apsnr ceiling, and its test expects that ceiling (193 dB luma, 187 dB chroma) for a plane without error. Its fixture does not call init(), so psnr_max stays 0 there: with this change applied, that test would read 0 (or 108 at 16 bit with init() and the default min_sse). Which value an error-free plane should report is the maintainers' choice; whichever PR lands second needs the other test adjusted.

When every frame of a plane is identical, the summed squared error is
0, log10(0) gives -inf and flush() publishes the max_apsnr ceiling,
e.g. 114 dB for 1080p 8-bit chroma. The per-frame psnr_y/cb/cr of the
same plane are capped at psnr_max (6 * bpc + 12, or the value derived
from min_sse), so the aggregate disagreed with every frame.

Publish psnr_max for a scored plane with zero error. Every other input
takes the existing expressions unchanged.

Add tests for zero error at 8, 10, 12 and 16 bits, zero error with
min_sse, zero chroma error with luma error, and the smallest non-zero
error.

Signed-off-by: Lusoris <lusoris@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant