Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

A Couple Of Scripts For Fast N Easy Music Files Conversion

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Paris Vanity Case
Posts: 104
Joined: 2007-03-08 18:30
Location: Athens, Greece

A Couple Of Scripts For Fast N Easy Music Files Conversion

#1 Post by Paris Vanity Case »

A friend of mine wrote a couple of simple and fast scripts for conversion of m4a and ogg music files to mp3. Here is how you can use them.

1. we need a folder where we keep scripts and this folder should be set as a path in .bashrc .
For example the folder /home/username/bin and the appropriate line in .bashrc:
CODE
#Paths
PATH="/home/username/bin:${PATH}"


2. in that folder create two new files m4a2mp3.sh and ogg2mp3.sh

3. make the files executables, in terminal:
CODE
chmod +x /home/username/bin/*


4. edit the files with your favorite editor and add these lines:
CODE

#!/bin/sh
IFS="
"
while [ "$#" -gt "0" ]
do
echo converting $1
if file $1 | grep "MPEG v4" >/dev/null
then
x=`echo $1 | sed 's/\(.*\.\)m4a/\1wav/'`
y=`echo $1 | sed 's/\(.*\.\)m4a/\1mp3/'`
if faad -o $x $1 >/dev/null 2>&1 && lame -h $x $y >/dev/null 2>&1
then echo OK!
rm $1
rm $x
else echo FAILED
fi
else echo 'NOT an MPEG v4 file'
fi
echo ''
shift
done

for the m4a2mp3.sh file and

CODE

#!/bin/sh
IFS="
"
while [ "$#" -gt "0" ]
do
echo converting $1
if file $1 | grep "Ogg data" >/dev/null
then
x=`echo $1 | sed 's/\(.*\.\)ogg/\1wav/'`
y=`echo $1 | sed 's/\(.*\.\)ogg/\1mp3/'`
if oggdec -o $x $1 >/dev/null 2>&1 && lame -h $x $y >/dev/null 2>&1
then echo OK!
rm $1
rm $x
else echo FAILED
fi
else echo 'NOT an OGG file'
fi
echo ''
shift
done

for the ogg2mp3.sh file.

5. now you can use the scripts to convert your files.
for example if you have some ogg files in /home/username/music/ you can type:
CODE
ogg2mp3.sh /home/username/music/*
to convert all of them. if there are any non-ogg files you will be notified and if you want to change specific files only you must type the exact path or cleverly use wildcards.

Please let me know if there are any typos or mistakes and let me thank Herc who wrote the scripts. Nice job Hercules!

PS: the scripts are licensed under GPL :wink:

User avatar
Paris Vanity Case
Posts: 104
Joined: 2007-03-08 18:30
Location: Athens, Greece

#2 Post by Paris Vanity Case »

PS: careful when changing paths at bashrc and never put files name after existing commands in any added folders or you could seriously mess up your system.

User avatar
rickh
Posts: 3434
Joined: 2006-06-29 02:13
Location: Albuquerque, NM USA

#3 Post by rickh »

Here's a more crude bash command I use to convert .wav files to .mp3 files. The main problem is that when the conversion is done, I have to go to the completed files and manually edit ".wav" out of the filename. One of these days, I'll put it together into a script using something similar to your sed commands to accomplish that automatically.

I like my .mp3 files to have a half second of silence leading in and a 3 second fadeout at the end, so after ripping a cd to .wav files, I edit them with Audacity to accomplish that as well as normalizing the volume. Then I handle the edited .wav files thus:

Create ~/tmp/ and ~/tmp/tmp/
Move the .wav files to ~/tmp/
$ for song in tmp/*.wav; do lame -V 1 "$song" "tmp/$song.mp3"; done

All the converted, high quality .mp3 files will now be in ~/tmp/tmp/
Debian-Lenny/Sid 32/64
Desktop: Generic Core 2 Duo, EVGA 680i, Nvidia
Laptop: Generic Intel SIS/AC97

User avatar
mzilikazi
Forum Account
Forum Account
Posts: 3282
Joined: 2004-09-16 02:14
Location: Colorado Springs, CO

#4 Post by mzilikazi »

rickh wrote:
All the converted, high quality .mp3 files will now be in ~/tmp/tmp/
"high quality" & "mp3" in the same sentence? Haha now that's a contradiction in terms! ;)
If you like a GUI to do all of the above and more:

Code: Select all

apt-get install soundconverter
It has a GUI and converts almost anything to almost anything else.
You also might want to apt-get install gtkpod. It has some nifty re-encoding scripts in /usr/share/gtkpod/scripts/
/usr/share/gtkpod/scripts/convert-flac2m4a.sh
/usr/share/gtkpod/scripts/convert-m4a2mp3.sh
/usr/share/gtkpod/scripts/convert-mp32m4a.sh
/usr/share/gtkpod/scripts/convert-ogg2m4a.sh
/usr/share/gtkpod/scripts/convert-wav2m4a.sh

I have no m4a to tinker with or I'd check em out myself.
Debian Sid Laptops:
AMD Athlon(tm) 64 X2 Dual-Core Processor TK-55 / 1.5G
Intel(R) Pentium(R) Dual CPU T2390 @ 1.86GHz / 3G

thamarok

#5 Post by thamarok »

RealAudio to MP3

Incase you have to download RealAudio music, you can convert it very easily to MP3 with just MPlayer and LAME:

Code: Select all

input_file=`dirname $1`'/'`basename $1 .rm`
mplayer $input_file'.rm' -ao pcm:file=$input_file'.wav'
lame -V0 -h $input_file'.wav' $input_file'.mp3'
rm $input_file'.wav'
xmessage -center "Conversion finished!"
Save that to a file like r2m.sh and then just chmod +x r2m.sh
Now whenever you need to convert a RealAudio file to MP3, just drag'n'drop the file on the r2m.sh icon and it does the conversion. Pretty handy isn't it ;)

Oh I just love to do small scripts in Bash <3

plugwash
Posts: 2507
Joined: 2006-09-17 01:10
Contact:

#6 Post by plugwash »

converting from one lossy format to another is something to be avoided where possible and certainly to be avoided for archival.

It is best to archive either in the format you received something in or a well supported lossless format or prefferablly both (the conversion from rm to flac will not be fully reversable but the flac is more likely to remain easilly readable into the future)

User avatar
rickh
Posts: 3434
Joined: 2006-06-29 02:13
Location: Albuquerque, NM USA

#7 Post by rickh »

Just a quick note here. This is the cleanest bash script, I have yet seen to convert .wav to .mp3

Code: Select all

#!/bin/bash
LAMEOPTS="-V 1"

for FILE in *.wav ; do
    OUTNAME="${FILE%%.wav}.mp3"
    lame $LAMEOPTS "$FILE" "$OUTNAME"
done
Debian-Lenny/Sid 32/64
Desktop: Generic Core 2 Duo, EVGA 680i, Nvidia
Laptop: Generic Intel SIS/AC97

mongooseman1128
Posts: 107
Joined: 2007-06-03 05:18

#8 Post by mongooseman1128 »

I have a bunch of .M4a files I got from iTunes but when I try to use soundconverter to convert the files it errors out the resulting file is an empty text document. I'm assuming this has something to do with copyright protection that iTunes puts on the files, but I'm not sure. How do I go about converting these files to mp3 (I would do .ogg but the files are going on my sandisk mp3 player which to my knowledge does not recognize .ogg). Also, as you may be able to tell I know very little about auido and video encoding I would appreciate any links to sites that can explain the inner workings of it.
HP DV6308NR
AMD Turion 64 X2 1.6 GHz
2 GB RAM
Broadcom 4311 wireless card
partition 1= Vista
partition 2= Swap
partition 3= Debian testing
partition 4= changes a lot

User avatar
rickh
Posts: 3434
Joined: 2006-06-29 02:13
Location: Albuquerque, NM USA

#9 Post by rickh »

Here's a script I have used to convert my kid's .m4a files to .mp3 files. No matter how much I rail at them, they have to be fashionable with their stinking ipods. No guarantees, but it worked for me.

Code: Select all

 #!/bin/bash
for i in *.m4a
do
faad "$i"
x=`echo "$i"|sed -e 's/.m4a/.wav/'`
y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
lame -h -b 128 "$x" "$y"
rm "$x"
done
It should go without saying that you have to have faad and lame installed.
Debian-Lenny/Sid 32/64
Desktop: Generic Core 2 Duo, EVGA 680i, Nvidia
Laptop: Generic Intel SIS/AC97

mongooseman1128
Posts: 107
Joined: 2007-06-03 05:18

#10 Post by mongooseman1128 »

Thanks for the help. :)
HP DV6308NR
AMD Turion 64 X2 1.6 GHz
2 GB RAM
Broadcom 4311 wireless card
partition 1= Vista
partition 2= Swap
partition 3= Debian testing
partition 4= changes a lot

Post Reply