The Beebotron

The Main Forums => Geek Speak => Topic started by: Ed on June 30, 2017, 03:41:58 PM

Title: Download 384 kbps LIVE stream
Post by: Ed on June 30, 2017, 03:41:58 PM
It is trivial to download the LIVE stream for Radio 4 Extra, because the url never changes (and the Beeb make no attempt to obfuscate that url).

To download the 384 kbps live stream, run a .bat file (a plain text file with the extension .bat instead of .txt) containing these two lines -

Code: [Select]
  set ffmpeg=C:\Program Files\FFMPEG\ffmpeg.exe

  "%ffmpeg%" -v 16 -stats -i "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_p" R4Extra.mp2


To get the ffmpeg.exe program, see this link: http://ffmpeg.zeranoe.com/builds/ (http://ffmpeg.zeranoe.com/builds/)

The program does not need installing. Just put the .exe file in the directory you specified in the .bat file.

If you prefer a lower bitrate, a 128 kbps stream is available instead: in the .bat file change .mp2 to .m4a so that ffmpeg gets the m4a stream instead (it's actually a variable bitrate, centered on 135 kbps).

If you prefer the mp3 stream, change .mp2 to .mp3 so that ffmpeg gets the mp3 stream instead (which is a fixed bitrate of 128 kbps).


These are the two live stream urls for Radio 4 Extra (either of which can be used in the .bat file):

  http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_p

  http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4extra_mf_q


Title: Re: Download 384 kbps LIVE stream
Post by: Ed on July 25, 2017, 02:25:09 PM
Although the above described method does work, I was never happy with it, because the audio stream which it accesses is unstable. The connection rarely lasts more than 15 minutes at a stretch.

So although you can reconnect when that happens, I decided to look around for a method which gives better results. And I eventually found the url's detailed below, each of which gives a stream which, in my tests, is usually stable over several hours.


Here, then, is the new method for forcing the live stream to run at 384 kbps, instead of at the standard bitrate of 320 kbps.


Use any of these four command lines (each is actually a 2-line command line) -

Code: [Select]
SET url=http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_med/ak/bbc_radio_four_extra.m3u8
ffmpeg  -v 16  -stats  -i %url%  output.mp2

Code: [Select]
SET url=http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_four_extra.m3u8
ffmpeg  -v 16  -stats  -i %url%  output.mp2

Code: [Select]
SET url=http://as-hls-uk-live.akamaized.net/pool_6/live/bbc_radio_four_extra/bbc_radio_four_extra.isml/bbc_radio_four_extra-audio=320000.m3u8
ffmpeg  -v 16  -stats  -i %url%  output.mp2

Code: [Select]
SET url=http://as-hls-uk-live.akamaized.net/pool_6/live/bbc_radio_four_extra/bbc_radio_four_extra.isml/bbc_radio_four_extra-audio=320000.norewind.m3u8
ffmpeg  -v 16  -stats  -i %url%  output.mp2


To play the command line, copy-and-paste the url into, for example, VLC Media Player (http://www.videolan.org/vlc/).

To download the live stream, copy-and-paste one of the 2-line command lines into a batch file ( e.g. download.bat ), put the batch file in the same directory as the ffmpeg.exe (https://ffmpeg.zeranoe.com/builds/) program, then run the batch file.

Notes on creating a batch file:  Create a Batch file (https://www.google.co.uk/search?as_q=&hl=en&num=20&btnG=Google+Search&as_epq=BATCH+FILE&as_oq=&as_eq=&lr=lang_en&cr=&as_ft=i&as_filetype=&as_qdr=all&as_occt=any&as_dt=i&as_sitesearch=&as_rights=&safe=images&gws_rd=cr&ei=wDZ3WZS6FISegAaFj7jIDA)





Title: Re: Download 384 kbps LIVE stream
Post by: ilainftw on July 27, 2017, 04:01:55 PM
Although the above described method does work, I was never happy with it, because the audio stream which it accesses is unstable.
Those are Shoutcast streams, which are likely to be less reliable than the HLS HTTP-based chunked audio streams.
Here, then, is the new method for forcing the live stream to run at 384 kbps, instead of at the standard bitrate of 320 kbps.
That is not what you are doing. The audio stream remains 320k AAC (or 128k in your first example). You are merely instructing ffmpeg to transcode it to MPEG-2 when saving to a file. 384k is the default bit rate used by ffmpeg for MP2 encoding, so you're just upsampling the source audio. It's OK if you prefer that output, but for most people it will suffice to save the AAC stream as-is into an MPEG-TS file (perhaps with remux to M4A for final recording). Transcoding (usually to MP3) would only absolutely be required if you have a hardware player that doesn't support AAC audio or can't handle large AAC files (from lengthy recordings).
Use any of these four command lines (each is actually a 2-line command line) -
In general, it's better to use the variant playlists, e.g.:
Code: [Select]
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_four_extra.m3u8rather than the stream playlists they contain, e.g.:
Code: [Select]
http://as-hls-uk-live.akamaized.net/pool_6/live/bbc_radio_four_extra/bbc_radio_four_extra.isml/bbc_radio_four_extra-audio=320000.m3u8The stream playlists may change over time. Each variant playlist for BBC radio contains only a single stream, so no danger of getting an unexpected bit rate.
Title: Download 384 kbps LIVE stream
Post by: Ed on July 31, 2017, 05:03:12 PM
Your comments are interesting, but I believe you are wrong.

I have the ability to monitor the audio stream itself, and to measure its bitrate. There are various software tools which include this capability. My tests establish that ffmpeg is actually fetching a 384 kbps bitrate stream.

Let's try the easiest test. I'm running Windows 7: for anyone using it, and interested in carrying out a test, all you need do is right-click on the Desktop task bar, then click 'start task manager'.

The 'Networking' tab in Task Manager will show the bitrate of the incoming stream: both as a visual graph, and (in the column 'Bytes Received per Interval') as a number. It's important to only have a single stream download running when you're doing this test (otherwise you'll see the combined data for all running streams).

It's quite good fun to take one of my .mp2 download methods, and run it with Task Manager open so you can watch the results. Then change the .mp2 extension to .wav and re-run the test: watch the incoming rate shoot up from 384 kbps to 1,500 kbps !

(Whatever figures you're seeing will quadruple, as will the average height of the visual display graph. Because these are 'chunked' streams, the audio is delivered in discontinuous chunks, for reliability, not as a continuous steady stream at 384 kb/sec, so what you see is an average, rising and falling, not a steady line.)

Not that I recommend downloading the uncompressed .wav stream, because it gives you a gigantic file size. But it makes a powerful demonstration of my point.


@ilainftw : I'd be interested to know what software you are using to measure the bitrate. Perhaps it's something I can run in Windows 7 ?
Title: Re: Download 384 kbps LIVE stream
Post by: ilainftw on July 31, 2017, 11:11:04 PM
You are confusing download speed with audio bitrate. Just because you are downloading HLS chunks faster than >320k doesn't mean the encoded audio is >320k. If you are downloading an HLS on-demand stream or a live stream with a rewind buffer, then of course ffmpeg will download as fast as it needs to (upstream permitting) to do whatever transcoding you have configured. Without a rewind buffer, HLS live stream downloading settles near the nominal audio bit rate. The BBC doesn't give you >320k audio just because you ask for it (but you're really not doing that). The BBC doesn't give you MPEG-2 or WAV audio just because you ask for it (but you're really not doing that either).  When you think about how HLS streams are produced, and how the BBC provides only one stream per variant playlist, that wouldn't make any sense. You only get apparently higher bitrates in your output files because you're transcoding and upsampling the audio stream after it is downloaded. Prove it to yourself by downloading a 320k live stream with no transcoding:
Code: [Select]
ffmpeg -i URL -c copy file.ts then check the audio bit rate in the resulting file. It will contain 320k audio. Do the same with a 320k on-demand stream, which will show the same result.