Bash: Scan a folder for files by extension.

I actualy fouind some m4a files in my collection and then converted them to MP3 and they did play fine. Here is the resulting script file. Save it as the file m4aTOmp3 in your home area ~/bin folder (/home/name/bin).

#!/bin/bash

#: Title       : /home/james/bin/m4aTOmp3
#: Date Created: Sun Dec 5 09:09:11 CST 2010
#: Last Edit   : Sun Dec 5 09:09:11 CST 2010
#: Author      : J. McDaniel
#: Version     : 1.00
#: Description : Convert m4a files to mp3 
#: Options     : none

current_directory=$( pwd )

#remove spaces

for i in *.[Mm]4[Aa]; do 

  mv "$i" `echo $i | tr ' ' '_'`; 

done

#remove uppercase

for i in *.[Mm]4[Aa]; do 

  mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; 

done


#convert m4a to wav files

for i in *.m4a ; do 

  faad $i; 

done

# convert wav to mp3

for i in *.wav ; do 

  name="${i%\.*}.mp3" ;
  lame -b 128 $i $name ; 

done 

# removing old files
rm *.wav
# rm *.m4a

exit 0
# End Of Script

To make it executable, run the following command:

chmod +x ~/bin/m4aTOmp3

To use m4aTOmp3 open a terminal session, change to the folder containing the m4a files and type in m4aTOmp3 and watch it go. It seems that you need to get rid of spaces and capital letters for proper conversion in Linux. Further, the file faad program converts everything to wav first, then uses lame to convert it to mp3. Notice the lame bitrate option of 128, this is the default, but you may want a higher number. You can test the mp3 files with the terminal program called play name.mp3 (part of the application called sox).

If this does not work for you, then you have multimedia problems. I suggest you download and run my script called mmcheck. Message #40 has the most recent version:

MMCHECK - Check Your Multimedia in 10 Steps - Script File, as proposed by RedDwarf

Thank You,