On 11/17/2025 10:01 AM, Erdinc Kaya via ffmpeg-devel wrote:
- Correctly scale bitrate by bits_per_coded_sample instead of assuming 8 bits per byte.

When is a byte not 8 bits?

- Prevents wrong bitrate reports for 16-bit PCM WAV files.

Do you have a sample that gets the wrong bitrate? I generated one just now, a 1 second 44100Hz 16bit stereo pcm wav file, and it gave me the correct bitrate of 1411 kb/s.

This function reads bitrate from a coded value in the container, BytePerSec, which is converted to bits. So not sure why you think it needs to be altered.


Signed-off-by: Erdinc Kaya <[email protected]>
---
  libavformat/riffdec.c | 4 ++++
  1 file changed, 4 insertions(+)

diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 30835d5f36..d63edc6377 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -130,6 +130,10 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
              par->bits_per_coded_sample = avio_rb16(pb);
          }
      }
+
+    if (par->bits_per_coded_sample)
+        bitrate *= 8.0 / par->bits_per_coded_sample;

bits_per_coded_sample is going to be 16 for a 16 bit pcm sample, clearly, so this here will halve the value in bitrate.

+
      if (id == 0xFFFE) {
          par->codec_tag = 0;
      } else {

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to