Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 May 2011 12:56:20 -0500
From:      Antonio Olivares <olivares14031@gmail.com>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis
Message-ID:  <BANLkTi=NZv0AF3UAnGxVy1rt6Kb8kP3Y3g@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Dear kind FreeBSD users,

I have a dilemma, I have a collection of songs in mp3 form from old
cd's that I ripped.  Sadly, the mp3s can play but with a screeching
sound :(.  I have confirmed that by converting the mp3's to ogg vorbis
format, the screeching sound is lost.  So I have decided to convert my
songs to ogg vorbis.  I have found a script that converts from any
sound format to mp3, but I modified it to convert to ogg at 128 k
which is default.  The script that I modified is found at :

http://en.linuxreviews.org/HOWTO_Convert_audio_files

However, when I run it, I have to switch to the folder where the mp3's
are at and run

$ ./convert2ogg mp3
and when it is done
$ ./renamer

to rename the songs from *.mp3.ogg to *.ogg and then delete the mp3's
manually.

==========================================================
[olivares@acer-aspire-1 Download]$ cat renamer
#!/bin/sh

for i in *.mp3.ogg
 do
   mv "$i" "$(echo $i|sed 's/mp3.ogg/ogg/g')"
 done

[olivares@acer-aspire-1 Download]$ cat convert2ogg
#!/bin/sh
#
# Usage: convertoogg fileextention
#
if [ $1 = "" ];then
  echo 'Please give a audio file extention as argument.'
  exit 1
fi

for i in *.$1
do
  if [ -f "$i" ]; then
  rm -f "$i.wav"
  mkfifo "$i.wav"
  mplayer \
   -quiet \
   -vo null \
   -vc dummy \
   -af volume=0,resample=44100:0:1 \
   -ao pcm:waveheader:file="$i.wav" "$i" &
  dest=`echo "$i"|sed -e "s/$1$/ogg/"`
  oggenc -b 128 "$i.wav" "$dest"
  rm -f "$i.wav"
fi
done

==========================================================

My question is the following:
How can I run the script to recursively find all mp3's and convert
them to ogg vorbis(with ogg extension already in place/or rename them
in one step[instead of running two scripts] and deleting the mp3's)
all in one time?

Say I have a folder with songs:

Los Invasores de Nuevo Leon -> Disc 1
                                              -> Disc 2
                                              -> Disc 3
                                                     .
                                                     .
                                               -> Disc 20

And instead of going in manually and running the above scripts through
each folder, run a modified script that will recursively find all
mp3's in the directories and convert them to ogg, rename them and
delete the mp3's?  I know it can be done, but I am not expert and am
afraid to screw up [see thread of updating freebsd with portmaster -af
in case you have doubts].  I tend to shoot myself in the foot :(

Something like
$ find -iname "*.mp3" -exec ./convert2ogg ~/Los\ Invsores\ de\ Nuevo\ Leon/mp3

or similar that can do the job with a modified convert2ogg file that
can rename the output correctly in the first step.  Any
suggestions/advice/comments/observations are welcome.  I will attempt
this on Monday on my machine at work since it is the one that has the
screeching sound :(

I will also try to get back a machine[the one with # portupgrade -af ,
# portmaster ?,etc]

Regards,

Antonio



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTi=NZv0AF3UAnGxVy1rt6Kb8kP3Y3g>