Re: mass conversion from ogg to mp3
> I have a large number of music files (17 gig worth...yes, for all prying
> eyes they are legal...) that I find I need to convert from .ogg to .mp3.
> Not that I want to...but between a teenager with an iphone and being saddled
> with cell phone that won't play .ogg...well, you get the picture.
> What is the best way to do this? I would prefer a CLI option that I can run
> in the background, but I want to save as much sound quality as I can with
> the transfer...
You may want to consider this conversion, not as a way to replace your
Ogg collection with an MP3 collection, but just as a way to get
a specialized version of your collection for some particular devices.
My main collection is in Flac format, but I convert it to Ogg(96kb/s)
before uploading it to my "MP3" player, since Flac would take up too
much space. The quality is not as high, but given the circumstances in
which I listen to it, I can't really tell the difference.
As for the conversion, I use the script below.
Stefan
#!/bin/sh
bitrate="bitrate=98304" # 96Kb/s
samplerate=""
delete=false
dontrun=false
outformat=ogg
if [ -x "/usr/bin/gst-launch-0.10" ]; then
gst_launch="/usr/bin/gst-launch-0.10"
resample="audioresample !"
decode="decodebin"
oggmux="! oggmux"
else
gst_launch="gst-launch-0.8"
resample="audioscale !"
decode="spider"
oggmux=""
fi
usage () {
echo "usage: $(basename $0) [--bitrate=KBITS] [--samplerate=HZ] [--delete] FROM [TO]"
}
while [ $# -gt 0 ]; do
case "$1" in
--bitrate=*) bitrate="bitrate=$(expr "$(echo "$1" | sed 's/.*=//')" "*" 1024)";;
--quality=*) bitrate="quality=$(echo "$1" | sed 's/.*=//')";;
--samplerate=*)
rate=$(echo $1 | sed 's/.*=//')
samplerate="$resample audio/x-raw-int,rate=$rate !" ;;
--help) usage; exit 0 ;;
--delete) delete=true ;;
--flac) outformat=flac ;;
-n ) dontrun=true ;;
-*) usage ; exit 1 ;;
*) from="$1"; to="$2"; if [ $# -gt 1 ]; then shift; fi ;;
esac
shift
done
case "$outformat" in
ogg )
fileext="64.ogg"
encoder="vorbisenc $bitrate $oggmux"
;;
flac )
fileext="flac"
case "$bitrate" in
quality=* ) ;;
* ) bitrate="" ;;
esac
encoder="flacenc $bitrate"
;;
esac
if [ "$from" = "" ]; then
usage; exit 1
fi
run () {
echo "$@"
if [ "$dontrun" = "false" ]; then
"$@"
fi
}
convertfile() {
from="$1"
to="$2"
if [ "$to" = "" ]; then
to="."
fi
if [ -d "$to" ]; then
case "$from" in
/* ) fromrel="$(basename $from)" ;;
* ) fromrel="$from"
esac
base="$(echo "$fromrel" | sed 's/\.[^.][^.]*$//')"
to="$to/$base.$fileext"
fi
if [ "$to" = "$from" ]; then
echo "Don't know how to overwrite!"
exit 1
fi
echo "Converting "'"'"$from"'"'" to "'"'"$to"'"'
# "gst-inspect vorbisenc" shows available options
#
# FIXME! The stupid flacenc/flacdec/audioconvert step works around
# a problem I found when converting Ogg files that had been split by
# mp3splt (in which case, oggmux seems to get confused and outputs an
# empty file).
run $gst_launch filesrc location="$from" ! $decode ! $samplerate audioconvert ! $encoder ! filesink location="$to"
if [ "$?" = "0" ] && [ "$delete" = "true" ]; then
run rm "$from"
fi
}
convert () {
case "$1" in
*."$fileext" ) ;; # Nothing to do.
* )
if [ -d "$1" ]; then
case $1 in */) from="$1" ;; *) from="$1/" ;; esac
for f in "$from"*.ogg \
"$from"*.flac \
"$from"*.m4a \
"$from"*.mp3 \
"$from"*.ac3 \
"$from"*.wav \
"$from"*/;
do
if [ -r "$f" ]; then
convert "$f" "$2"
fi
done
else
convertfile "$1" "$2"
fi
esac
}
convert "$from" "$to"
# arch-tag: d65ee1c6-1f4e-4175-b9ea-b9d512566b15
Reply to: