[FFmpeg-devel] apsnr's PSNR formula is different from Wikipedia's formula

Shawn Singh shawnsingh at google.com
Mon Oct 7 20:22:29 EEST 2024


On Tue, Oct 1, 2024 at 3:41 PM Jing Lu <lujin at google.com> wrote:

> Hi ffmpeg-devel@,
>
> I recently came across the apnsr filter
> <https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/af_asdr.c#L238>,
> and the formula for PSNR it uses:
>
> 2.0 * log(s->max) - log(s->nb_samples / s->chs[ch].uv)
>
>
> which is different from the formula given by Wikipedia's PSNR
> <https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio>:
>
> 20 * log_10(MAX) - 10 * log_10(MSE)
>
>
> Some differences I noticed:
> - the forms of the formulae are very different
> - natural number (e) as its log base v.s. 10 as the log base.
> - the choice of s->max
> <https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/af_asdr.c#L213> as
> FLT_MAX or DBL_MAX v.s. 1.0 or 2.0 in popular implementations of
> Wikipedia's formula, for floating point sample formats.
>
> These differences yield significantly different ranges of PSNR values:
> 600+ v.s. mostly around 0 - 100 dB.
>
> I'm wondering:
>
>    - What's the context of apsnr's formula?
>    - If we could change apsnr's implementation to use Wikipedia's formula
>    or add a switch to use Wikipedia's formula?
>
> Thanks,
> Jing
>


Dear all, does anyone else have opinions about this?    Here are some
additional thoughts I have:

- All definitions of decibels that I am aware of use log base 10, including
textbooks and online course materials.  Both Wikipedia and ITU-R V.574-5
cite two standards in particular, ISO 80000-2 (or the upcoming ISO
80000-15) and IEC 60027-3 as measurement standards that define decibels
with base 10.  (I have not seen the ISO or IEC documents myself)
-  The expression (nb_samples / s->chs[ch].uv) is the inverse of MSE.
Therefore, when the error is larger, the final logarithm result will be
lower.  This is backwards from the usual interpretation that more error has
a lower signal-to-noise ratio.

Is there interest in changing the apsnr implementation, if we can provide a
patch?

Thank you!


More information about the ffmpeg-devel mailing list