TIPS How to play AAC stream for MOH?

Halea

Well-Known Member
Joined
Aug 12, 2016
Messages
1,164
Reaction score
917
I'm trying to add an MOH stream to an older IncrediblePBX system, on which in the past I always successfully used something like:
/usr/bin/mpg123 -q -s --mono -r 8000 -f 8192 -b 0 http://icecast.radiofrance.fr/franceinfo-midfi.mp3

The new source that I'm trying to make work is encoded in AAC format which doesn't seem to be compatible with mpg123.

Would you know of any other command line player similar to mpg123 that can playback AAC streams and can be used with freepbx/asterisk?

If you wonder what the stream looks like the following is a perfect specimen:
(The actual stream that I'll be using is a licensed source, not the one above, but its format is identical to the one above)

It can be played (and analyzed) with ffplay (from the ffmpeg toolkit). Unfortunately I can't get ffplay to cooperate with freepbx/asterisk.
If anyone has experience in doing so that might be my answer.

TIA
 
Seems you can't play AAC with mpg123


It seems it can be done with VLC (have to install it of course).

something like

Code:
/usr/bin/vlc-wrapper rtp://@:5004 --sout '#transcode{acodec=ulaw,ab=64,channels=1,samplerate=8000}:std{access=file,mux=raw,dst=-}'



I tried it with your URL:

Code:
/usr/bin/vlc-wrapper https://stationplaylist.com:7104/listen.aac --sout '#transcode{acodec=ulaw,ab=64,channels=1,samplerate=8000}:std{access=file,mux=raw,dst=-}'


I am not getting an error, but I am not hearing anything.


NoOp("PJSIP/2007-0000005e", "Blackhole Dest: Put caller on hold forever") in new stack
-- Executing [musiconhold@app-blackhole:2] Answer("PJSIP/2007-0000005e", "") in new stack
> 0x6a900018 -- Strict RTP learning after remote address set to: 192.168.1.119:10018
> 0x6a900018 -- Strict RTP switching to RTP target address 192.168.1.119:10018 as source
-- Executing [musiconhold@app-blackhole:3] MusicOnHold("PJSIP/2007-0000005e", "") in new stack
-- Started music on hold, class 'default', on channel 'PJSIP/2007-0000005e'
> 0x6a900018 -- Strict RTP learning complete - Locking on source address 192.168.1.119:10018
-- Stopped music on hold on PJSIP/2007-0000005e
== Spawn extension (app-blackhole, musiconhold, 3) exited non-zero on 'PJSIP/2007-0000005e'


I tried playing the stream from VLC on my Debian laptop. Maybe this is why I cannot hear anything?

You attempted to reach stationplaylist.com. However, the security certificate presented by the server is unknown and could not be authenticated by any trusted Certificate Authority.
This problem may be stem from an attempt to breach your security, compromise your privacy, or a configuration error.

They are using Let's Encrypt

I tried running it from my PBX on the command line

Code:
/usr/bin/vlc-wrapper -vvv https://stationplaylist.com:7104/listen.aac --sout '#transcode{acodec=ulaw,ab=64,channels=1,samplerate=8000}:std{access=file,mux=raw,dst=-}'

...
[717047c8] gnutls tls client error: Certificate verification failure: The certificate is NOT trusted. The certificate issuer is unknown.
[717047c8] gnutls tls client debug: 1 certificate(s) in the list
[717047c8] gnutls tls client debug: no known certificates for stationplaylist.com
[717047c8] main tls client error: TLS session handshake error
[717047c8] main tls client error: connection error: No such file or directory
[717047c8] gnutls tls client debug: TLS handshake: Error in the push function.
[717047c8] gnutls tls client error: TLS handshake error: Error in the push function.
[717047c8] main tls client error: TLS session handshake error
[717047c8] main tls client error: connection error: Network is unreachable
[71704060] access stream error: HTTP connection failure
[71704060] main stream debug: no access modules matched
[71900520] main input error: Your input can't be opened
[71900520] main input error: VLC is unable to open the MRL 'https://stationplaylist.com:7104/listen.aac'. Check the log for details.
[010b78a8] main playlist debug: dead input

I got around the certificate with the switch " --sout --gnutls-system-trust" but now getting the same error as before with ffmpg123.

In the command line, I am seeing

[72c00e70] main stream out warning: missing value for option mux
[72c00e70] main stream out warning: missing value for option access
[72c00e70] main stream out debug: set config option: sout-standard-dst to --gnutls-system-trust
[72c00e70] stream_out_standard stream out error: no mux specified or found by extension
[72c00e70] main stream out debug: no sout stream modules matched
[72c00e70] main stream out debug: destroying chain... (name=(null))
[72c00e70] main stream out debug: destroying chain done
[72c00c88] main stream output error: stream chain failed for `standard{mux="",access="",dst="--gnutls-system-trust"}'
[71600520] main input error: cannot start stream output instance, aborting
[01236920] main playlist debug: dead input

Seems maybe the certificate is still an issue.


I tried switching to http from https with some success.


Try this one:

Code:
/usr/bin/cvlc http://stationplaylist.com:7104/listen.aac '#transcode{acodec=ulaw,ab=64,channels=1,samplerate=8000}:std{access=file,mux=raw,dst=-}'

I think I tried too many times to connect, and now seem to be unable to connect now. A while ago, in the command line it had shown I had connected, and even was showing the name of the music, and artist.

[71a00520] main input debug: `http://stationplaylist.com:7104/listen.aac' successfully opened
...
[00bbec8] main audio output debug: inserting 2384 zeroes
[71500b18] http stream debug: New Icy-Title=Joe Harnell - George Gershwin Montage - Joe Harnell Plays Solo Piano


I switched over to cvlc when I saw a warning about no interface

main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
 
Last edited:
...
It seems it can be done with VLC (have to install it of course).
...
I didn't mention in my OP but VLC was my first attempt to play the AAC stream in asterisk. But I quickly noticed that it was putting a heavy load on the CPU so I gave up on it right away.
Some players are very aggressive on the stream fetching part and they multiply their connections quickly without giving time to settle to the server, which in turn causes the server to police the connections by slowing down or rejecting them, which in turn make the player to become even more aggressive! Eventually the whole thing crashes and the cycle restarts.
 
All this time I thought that ffmpeg was the conversion component and ffplay was the player!

You're not wrong; in this case, ffmpeg is converting the AAC stream into an slin stream and outputting it to the STDOUT pipe which is what Asterisk wants for an MOH stream.
 
To follow up on my OP;

Thanks to @billsimon 's suggestion I was able to get my new AAC stream up and running as a MOH source:
ffmpeg -i https://stationplaylist.com:7104/listen.aac -f s16le -ac 1 -ar 8000 pipe:1
The quality of the stream is very good and ffmpeg's extra load on the CPU is quite negligible.

Two things that I noticed:

1- It takes considerably longer for the AAC stream to show up in MOH, almost like a minute 30 seconds (average of 3 readings), which initially made me think that this wasn't working. But it's not an issue because once the stream is established and properly passed to MOH it is instantly available to any connection which is put on hold, or to those who want/need some background music to play in their office. So, even though there is a start up delay it's not an issue. (I think ffmpeg is buffering the converted output, because the AAC feed's start is instant when I connect to it with other tools like VLC)

