karlheyes / icecast-kh

KH branch of icecast
GNU General Public License v2.0
298 stars 106 forks source link

Incorrect samplerate for liquidsoap HE-AACv2 source #184

Open waster opened 6 years ago

waster commented 6 years ago

Hello,

OS: Ubuntu 16.04 server Icecast 2.4.0-kh6-2-gddfd9c5

We're using liquidsoap to send stream on test moutn point "/test.aacp":

output.icecast(%fdkaac(bitrate=64, channels=2, samplerate=44100, afterburner=true, aot="mpeg2_he_aac_v2", transmux="adts", sbr_mode=true),icy_metadata="true",
        format="audio/aacp",
        host="82.202.236.188",
        mount="test.aacp",
        port=10000,
        password="XXXXXXXXXX",
        description="Stream transcoder based on liquidsoap",
        genre="various",
        url="http://82.202.236.188:10000/test.aacp",
        name="test",
        public=true,
source)

Problem is that sample rate displayed on http://82.202.236.188:10000/ has 22050 value.

So the corresponding tag in http://82.202.236.188:10000/admin/stats value is:

<source mount="/test.aacp">
   ...
   <mpeg_samplerate>22050</mpeg_samplerate>
   ...
</source>

ffrpobe for the same stream displays correct value 44100:

$ ffprobe http://82.202.236.188:10000/test.aacp
...
Input #0, aac, from 'http://82.202.236.188:10000/test.aacp':
  Metadata:
    icy-br          : 64
    icy-description : Stream transcoder based on liquidsoap
    icy-genre       : various
    icy-name        : test
    icy-pub         : 1
    icy-url         : http://82.202.236.188:10000/test.aacp
    StreamTitle     : Juicy 
  Duration: N/A, bitrate: 64 kb/s
    Stream #0:0: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 64 kb/s

Can it be fixed?

Regards, Andrey.

karlheyes commented 6 years ago

strictly speaking, what you are seeing is correct. Icecast only detects the details at the ADTS level which for the stream you are talking about is 22050hz. The AACv2 profile (specifically SBR), which involves some further decoding, simulates the 44.1khz signal based on information within 22khz. It would require some further decoding work to extract that correctly.

karl

waster commented 6 years ago

Yes, I agree with that, but the end samplerate after SBR is 44100, and according to http://wiki.hydrogenaud.io/index.php?title=Fraunhofer_FDK_AAC#HE-AAC.2FSBR :

The end result is an apparent full bandwidth transmission (as if no low-pass filter was applied)

I guess the right thing is to get end sample rate for the source? Please correct me if I'm wrong.

karlheyes commented 6 years ago

indeed. Assuming you know the specifics of decoding the profile/SBR setting then it could be added to the aac parsing routine. There is also the channel aspect as well, PS doing a similar thing for the channels.

karl