Support for live radio Shoutcast streams

Vangelis forthnet northmedia1 at the.forthnet.gr
Fri Dec 12 21:06:52 PST 2014


Hello dinkypumpkin :-)

I was browsing the code of your latest get_iplayer commit git-d1caff0:

"Added support for live radio Shoutcast streams"

http://git.infradead.org/get_iplayer.git/blobdiff/97967add4aaa8e3950221e70f8548a46f0ae01fb..d1caff0e19139eba4f4e6cac826a6ebf7061e295:/get_iplayer

> @@ -7245,11 +7251,12 @@ sub get_stream_data {
> (snip)
> +       my $media_stream_shoutcast_prefix;
> (snip)
> +               my ($mediaset, $mobile_mediaset, $shoutcast_mediaset);

> @@ -7257,10 +7264,12 @@ sub get_stream_data {
> (snip)
> +                       $shoutcast_mediaset = 'http-icy-aac-lc-a';
> (snip)
> +               $media_stream_shoutcast_prefix = 
> "http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/$shoutcast_mediaset/vpid/"; 
> # $verpid

> @@ -7411,6 +7427,20 @@ sub get_stream_data {
> (snip)
> +                       # shoutcastaachigh
> +                       if (  $mattribs->{bitrate} >= 192 ) {
> (snip)
> +                       # shoutcastaacstd
> +                       } elsif ( $mattribs->{bitrate} >= 96 ) {

I won't pretend I fully understand all the code in this commit,
but AFAICT you are using ONE FIXED "shoutcast_mediaset" -
as you surely know, the mediaselector/5 API (I'll call it ms5)
uses geo-location; for all National Radios but Radio 3, ms5, when
tried from a UK IP, returns streams which have a real bitrate of
128kbps at 44.1kHz; e.g.

http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_one

whereas Radio 3:

http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_three

may return media bitrate="128" but the real bitrate of the stream is 
320kbps at 44.1kHz.
(you can check the stream in an audio player - I used Winamp & VLC).
IIUIC, the code would declare all streams as being "shoutcastaacstd".
Now the situation is quite different for overseas IPs (yes, the beeb does 
offer
Shoutcast streams internationally...);

When I try the BBC Radio 1 ms5 URL above from my non-UK IP, this is what I 
get:

<media bitrate="128" encoding="aac" kind="audio" 
service="pc_stream_audio_simulcast_nonuk_a_lm_p010" 
type="audio/x-scpls"><connection authExpires="2014-12-13T05:16:52+00:00" 
authExpiresOffset="6516" 
href="http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio1_p?s=1418434096&e=1418448496&h=b83f3eace614bf5e621a6cf9911e83c6" 
priority="5" protocol="http" supplier="ll_icy"/><connection 
authExpires="2014-12-13T05:06:13+00:00" authExpiresOffset="5877" 
href="http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio1_q?s=1418434096&e=1418448496&h=2fdb80f2ac297da7bd0d147aa032eb6f" 
priority="10" protocol="http" supplier="ll_icy2"/></media>

Again, media bitrate="128" is MISLEADING, since the Int'l shoutcast streams
for all National Radios (Radio 3 included) are 56kbps at 32kHz
(you can try the intl stream yourself - it even works without the 
auth-token).

But THERE EXIST two more "shoutcast_mediasets":

$shoutcast_mediaset = 'http-icy-aac-lc-b'

This one ONLY WORKS for UK IPs, revealing
56kbps at 32kHz streams for all National Radios
(identical specswise to the overseas streams, but
different to them):

http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-b/vpid/bbc_radio_three

where the statement media bitrate="56" is indeed true!
(when tried from a non-UK IP, you get:
<error id="geolocation"/> )

What "shoutcastradiomode" would your code assign to these streams?

$shoutcast_mediaset = 'http-icy-he-aacv2-a'

This third and final one works the same for UK and non-UK IPs,
producing data for Shoutcast streams that are 48kbpsHE-AACv2 at 44.1kHz
(these are different streams for UK & overseas):

http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-he-aacv2-a/vpid/bbc_radio_one

What are your thoughts on adding support for these additional 
shoutcast_mediasets?
And I don't know if it's the same thing,
but Winamp reports the streaming servers as being Limecast 2.0.0 -
is this a Limelight server using the Shoutcast protocol?

> @@ -10151,6 +10188,183 @@ sub get {
> (snip)
> +package Streamer::shoutcast;

What I currently do for recording these streams is:
1. Download via browser and save this pls file:
http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-a/vpid/bbc_radio_one/format/pls.pls
2. Open in an editor & copy the href value
(I usually copy the href value of supplier="ll_icy2";
this is a backup stream not used very much by clients
and less prone to breakage...)
3. Use ffmpeg to dump:
ffmpeg -i 
"http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio1_p" -c:a 
copy -bsf:a aac_adtstoasc "BBC Radio 1 Live.m4a"
Does your code do pretty much the same?

> +       # Convert aac to aac/mp4a/mp3
> (snip)
> +               if ( $opt->{aactomp3} ) {

Would you consider transcoding in real-time?
If I record a 2 hour live programme, why wait an
additional time (especially on low end machines)
for the transcoding to complete?
For the live rtmp streams we have to also call
FFmpeg for on-the-fly transcoding, but for the
saving of the icy streams we are already using this.
In my ancient 2007 system,

ffmpeg -i 
"http://bbcmedia.ic.llnwd.net/stream/bbcmedia_intl_lc_radio1_p" -c:a 
libmp3lame -ab 128k -ar 44100 -ac 2 "BBC Radio 1 Live.mp3"

works with very little impact on resources;
when I press q after 3 hours, MP3 file is already there
to tranfer to my Portable MP3 Player (does not play AAC).

And one final query:
If the options
-p "[value]" --partial-proxy
are used in GiP, will the actual stream be fetched without the proxy,
as is the case with rtmp streams, or --partial-proxy will not apply
for HTTP streams?
(FYI, host "bbcmedia.ic.llnwd.net" is not geo(b)locked...).

Apologies for the lengthy comments,
I aimed to contribute/recommend  rather than dispute your
coding wizardry!

Merry Christmas to all,
Vangelis. 




More information about the get_iplayer mailing list