Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
script for mass mp3 to ogg conversion
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2858
Location: Bay Area, CA

PostPosted: Fri Jun 24, 2005 4:11 am    Post subject: script for mass mp3 to ogg conversion Reply with quote

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
View user's profile Send private message
codergeek42
Bodhisattva
Bodhisattva


Joined: 05 Apr 2004
Posts: 5142
Location: Anaheim, CA (USA)

PostPosted: Fri Jun 24, 2005 4:48 am    Post subject: Reply with quote

Or you could
Code:
# emerge media-sound/mp32ogg
:wink:
_________________
~~ Peter: Programmer, Mathematician, STEM & Free Software Advocate, Enlightened Agent, Transhumanist, Fedora contributor
Who am I? :: EFF & FSF
Back to top
View user's profile Send private message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2858
Location: Bay Area, CA

PostPosted: Fri Jun 24, 2005 5:05 am    Post subject: Reply with quote

codergeek42 wrote:
Or you could
Code:
# emerge media-sound/mp32ogg
:wink:
how do I use it for my requirement? it just says 'mp32ogg dir1 dir2 file1 file2 ...". nice usage.
Back to top
View user's profile Send private message
robbyt
n00b
n00b


Joined: 11 Aug 2004
Posts: 32

PostPosted: Fri Jun 24, 2005 9:18 pm    Post subject: Reply with quote

just another tip,

compressing audio that was already compressed, using two diffrent codecs will make your music sound like crap.
Back to top
View user's profile Send private message
johntramp
Guru
Guru


Joined: 03 Feb 2004
Posts: 457
Location: New Zealand

PostPosted: Fri Jun 24, 2005 9:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum