mkvmerge mis-identifies certain AAC streams as 24 kHz instead of 48 kHz
The problem is not restricted to audio files. It also happens with video files containing an AAC audio stream.
Here is an Matroska audio file demonstrating the problem.
Unpack it with
$ openssl base64 -d << EOF | zcat > problem.mka
H4sIAAAAAAACA5Nyvb94sVNbI6PTdyD+1Mji9LmRw6mpIzexpCi/ODvRqR0o1NrI
JBHckM7IAAKstwR9Z5cc2N8io8xi5ru7O3h1i6jnyrTgNY0LITyxkHXZQN5H3909
QJ5QyOH04DVNTD0QrkzwbqBkE+u+NxDTGIIZqA9A7jm9v+Xua6eZWtc3NvM7Ofg2
9PoklqWZWuiZmOoZGhiEO6Lyi5dM6L84OSPFqdbko+zE9rWTNVe5dHY4uDaAzQP5
yHHq/pYnWfFx6yDuZmy73shYfLTD2My0su7h5gVzGhmUts5pLs1LaWt1jHd0dG5u
ZHo4Z34j09YOh+sFYC0VCGZSSqNC8qImYQFoKDBaMIwCsgAoeX3Z3xLp5veuuBia
pNSTDzSkn4BypFwXt7v6Ofu7uAa5tKNFOkyDcfKB7mREXKafWOS6uMMlNMgxxNPf
z6V9ioGBFRjpGZgYG4ABA4O887ZSp837Wyw2trI9b2RY7LS8kYGhQVGAlWGB9BYW
BZj7mN0azP83jMYTAuT/Hw0DJHDvAF2tY7wCKoGn729ZyNFXurt/cyPD9i5gyf+x
iZn1QyMnALTYmzUOBgAA
EOF
If the above extraction commands do not work for you, extract the file manually with alternative utilities available to you: The lines between the "$"-line and the "EOF" lines contain the base-64 encoded gzip-compressed contents of the file "problem.mka".
Now examine the file with mkvmerge:
$ mkvmerge --identify --identification-format json problem.mka | grep freq
"audio_sampling_frequency": 24000,
But other well-known utilities think differently:
$ mediainfo problem.mka | grep Sampling
Sampling rate : 48.0 kHz
$ ffprobe -v error -hide_banner -show_format -show_streams -print_format json -i problem.mka | grep sample_rate
"sample_rate": "48000",
I am also fairly certain that the file actually uses 48 kHz, because 24 kHz would be a rather exotic sample rate.
However, mkvmerge does make that mistake for all AAC streams, but just for some.
Comparing the output of the above "mkvmerge --identify" command for the above file with another .mka file not triggering the mistake, I found the following difference:
The file incorrectly identified as 24 kHz (the above file) had the "aac_is_sbr" setting set to "true".
The file correctly identified as 48 kHz (most Matroska files do) had the "aac_is_sbr" setting set to "unknown".
So it seems the SBR setting of AAC streams is at the core of the problem.