sean finney on 23 Mar 2006 20:05:09 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] .ogg to .mp3 or .aac


hey art,

On Thu, Mar 23, 2006 at 02:28:09PM -0500, Art Alexion wrote:
> an iPod.  It only plays .mp3 and .aac compressed formats.  I would like to 
> convert to one of these formats with as little loss as possible.  I know I 
> can use oggenc to decode to .wav and then lame to encode as .mp3, but I 
> expect that that would degrade the sound significantly.
> 
> I have access to a samba linked machine running iTunes (I usually use amaroK), 
> and I understand that iTunes will encode to aac on the fly without affecting 
> the original file, but iTunes doesn't seem to accept ogg files either.

i hate to tell you this, but what itunes is doing is no different
from what you'd be doing with oggenc+lame,,only it is using
a different encoder.  the resulting quality will be directly dependant
on the starting quality in the ogg minus what's done by the
second encoder.

that said, here's a script i use for going from ogg to mp3,
preserving tags and all that jazz.  i'm sure google will find you
others too.  if fyou're interested, i also have a kde .desktop file
which adds a right-click menu option for converting to mp3.

it's not exactly well, documented, but if you can read
shell script it's not too complicated to figure
out.


	sean
#!/bin/sh

set -e

need="getopt dirname find xargs stat id sed echo grep cat vorbiscomment ogg123 lame"
for p in $need; do
	which $p >/dev/null 2>&1
	if [ $? -ne 0 ]; then
		echo "error, $p is not in your path" >&2
		exit 1
	fi
done

TEMP=`getopt -o Do: -n $0 -- "$@"`
if [ $? != 0 ] ; then 
	echo "incorrect usage" >&2 
	exit 1 
fi

eval set -- "$TEMP"
while [ ! "$done_with_args" ]; do
	case "$1" in
	-D)
		do_delete="yes"
		child_args="$child_args -D"
	;;
	-o)
		odir="$2"
		child_args="$child_args -o $odir"
		shift
	;;
	--)
		done_with_args="yes"
	;;
	*)
		echo "eh? $1" >&2
		exit 1
	;;
	esac
	shift
done


ifile=$1
if [ ! "$ifile" ]; then
	echo "gimme an input file"
	exit 1
elif [ ! -e $ifile ]; then
	echo "$ifile does not exist"
	exit 1
fi

if [ -d $ifile ]; then
	find $ifile -follow -type f -name '*ogg' -print0 |\
		xargs --no-run-if-empty -0 -n1 $0 $child_args
	exit 0
fi

me=`id -un`
them=`stat -c'%U' "$ifile"`

ifilebase=`echo $ifile | sed -e 's,^\([^/]*/\)*,,g'`
ofile=`echo $ifilebase | sed -e 's,.ogg$,.mp3,'`
if [ ! "$odir" ]; then
	odir=`echo $ifile | sed -e "s/$ifilebase\$//"`
fi

if [ ! -d "$odir" ]; then
	mkdir -p "$odir"
fi

ofile="$odir/$ofile"

set +e
ARTIST=`vorbiscomment -l -R $ifile | grep ARTIST | sed -e 's,[^=]*=,,'`
TITLE=`vorbiscomment -l -R $ifile | grep TITLE | sed -e 's,[^=]*=,,'`
ALBUM=`vorbiscomment -l -R $ifile | grep ALBUM | sed -e 's,[^=]*=,,'`
DATE=`vorbiscomment -l -R $ifile | grep DATE | sed -e 's,[^=]*=,,'`
TRACKNUMBER=`vorbiscomment -l -R $ifile | grep TRACKNUMBER | sed -e 's,[^=]*=,,'`
CDDB=`vorbiscomment -l -R $ifile | grep CDDB | sed -e 's,[^=]*=,,'`
set -e

echo "$ifile -> $ofile"
touch "$ofile"
#cat << EOF
#ARTIST=$ARTIST
#ALBUM=$ALBUM
#TITLE=$TITLE
#DATE=$DATE
#TRACKNUMBER=$TRACKNUMBER
#CDDB=$CDDB
#EOF
ogg123 -d wav -b 32768 --audio-buffer 4096 -f - "$ifile" | lame --quiet -h --tt "$TITLE" --ta "$ARTIST" --tl "$ALBUM" --ty "$DATE" --tc "switch to ogg.  it's better for you" --tn "$TRACKNUMBER" - "$ofile"

if [ ! "$odir" ] && [ "$me" = "$them" ]; then
	rm $ifile
fi


Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug