[FFmpeg-user] Functions for average and variance calulations

Ulf Zibis Ulf.Zibis at gmx.de
Tue Jul 9 01:39:23 EEST 2019


Am 09.07.19 um 00:25 schrieb Ulf Zibis:
> Hi,
>
> are there such functions in the FFmpeg library?
>
> I have an integer array with lets say 13 numbers (accumulated counts of
> X in the range of 0..12) like:
> a) 0 1 0 1 2 7 9 5 4 3 2 0 1
> b) 7 1 9 8 1 6 2 0 0 1 9 1 0
>
> In a) the average X would be ~6 and the variance would be small.
> In b) the average X would be ~3.5 and the variance would be bigger.
>
> I'm looking for functions that can calulate such values with a result in
> float resolution.
>
> -Ulf
For a qudratic average I could use something like:
        float sum = 0;
        for (int i = s->span_r -  s->span_l; i >= 0; i--)
            sum += pow(counts[i], 2);
        float qaverage = sqrt(sum / (s->span_r -  s->span_l + 1));

But for calculating the variance I'm lost. I assume, there are already
solutions for both in the FFmpeg lib.

-Ulf




More information about the ffmpeg-user mailing list