ffmpegffprobe

Detecting the value scale of statistics returned from ffprobe


I'm using ffprobe to detect max and min levels for various audio files. An example of the command I'm using is:

ffprobe -v error -f lavfi -i amovie=my_song.mp3,asetnsamples=n=4410,astats=metadata=1:reset=1 -show_entries frame_tags=lavfi.astats.Overall.Max_level,lavfi.astats.Overall.Min_level -of json

The max/min level values returned use different scales, depending on the format of the input file.

For example, an MP3 file may return fractional values from -1.0 to 1.0 representing a percent of maximum level. A signed 16 bit WAV file returns values in the range -32,768 to 32767. A signed 32 bit FLAC file uses the range -2,147,483,648 to 2,147,483,647. In these cases, the bit size of the values matches the bit depth of the audio file.

In other cases, such as a signed 8 bit WAV file, the results are returned using a scale that does not match the input file, such as 16 bit scale (-32,768 to 32767).

I'm trying to determine if there's anyway to detect which format or scale ffprobe is using when the results are returned, besides trying to do it heuristically. I haven't been able to find any other value that gets returned which specifically reflects the number system being used to generate these levels values. sample_fmt does, in some cases, match, but in cases such as a s8 WAV file, sample_fmt would return s8, which does not match the number format of the returned levels values (s16).

If it's not possible to request this information from ffprobe JIT, is there anywhere in the code base that would describe how it determines which scale to use?


Solution

  • Each audio filter can operate upon some specific set of sample formats. If the input isn't in one of those formats, the framework will convert it before passing the frame onto the filter. astats works with signed integer 16, 32 & 64 bits as well as floating point 32 and 64 bit but not with (un)signed 8-bit.

    To ffprobe show_entries, add stream=sample_fmt for identification.