Opened 14 months ago

Last modified 3 months ago

#9445 new defect

QDM2 wrong samplerate

Reported by: cgbug Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: qdm2
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Sample file:

When FFmpeg parses the header the samplerate is detected as 44100hz. But in reality the audio is actually 32000hz. So seems like an incorrect value in the header.

MediaInfo correctly detects it as 32000hz. I can't find the relevant piece of code in its source, so I can't say how it determined that value.

The file has 2 channels and bitrate in header is 128000. So maybe samplerate could be calculated based on that?

128000 (bitrate) / 2 (channels) / 2 (16 bits per sample) = 32000

Attachments (1) (111.2 KB ) - added by Carl Eugen Hoyos 3 months ago.

Download all attachments as: .zip

Change History (4)

by Carl Eugen Hoyos, 3 months ago

comment:1 by Carl Eugen Hoyos, 3 months ago

Why do you believe there is a bug?
Or to say it differently: How long is the sample supposed to play?

comment:2 by cgbug, 3 months ago

Plays for 32s while duration is 44s.

comment:3 by Carl Eugen Hoyos, 3 months ago

Should be tested against an original QuickTime installation

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 51ca1fb516..8f0c888f59 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1613,7 +1613,7 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
     static AVOnce init_static_once = AV_ONCE_INIT;
     QDM2Context *s = avctx->priv_data;
-    int tmp_val, tmp, size;
+    int tmp_val, tmp, size, sample_rate;
     GetByteContext gb;
     /* extradata parsing
@@ -1695,7 +1695,9 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
     av_channel_layout_default(&avctx->ch_layout, s->channels);
-    avctx->sample_rate = bytestream2_get_be32(&gb);
+    sample_rate = bytestream2_get_be32(&gb);
+    if (avctx->sample_rate <= 0)
+        avctx->sample_rate = sample_rate;
     avctx->bit_rate = bytestream2_get_be32(&gb);
     s->group_size = bytestream2_get_be32(&gb);
     s->fft_size = bytestream2_get_be32(&gb);
Note: See TracTickets for help on using tickets.