View previous topic :: View next topic |
Author |
Message |
devsk Advocate
Joined: 24 Oct 2003 Posts: 2995 Location: Bay Area, CA
|
Posted: Fri Jun 24, 2005 4:11 am Post subject: script for mass mp3 to ogg conversion |
|
|
I had this peculiar requirement that I needed all my songs on another machine and I was tight on space on that machine. so, instead of copying mp3 I decided to copy ogg and hence reduce space by half (of course I lost the quality of higher kbps mp3). So, I wrote this small script. it can convert all mp3 (with their shady blank chars in names) in a directory tree to ogg file and put it next to mp3 file or it can create an equivalent directory structure on another tree with just ogg files. tune the oggenc settings to your taste. also understand that you are losing some quality in this process even if your source (mp3) and destination (ogg) bit-rates match.
you can invoke multiple times with same args, it won't repeat what it did last time.
Code: |
#!/bin/bash
if [ "$#" == "1" ];then
sourceDir="${1}"
destDir="${1}"
else
if [ "$#" == "2" ];then
sourceDir="${1}"
destDir="${2}"
else
echo "Usage : convertmp3toogg <srcdir> [<destdir>]"
echo ""
exit 1;
fi
fi
# xargs takes only command files...no functions...:(
cat > /tmp/convert1 << EOF
filen="\${1}"
oggfile="\${1/.mp3/.ogg}"
if [ -f "${destDir}/\${oggfile}" ]; then
exit 0
fi
oggdir="\`dirname \"\${filen}\"\`"
if [ ! -d "${destDir}/\${oggdir}" ] ;then
echo "Making dir \"${destDir}/\${oggdir}\"..."
mkdir -p "${destDir}/\${oggdir}"
fi
echo "Converting \"\${filen}\" to \"\${oggfile}\"..."
mpg123 -q -w /tmp/out.wav "\${filen}"
oggenc -Q -q 0.5 /tmp/out.wav
mv /tmp/out.ogg "${destDir}/\${oggfile}"
id3cp "\${filen}" "\${oggfile}"
EOF
chmod +x /tmp/convert1
if [ ! -d "${destDir}" ] ;then
echo "Making destdir \"${destDir}\"..."
mkdir -p "${destDir}"
fi
cd "${sourceDir}"
find . -name "*.mp3" -print0 | xargs -L1 -0 /tmp/convert1
echo "Done."
exit 0
|
also its a good idea to redirect the output to a file. like if the script is called convertmp32ogg, then Code: | convertmp32ogg > /tmp/conversion.log 2>&1 |
|
|
Back to top |
|
|
codergeek42 Bodhisattva
Joined: 05 Apr 2004 Posts: 5142 Location: Anaheim, CA (USA)
|
Posted: Fri Jun 24, 2005 4:48 am Post subject: |
|
|
Or you could Code: | # emerge media-sound/mp32ogg |
_________________ ~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF |
|
Back to top |
|
|
devsk Advocate
Joined: 24 Oct 2003 Posts: 2995 Location: Bay Area, CA
|
Posted: Fri Jun 24, 2005 5:05 am Post subject: |
|
|
codergeek42 wrote: | Or you could Code: | # emerge media-sound/mp32ogg |
| how do I use it for my requirement? it just says 'mp32ogg dir1 dir2 file1 file2 ...". nice usage. |
|
Back to top |
|
|
robbyt n00b
Joined: 11 Aug 2004 Posts: 32
|
Posted: Fri Jun 24, 2005 9:18 pm Post subject: |
|
|
just another tip,
compressing audio that was already compressed, using two diffrent codecs will make your music sound like crap. |
|
Back to top |
|
|
johntramp Guru
Joined: 03 Feb 2004 Posts: 457 Location: New Zealand
|
Posted: Fri Jun 24, 2005 9:56 pm Post subject: |
|
|
robbyt wrote: | just another tip,
compressing audio that was already compressed, using two diffrent codecs will make your music sound like crap. |
devsk did state more than once that there would be audio quality lost. |
|
Back to top |
|
|
|