Recording online streams (real / wma) to mp3 format (or ogg) with mplayer



So, I’ve been looking back over my list of “scripts” that are pulling in audio from various news sources online for the onlineradiotv.com site. It’s also got me doing a bit more spanish language listening than I had been. In the car, I usually use an mp3 player (the nexia) with a small FM transmitter to listen. One of the problems is that I only have a very short list of sources that I can actually download an mp3 from. The rest are streams only. Some are mms (Windows media) streams, others are (rtsp) real server streams… yet others are “playlist” style asf, or ram files that point to other files (rm or asx/wma)…


The bottom line, is that all of those are formats that my player doesn’t support. (Or at least I haven’t tried… wma may be supported.) For the most part, I’ve standardized most of my audio on mp3 just for compatibility (some are in ogg awaiting the day that ogg is as widely playable…) So, I got to thinking, if mplayer can handle all these different file formats, shouldn’t I be able to “capture” a stream to an mp3? I’ve tried various “stream ripping” programs before and had mixed success. Usually, they were specific to one format (realplayer for instance.)

The nice thing about mplayer is with it’s wide codec support, it should be able to capture to file almost ANY audio from almost any stream. Here’s how to do it. We’ll use the bbc spanish language news update as an example….

http://www.bbc.co.uk/spanish/radio/aod/rpms/spanish_bbc_noticias.rpm is the address…

$mplayer -cache 128 -playlist http://www.bbc.co.uk/spanish/radio/aod/rpms/spanish_bbc_noticias.rpm

the above command is usually enough to simply play the audio. For recording, we could probably ignore the cache option (-cache 128 starts the audio playing more quickly than the default setting, but if we’re recording to file it shouldn’t matter…)

$mplayer -playlist http://www.bbc.co.uk/spanish/radio/aod/rpms/spanish_bbc_noticias.rpm -ao pcm:file=/tmp/bbcspanish.wav -vc dummy -vo null

(so we’re writing to a .wav file – or uncompressed audio) The -vc and -vo switches relate to video output which is dumped. I really questioned if it was necessary, but I’ve based this on instructions found here for recording streaming audio with mplayer. The biggest change is that I’ve updated the switches -aofile is deprecated in current mplayer…. the -ao pcm:file=filename approach above is the current usage….

So, now we’ve got a wav file how do we get mp3?

lame -m s /tmp/bbcspanish.wav -o /home/user/mp3s/bbcspanish_`date +%b%d`.mp3

or it could be encoded to ogg

oggenc /tmp/bbcspanish.wav -o /home/user/mp3s/bbcspanish_`date +%b%d`.ogg

I’ve done a script along those lines that looks like this….

#!/bin/bash
#streamp2mp3
mplayer -playlist $1 -ao pcm:file=/tmp/$2.wav -vc dummy -vo null ;
#oggenc /tmp/$2.wav -o /home/avery/unmp3noticias/$2_`date +%b%d`.ogg ;
lame -m s /tmp/$2.wav -o /home/avery/unmp3noticias/$2_`date +%b%d`.mp3
rm /tmp/$2.wav ;

I’ve designed it so I can call stream2mp3 http://www.bbc.co.uk/spanish/radio/aod/rpms/spanish_bbc_noticias.rpm bbcspanish

In other words, the first variable is the stream to capture and the second variable is the first part of the filename (the rest of the file name is date stamped and then .mp3 is added. I’ve got the oggenc line in there in case I ever switch to .ogg format, I can simply comment out the lame line and uncomment oggenc….

Now, for some streams the above -playlist option will not work. So, the script could use some alterations to accomodate that possibility. (I’ve found -playlist is an unforgiving switch to mplayer – it it’s used and the file is NOT a playlist it WILL NOT work.) I guess a lazy solution would be to have a stream2mp3playlist and stream2mp3 version of the script… but that’s not an elegant fix. Anyway the bottom line is it’s worked for me quite well and thought I’d share it (along with the above link that was essentially the how-to on the subject.)

Related Posts

Blog Traffic Exchange Related Posts
  • CDROM drives with yellow exclamation point in Windows XP I ran into something I hadn't yet seen firsthand today. A PC (running Windows XP home) with 2 optical drives (CD-RW and DVD drive). However, neither cd drive showed up in My Computer and both of them had a yellow exclamation point in the device manager listing. Of course, two......
  • Automatically downloading a file mp3 with a bash script Linux systems give you many possibilities and one of them is good scheduling (cron), another is good scripting capabilities. I've done things with linux fairly easily that with Windows would have been next to impossible and required me to download several other things to make it happen. Anyway, I recently......
  • Frontier Labs - nexblack I know it's not an ipod... but I'm looking forward to hearing some word when Fronteir Labs releases their "Nexblack". For background.... the nexblack is priced at around $89 (at the frontier labs store), but I've found $69 here. It's a portable mp3/wma/wma with drm/ogg player (according to the spec......
Blog Traffic Exchange Related Websites
  • Schwinn Exercise Bike A perfect workout The Schwinn Airdyne Exercise Bike, designed for the total body workout, features patented Airdyne technology that uses a fan wheel to create resistance which increases by pedaling faster and harder. Schwinn exercise bike is one of the best indoor bikes that provides effective workout for all types of users and......
  • Audacity Powerfull,Free Cross-Platform Sound Editor Audacity Powerfull,Free Cross-Platform Sound Editor With so many audio editors out there, finding the right tool for the job can be tricky. The multiplatform, open-source editor Audacity has leaped to the top of our list with its clean interface, excellent features, and support for 32-bit floating-point audio. Audacity succeeds at......
  • MediaMonkey Review On the subject of music players, there are more over a few names to pick from. With the heavyweights like Media Player and JetAudio Basic 8.0.14 to prospects light on resources and at the top of configurable options like Foobar. MediaMonkey fits somewhere at the center but offers some very......
PDF24    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site