Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Mar 2012 09:42:57 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Steve Bertrand <steve.bertrand@gmail.com>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Convert mp3 to audio CD
Message-ID:  <20120321094257.992e4009.freebsd@edvax.de>
In-Reply-To: <4F694698.5080009@gmail.com>
References:  <4F694698.5080009@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 20 Mar 2012 23:10:16 -0400, Steve Bertrand wrote:
> I know this is a backwards request, as I haven't had to go from mp3 to 
> audio CD format in at least 10 years, but I do now.
> 
> What is available to do so?

This script, ugly as hell, but works. :-)

You need to install madplay or mpg123, as well as sox.
If you also want to convert Ogg/Vorbis files, you need
ogg123 (vorbis-tools). And of course you need a cd
burning program such as cdrdao or cdrecord. See the
examples for calling them at the end of the script.







#!/bin/sh

echo "=== MP3 + OGG/Vorbis -> Audio CD Converter ==================================="
echo -n "MP3 decoders found:"
DECODER=0
which mpg123 > /dev/null 2>&1
if [ $? -eq 0 ]; then
	DECODER=2
	echo -n " mpg123"
fi
which madplay > /dev/null 2>&1
if [ $? -eq 0 ]; then
	DECODER=1
	echo -n " madplay"
fi
if [ $DECODER -eq 0 ]; then
	echo "none, aborting."
	exit 1
fi
echo -n ", using "
if [ $DECODER -eq 1 ]; then
	echo "madplay."
else
	echo -n "mpg123"
	which madplay > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		echo " and sox."
	else
		echo ", but sox is not available, exiting."
		exit 1
	fi
fi
echo -n "OGG/Vorbis decoders found:"
which ogg123 > /dev/null 2>&1
if [ $? -eq 0 ]; then
	echo " ogg123."
else
	echo "none, aborting."
	exit 1
fi

TOCFILE="audiocd.toc"
echo "CD_DA" > $TOCFILE

FILELIST=`ls *.[mo][pg][3g]`
if [ "$FILELIST" = "" ]; then
	echo "No files (*.mp3 and/or *.ogg) found, aborting."
	exit 1
fi

for FILE in *.[mo][pg][3g]; do
	echo -n "$FILE -> "
	echo $FILE | grep " " > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		echo "filename contains spaces, cannot proceed."
		exit 1
	fi
	TYPE=""
	echo $FILE | grep ".mp3" > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		TYPE="mp3"
	fi
	echo $FILE | grep ".ogg" > /dev/null 2>&1
	if [ $? -eq 0 ]; then
		TYPE="ogg"
	fi
	if [ "$TYPE" = "ogg" ]; then
		ogg123 -q -d raw -f $FILE.raw $FILE
		sox -r 44100 -c 2 -w -s $FILE.raw $FILE.cdr
		rm $FILE.raw
	elif [ "$TYPE" = "mp3" ]; then
		case $DECODER in
		1)
			madplay -q -o cdda:$FILE.cdr $FILE
			;;
		2)
			mpg123 -sq $FILE > $FILE.raw
			sox -r 44100 -c 2 -w -s $FILE.raw $FILE.cdr
			rm $FILE.raw
			;;
		esac
	elif [ "$TYPE" = "" ]; then
		echo "file type unknown, aborting."
		exit 1
	fi
	echo $FILE.cdr
	echo TRACK AUDIO COPY AUDIOFILE \"$FILE.cdr\" 0 >> $TOCFILE
done
echo "Your recording command could be:"
echo " # cdrecord -eject -v -dao -audio *.cdr"
echo " # cdrdao write --eject audiocd.toc"
echo "After finished, don't forget to delete converter garbage:"
echo " # rm *.cdr audiocd.toc"
echo "=============================================================================="
exit 0




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120321094257.992e4009.freebsd>