Convert Audio

Convert RM audio to MP3

The following script will convert all files in a directory (it will use the current directory if none is specified). Make sure to change the OUTPUTDIR to match what you want.

#!/bin/bash
# transcodes realmedia (RM) audiofiles to MP3 audio files.
# Version 0.1
# Author: Arjen
# Usage: rm2mp3 

### Configuration

#This is where the temporary wav files will be stored
TMPDIR="/tmp"

#This is where the MP3 files will end up
OUTPUTDIR="/home/frank/Desktop/mp3"

#Path to mplayer binary. Don't change unless you know what you're doing.
MPLAYER="/usr/bin/mplayer"

#Path to lame binary. Don't change unless you know what you're doing.
LAME="/usr/bin/lame"

#Options for rm to wav decoding
MPLAYER_OPTS="-ao pcm:file"

#Options for lame encoding
LAME_OPTS="-f"

#Define working directory
WORK="$TMPDIR/rm2mp3.$$"

#Define working name for tracks
WAV="$WORK/track.wav"

### End configuration

# Get absolute directory paths
INPUTDIR="$1" #you can change this to an absolute path
cd "$INPUTDIR"
INPUTDIR="$PWD"

# Setup work directory, clean and create
rm -rf "$WORK"
if [ -e "$wORK" ]; then
echo "Couldn't delete $WORK"
exit 1
fi
mkdir "$WORK"
if [ ! -d "$WORK" ]; then
echo "Couldn't create $WORK"
exit 1
fi

# Transcode the files
cd "$INPUTDIR"
OLDIFS="$IFS"
IFS=$'\n'
for filepath in $(find . -type f -name '*.rm' -print \
| sort | sed -e 's/^\.\///' -e 's/\.rm$//'); do
IFS="$OLDIFS"
filedir="$(dirname "$filepath")"
filename="$(basename "$filepath")"
if [ ! -d "$OUTPUTDIR/$filedir" ]; then
mkdir -p "$OUTPUTDIR/$filedir"
fi
if [ ! -f "$OUTPUTDIR/$filepath.mp3" ]; then
#Create wav file
$MPLAYER "$INPUTDIR/$filepath.rm" $MPLAYER_OPTS="$WAV"

# Encode MP3
$LAME $LAME_OPTS "$WAV" "$OUTPUTDIR/$filepath.mp3"
fi
done

# Clean up
rm -rf "$WORK"
exit
By practic on August 3, 2011 | | A comment?