Opened 8 months ago

Last modified 7 months ago

#10535 new enhancement

astats bit depth, first number not very useful

Reported by: danadam Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: astats
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

"Bit depth" line in astats filter output reports two numbers: X/Y

The meaning of the second number is clear: bits less significant than Y are not used.

The meaning of the first number is: number of bits from Y until the most significant bit that toggles to 1.

Now the thing is, that first number is not very useful. Most of the audio has samples with both positive and negative values. With two's complement representation, the most significant bit is set to 1 for any negative value.

As a result, for most of the audio the first number will always be the same as the second number.

A more useful value for X would be: max of number of bits from Y until:

  • the most significant bit that toggles to 1, for positive samples,
  • the most significant bit that toggles to 0, plus 1, for negative samples.

This is actually what SoX is reporting in its "stats" effect.

In attachment I included 2 files: "sine_no_dc.flac" and "sine_with_dc.flac".

"sine_no_dc.flac" is a normal sine, 1 kHz at -25 dBFS with dithering at 14 bits. This means that top 4 bits and bottom 2 bits are not really used and SoX reports it like that:

]$ sox "sine_no_dc.flac" -n stats
...
Bit-depth      10/14

But because it has samples with negative values, "astats" reports:

]$ ffmpeg -i "sine_no_dc.flac" -af astats -f null /dev/null
...
[Parsed_astats_0 @ 0x5618db467ac0] Bit depth: 14/14

"sine_with_dc.flac" is similar but it has DC component, so that all samples are positive. This time both SoX and ffmpeg report the same:

]$ sox "sine_with_dc.flac" -n stats
...
Bit-depth       9/14

]$ ffmpeg -i "sine_with_dc.flac" -af astats -f null /dev/null
...
[Parsed_astats_0 @ 0x55aa1e5d3b80] Bit depth: 9/14

The files were generated with SoX:

sox -r44.1k -n -b16 "sine_no_dc.flac"   synth 1    sin 1k norm -25 dither -p14
sox -r44.1k -n -b16 "sine_with_dc.flac" synth 1 51 sin 1k norm -25 dither -p14

Attachments (2)

sine_no_dc.flac (15.5 KB ) - added by danadam 8 months ago.
sine_with_dc.flac (16.3 KB ) - added by danadam 8 months ago.

Download all attachments as: .zip

Change History (3)

by danadam, 8 months ago

Attachment: sine_no_dc.flac added

by danadam, 8 months ago

Attachment: sine_with_dc.flac added

comment:1 by Elon Musk, 7 months ago

Added 2 more bit depth results. First one calculates bit depth of negative samples differently now.

Note: See TracTickets for help on using tickets.