"Piping" decoded audio output from one app to the input "file" of another

Eric Dunbar eric.dunbar at gmail.com
Sun May 1 15:35:27 UTC 2005


Goal: I wanted to capture radio shows from CBC radio 1*, encode them
to MP3 and then listen to them at my leisure on my iPod Shuffle.

*Canadian Broadcasting Corporation, the Canadian BBC or NPR .

Since I've gotten this thing working I've been able to listen to a LOT
more programs that I want to listen to WHEN I want to listen to them
than I used to....

the good ones (IMNSHO) are on at times when I don't really listen to
radio, e.g. Ideas 21-22 EST (-05:00 EST) <http://www.cbc.ca/ideas/>
which is a one hour program on a specific topic from anything on
science-politics-religion-philosophy-children's lit-the kitchen
sink-art-etc (they had a show on Hans Christian Anderson and on the
monarch butterfly (very good episode IMO) for e.g.)

Synopsis of problem: I wanted to pipe an .ogg stream from a wget
download to an .ogg to .wav decoder to a .wav to .mp3 encoder

(FYI ogg is similar to the mp3 file format (compressed) and .wav is
uncompressed audio)

Solution: even simpler than I thought (will work on Linux and under OS X):

ogg123 -d wav -f - http://oggtrial.nm.cbc.ca:80/cbcr1-toronto.ogg|lame
- outfile.mp3

This line uses ogg123 to connect to CBC's server, download their live
ogg stream and then pipe it to lame (an mp3 encoder/decoder) to encode
to MP3. Lame and ogg123 play together very nicely. When lame's stdin
input is empty it waits for something to come in and continues
encoding :) :) :-)

This is a LOT cleaner than what I was doing up to today (using various
scripts and cron jobs):
1. download stream to .ogg file using wget (2nd cron job killall wget
at a certain time)
2. convert all .ogg to .wav in one dir using oggdec (quite fast) and
rm -f all the ogg
3. convert all .wav to .mp3 using lame and rm -f all the wav

I tried piping wget to oggdec to lame but couldn't get past oggdec...
rather than pipe to lame oggdec would write to the file -.wav (which
was a pain to delete from the command line... I ended up using
nautilus or OS X Finder (logged in via SMB))

This is what I tried (unsuccessfully):
wget http://oggtrial.nm.cbc.ca:80/cbcr1-toronto.ogg -O -|oggdec -|lame
- outfile.mp3

(FYI I tried oggdec -, oggdec - -, oggdec, all to no avail)

PS I can't get lame to do the ogg-to-mp3 conversion directly (I
compiled from source with the --with-vorbis flag enabled but couldn't
figure out how to get ogg->mp3... doesn't matter b/c ogg123->lame
works beautifully).

PS this post'll appear twice in response to two message threads I started!

PSS This is what my script looks like (so far it seems to be working
with cron... I set it to start on the top and bottom of the hour from
2100 to 2200 weekdays and 1000 to 1200 on Sundays):

#!/bin/bash
killall ogg123

Date=$(date +%Y%m%d.%H%M)
URL="http://oggtrial.nm.cbc.ca:80/cbcr1-toronto.ogg"
LPath="/home/erdunbar/"

/usr/bin/ogg123 -d wav -f - $URL|/usr/local/bin/lame - ${LPath}CBC-${Date}.mp3

Notes:
(1) I had to specify the path for lame b/c the cron tab entry didn't
run properly without. ogg123 would run but then the error message in
mail reported that lame couldn't be found.
(2) for newbies... you have to "chmod +x yourscriptname" to make your
script executable (you can run it manually from the command line by
typing ./yourscriptname after chmodding it).
(3) if you're interested in finding out what the flags mean, run man
ogg123 or man lame.
(4) I also run a cron tab "killall ogg123" to stop the final instance
of this script... I like 30 minute segments for listening purposes

Now... my next task is to get this machine to auto-update its time
(YellowDogLinux) b/c every week or so it slips by a minute or so.

Eric
cc:YDL General, Ubuntu-users, MUGLO

On 4/27/05, Cian Duffy <myob87 at gmail.com> wrote:
> Short answer: Yes, just use a pipe (|) to do it
> 
> Long answer: Don't bother, just recompile LAME with Ogg input support
> - its either an official compile option or theres a patch for it.
> oggdec is slow (not that LAME doing it will be majorly), and there is
> a possibility of pipe-starvation, where LAME could be running faster
> than oggdec, and there wouldn't be any file to encode from...
> 
> Cian
> 
> On 27/04/05, Eric Dunbar <eric.dunbar at gmail.com> wrote:
> > Hi all,
> >
> > I'm trying to use oggdec and lame to convert from .ogg to .mp3.
> >
> > First I decode with oggdec to a .wav file and then from .wav to .mp3 using lame.
> >
> > What I was wondering is if it'd be possible to direct the .wav output
> > from oggdec *directly* to lame, skipping the intermediate file
> > creation process?




More information about the ubuntu-users mailing list