Author Topic: How to capture Radio Streams with MusicBee using FFmpeg - w/ DATE on Filename  (Read 1761 times)

maurirope

  • Newbie
  • *
  • Posts: 19
If any of you are like me, you like to listen to (a) live radio stream(s) from several different journalistic or opinion talk shows oftentimes along your breakfast, brunch, lunch, snack, tea, dinner or supper coffee or... Mate for my fellow Rioplatense latinos.

If any of you had a hard time making the Streamripper suggested Tip work, like I had, I believe this one new ACME TrickTip™ will be well received. (Cheers to the folks at the previous topic who inspire this one).

If you also had a hard time coping with the Template Editor and flexibility of the metadata items provided in there, this ACME TrickTip™ will serve you well to customize your resulting output file, whatever the input is, provided it is supported for encoding by the FFmpeg library, which is very well supported itself.

These are pretty simple steps to follow to get your thing working in no time.

1. Download the Windows binary build of FFmpeg provided at: https://ffmpeg.org/download.html#build-windows

2. Place the ffmpeg.exe binary executable that can be found within the build you downloaded wherever you like to and remember where you placed that, (make sure MusicBee can access it).

3. Get to MusicBee Preferences -> Tools. For the Application Path you will reference the ffmpeg.exe from before.

4. Now comes the trickery and treatery. You can use FFmpeg to include a timestamp in the resulting output file. Use the strftime feature for this. For example, you can use the following for parameters:
 
Code
-i <URL> -f segment -strftime 1 -segment_time 10:00:00 "Z:\media\radio\<TITLE> - %Y-%m-%d.ogg"
5. This will save the recorded stream with a filename that includes the title for the stream, followed by the current year, month and date. You can change the date/time format using a strftime compatible string.

A few notes about codec formats, containers and strftime:
- As far as I could research this, from the comments beneath the FFmpeg source code, for certain configurations, strftime may cause strings that are too long to handle for the design of the functions running underneath, therefore my conclusion is nobody has ventured into extending support for widespread usage of strftime on other muxers but segment and hls (Apple HTTP Live Streaming muxer). This is notably the case for MP3 as support is provided by the LAME libraries and not FFmpeg itself.
- Since strftime is only supported for these within FFmpeg, for this design you are required to specify -f segment within the parameters, along with a -segment_time that is greater than or equal to the duration of the show you are to record.
- The actual purpose of segment is to provide "automated stream segmenting". Meaning that whatever time you choose for -segment_time will be the duration of each segment of the stream you are recording.
- Using a -segment_time longer than the duration of the show, makes it so that it will record a single file until you stop the execution of the FFmpeg instance.

- The parameters "code example" provided above use OGG for container. As far as I could research, this defaults to using libvorbis for encoder. Which in turn defaults to using variable bit-rate.
- As far as I could research this, the encoder to be used is extrapolated from the format you use on the name of the resulting file.
- As mentioned for .ogg the encoder used is libvorbis. For .opus file formats, the encoder used is libopus. Both of these have VBR for default.
- For .aac the encoder used is FFmpeg's native aac implementation. For .mp3 the encoder used is libmp3lame. Both of these seem to have a CBR 128kbps value (again, as far as I could research this).
- You can setup multiple "External Tools" with these different formats, for different use cases.
- I have been unable to customize the output beyond what is described here, however I will not continue to pursue that path for the time being, as I accomplished what I wanted personally, and it has already driven me mad for like 7 hours.  ;D
- If anyone wants to contribute and shed some light on other combinations, please do so, I can see how there are infinite possible use cases and possibly infinite users looking for their unique solution.

The freaking bibliography:

(for masochists only)
https://github.com/FFmpeg/FFmpeg
https://trac.ffmpeg.org/wiki
https://ffmpeg.org/ffmpeg.html
https://ffmpeg.org/ffmpeg-formats.html
The most important Stack Overflow answer during this research
https://stackoverflow.com/questions/34884493/how-to-make-ffmpeg-insert-timestamp-in-filename
https://stackoverflow.com/questions/46978379/ffmpeg-using-current-datetime-in-the-filename-strftime-parameter-doesnt-seem
https://stackoverflow.com/questions/3255674/convert-audio-files-to-mp3-using-ffmpeg
https://stackoverflow.com/questions/61129758/ffmpeg-strftime-microseconds
https://stackoverflow.com/questions/59549766/is-there-a-way-to-identify-if-an-audio-is-vbr-or-cbr-using-ffmpeg
Last Edit: March 26, 2023, 05:17:01 AM by maurirope

sveakul

  • Sr. Member
  • ****
  • Posts: 2459
How anyone could think this is "easier" than Streamripper--which saves the stream in its actual bitrate (if mp3/aac/ogg) with no changing code extensions, and with the actual title metadata from the stream if provided not to mention optionally adding a tag--is beyond me, but I applaud the investigation into new ways of saving streams and give the author credit for the obvious research involved.
Last Edit: March 26, 2023, 07:02:45 PM by sveakul

maurirope

  • Newbie
  • *
  • Posts: 19
How anyone could think this is "easier" than Streamripper--which saves the stream in its actual bitrate (if mp3/aac/ogg) with no changing code extensions, and with the actual title metadata from the stream if provided not to mention optionally adding a tag--is beyond me, but I applaud the investigation into new ways of saving streams and give the author credit for the obvious research involved.

Hi there! So this is not meant for being easier but for being more customizable. FFmpeg usage is much more extendable than that of Streamripper's.

In the other hand, can you share what is the Streamripper version number that you are using? I have been unable to find one that works for me for Win11 for quite some time, and just gave up on it. I assumed I couldn't be the only person looking for an alternative.

Also, there's writing metadata tags using FFmpeg and way more expandability regarding encoding formats. I just did not include that here.

Maybe it is that between so much text, it is missed that the point, is to hint at the possibilities of using a powerful command tool, for those that might believe these aren't within reach.  8)

As you say, letting in new ways.

sveakul

  • Sr. Member
  • ****
  • Posts: 2459
If your usage involves re-encoding the streams from their native format, then yes ffmpeg.exe would provide a multitude of ways to do that as well as expanded tagging capabilities.  I use it myself for several video transcoding and joining tasks.

I do not have access to Windows 11 (yet) so I'm afraid I can't say anything about its compatbility with Streamripper--can anyone else here comment?  I believe development of Streamripper has been abandoned, the latest version is 1.64.6 from 2009-03-31.

You might also take a look at wget.exe (https://getmusicbee.com/forum/index.php?topic=36212.0); while it can provide a raw stream dump of just about anything, it certainly needs editing by a tool like ffmpeg to make the results usable.