Skip to content

Recording streams with mplayer (real audio, asf, …)

Problem: I have a Unix server (BSD at the moment) always on and I want to record real audio streams daily, encoding them in mp3 to listen later in my ipod.

Solution: mplayer, lame, shell script and cron

1) I wrote a script called record.sh that get an output filename and an url representing the stream to record

#!/bin/sh
# Usage:
# record.sh <file> <url_to_record>
mplayer -quiet -cache 32 -vc dummy -vo null -ao pcm:file=$1.wav $2 > /dev/null
lame –quiet –preset radio $1.wav $1.mp3
rm $1.wav > /dev/null

2) I wrote a script that grabs my favourite program. Call it for example grab_xyz.sh

#!/bin/sh
RECORD=/home/pc/bin/record.sh
filename=/data/shared/P2PDownload/toListen/$(date+%y%m%d)_xyz
$RECORD $filename rtsp://url/xyz.rm

3) Finally I edited a cron job (cfr: crontab -e)

# Record ‘XYZ from Live Stream’ (from 13.30 to 14.30)
30 13 * * *     $HOME/bin/grab_xyz.sh
30 14 * * *     /bin/killall mplayer

4) At end I’ll find (in toListen directory)

060118_xyz.mp3
060117_xyz.mp3
060116_xyz.mp3

Post a Comment

Your email is never published nor shared. Required fields are marked *