Restreaming ASF to MP3 Via Icecast and VLC

Say you have an internet radio stream that you like to listen to. You like to actually get up from your computer once in a while and go outside, so you want to play it on your iPhone/Blackberry/G1/Treo/Centro/Pre/Whatever as you’re out and about. But wait! Due to poor decision making by your beloved stream provider, your favorite stream is only in Microsoft’s poorly-supported ASF streaming format. There’s no MP3 or OGG options! Many if not all of the phones I just mentioned may/will not play these streams, at least not natively. MP3 on the other hand, is ubiquitous (though, given, not truly as free as OGG). One option you may have, if you run your own Linux server, is to download the ASF stream, re-encode it to MP3, and re-stream it via your own Icecast server. Icecast is easy enough to set up, however information on setting up the VLC portion of this workaround online seems a little slim online, so I thought I’d make a post simplifying the setup.

First off, check to make sure your VLC has “Shout” Shoutcast/Icecast output support:

vlc --list | grep access_output_shout

You should see the following in the output:

access_output_shout IceCAST output

If not, you may need to either re-install with a version of VLC that supports shout output, or recompile it with shout support.

Then run the following command, altering the items in bold for your purposes (all on one line):

cvlc "http://classicalstream2.publicradio.org/classical" ':sout=#transcode{acodec=mp3,ab=192,channels=2}:duplicate{dst=std{access=shout,mux=raw,dst=source:YOURPASSWORD@your.icecast.server.com:8000/mpr.mp3}}' --sout-shout-mp3 --sout-shout-name="MPR MP3 Restream" --sout-shout-description="Restreaming of MPR" --sout-shout-url="http://minnesota.publicradio.org" --sout-shout-genre="Liberal Tripe" --loop

Assuming you have already properly set up your Icecast server, you should now have a mountpoint running the stream you have just created.

Note that VLC seems to have problems parsing some ASX playlist files. You may need to download the ASX file with wget to investigate what the actual stream URL is. For example, the stream above came from “http://minnesota.publicradio.org/tools/play/streams/classical.asx”, which had these contents:

<ASX version="3.0">
   <ABSTRACT>The Windows Media Stream for MPR's Classical Music Service</ABSTRACT>
   <TITLE>MPR Classical Windows Stream</TITLE>
   <AUTHOR>Minnesota Public Radio</AUTHOR>
   <COPYRIGHT>2009 Minnesota Public Radio</COPYRIGHT>
   <MOREINFO HREF = "http://minnesota.publicradio.org" />
   <ENTRY>
      <TITLE>MPR Classical Windows Stream Underwriter</TITLE>
      <COPYRIGHT>2009 Minnesota Public Radio</COPYRIGHT>
      <REF HREF="http://ondemand2.publicradio.org/ondemand/joinnow.wma"/>
      <BANNER HREF="http://www.publicradio.org/applications/underwriters/images/prepend/content/joinnow.gif">
          <MOREINFO HREF = "https://contribute.publicradio.org/"></MOREINFO>
      </BANNER>
   </ENTRY>
   <ENTRY>
      <TITLE>MPR Classical Windows Stream</TITLE>
      <COPYRIGHT>2009 Minnesota Public Radio</COPYRIGHT>
      <REF HREF="http://classicalstream2.publicradio.org/classical"/>
      <BANNER HREF="http://www.publicradio.org/applications/underwriters/images/prepend/content/joinnow.gif">
          <MOREINFO HREF = "https://contribute.publicradio.org/"></MOREINFO>
      </BANNER>
   </ENTRY>
</ASX>

As you can see, the first item in the playlist is NPR’s obligatory call (**cough** commercial **cough**) for donations (http://ondemand2.publicradio.org/ondemand/joinnow.wma). The second is your actual stream URL (http://classicalstream2.publicradio.org/classical). You’ll want to use the stream URL in your VLC command.

Also, I have seen cases where VLC pukes on some ASF streams. Though I haven’t confirmed this, it appears to be a bug with downsampling/resampling (http://mailman.videolan.org/pipermail/vlc-devel/2009-February/056823.html). In these cases, you may need to look that the 1.0.0 prerelease versions, which may not be available on your distro release (Fedora, for example, doesn’t have it until 11). Good luck!

UPDATE 10/27/09: It would appear that the precompiled RPMs offered on the VLC site for 1.0 or higher do not contain support for shout output. Not a big deal. Just download the source RPM (e.g., from http://download1.rpmfusion.org/free/fedora/development/source/SRPMS/) install the sources (rpm -Uvh vlc-1.0.3-0.1_rc.fc12.src.rpm), and edit the vlc.spec file (usually found in ~/rpmbuild/SPECS/). Look for a line that says “–enable-realrtsp \” and add a line below it that says “–enable-shout \”. Save and close the file, then run “rpmbuild -ba vlc.spec”. After it recompiles, install the updated RPMs (cd ~/rpmbuild/RPMS/x86_64/ ; yum –nogpgcheck reinstall vlc-core-1.0.3-0.1_rc.fc11.x86_64.rpm vlc-1.0.3-0.1_rc.fc11.x86_64.rpm). Make sure to alter the above paths to reflect your architecture, Fedora release, and vlc version.

3 thoughts on “Restreaming ASF to MP3 Via Icecast and VLC”

  1. Thank you for this explanation!

    However, when i run your cvlc command (plugging in my values) — the audio goes to my speakers, and I don’t see a new stream mount on my icecast. :(

    Are you sure that command works?

    Thanks-
    Matt