[FFmpeg-trac] #10535(avfilter:new): astats bit depth, first number not very useful
FFmpeg
trac at avcodec.org
Fri Aug 25 01:52:43 EEST 2023
#10535: astats bit depth, first number not very useful
----------------------------------+---------------------------------------
Reporter: danadam | Type: enhancement
Status: new | Priority: normal
Component: avfilter | Version: git-master
Keywords: astats | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
----------------------------------+---------------------------------------
"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
}}}
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10535>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list