2- This one is a bit more critical, so I am trying to figure out a solution!

When ffmpeg converts the AAC stream in its default settings, it puts out a very loud signal. To the point that when someone plays it through the speakerphone of a desk phone at the minimal sound level it is still very loud.
Further, with certain loud tunes, signal clipping starts showing up. That translates into an annoying clickety sound.

So, I am trying to attenuate the ffmpeg output level with the parameter "volume=0.5" as shown in the following script that I found on the net and from which I was trying to learn. But the volume setting didn't work, and when I finally went on to check the syntax in the man pages of ffmpeg I noticed that there is no such command line parameter! Now I am completely confused!

Initially I thought that I was having an issue with the quote marks, since the script showed "curly" double-quote marks. But now I am wondering whether this parameter is deprecated, and if so what is it replaced with?

The script that I was looking at is (note that the double quotes are different between lines 8, 10 and 15):
#!/bin/sh

# change following to yes in order to enable debugging output:
DEBUG=no

PLAYER=/usr/bin/ffmpeg

if [ “$DEBUG” = “yes” ]
then
PLAYER="$PLAYER -vvv "
else
exec 2>/dev/null
fi

exec $PLAYER -i “$1” -ar 8000 -ac 1 -acodec pcm_s16le -f s16le -af “volume=0.5” pipe:1

Any thoughts about how to reduce the volume of the ffmpeg output?
TIA
 
Last edited:
I reduced the output to 1/8 with "-vol 32" parameter to bring it to the same level as the other sources.
Everything is working well now. Case closed!
 
2- This one is a bit more critical, so I am trying to figure out a solution!

When ffmpeg converts the AAC stream in its default settings, it puts out a very loud signal. To the point that when someone plays it through the speakerphone of a desk phone at the minimal sound level it is still very loud.
Further, with certain loud tunes, signal clipping starts showing up. That translates into an annoying clickety sound.

So, I am trying to attenuate the ffmpeg output level with the parameter "volume=0.5" as shown in the following script that I found on the net and from which I was trying to learn. But the volume setting didn't work, and when I finally went on to check the syntax in the man pages of ffmpeg I noticed that there is no such command line parameter! Now I am completely confused!

Initially I thought that I was having an issue with the quote marks, since the script showed "curly" double-quote marks. But now I am wondering whether this parameter is deprecated, and if so what is it replaced with?

The script that I was looking at is (note that the double quotes are different between lines 8, 10 and 15):


Any thoughts about how to reduce the volume of the ffmpeg output?
TIA
Here's what I created as /usr/sbin/stream (chmodded to 755) that works well.

Code:
#!/bin/sh

# change following to yes in order to enable debugging output:
DEBUG=no

PLAYER=/usr/bin/ffmpeg

if [ "$DEBUG" = "yes" ]
then
PLAYER="$PLAYER -vvv "
else
exec 2>/dev/null
fi

exec $PLAYER -i $1 -ar 8000 -ac 1 -f s16le -vol 32 pipe:1
 
Last edited:
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Back
Top