M4aToMp3

wait for m4a files to appear (or already there), convert to mp3 in a subdirectory and move the m4a to a holding directory

#!/bin/sh

# assuming you are in the airplay recorder directory,
# create an mp3 directory and mp4 directory
# watch for new m4a files
# as each appears, and convert to mp3 in the mp3 directory
# move the m4a to a holding directory



# remove extension from file name in variable
# noext=${file%.m4a}

while true; do
    for FILE in *.m4a; do

       [ -f "$FILE" ] || break

       mkdir mp3 2>nul
       mkdir m4a 2>nul
       mkdir log 2>nul


       sleep 1

       BASE=${FILE%'.m4a'}

       DEST=$( printf "./mp3/%s.mp3" "$BASE")
       echo $DEST

       ffmpeg -y -i "$FILE" -codec:a libmp3lame -q:a 0 "$DEST">./log/ffmpeg.log 2>&1

       mv "$FILE" ./m4a

    done

    echo "waiting..."
    sleep 45

done

wait for m4a files to appear (or already there), convert to mp3 in a subdirectory and move the m4a to a holding directory. number the mp3 files as they come in

#!/bin/sh

# assuming you are in the airplay recorder directory,
# create an mp3 directory and mp4 directory
# watch for new m4a files
# as each appears, and convert to mp3 in the mp3 directory
# move the m4a to a holding directory


# remove extension from file name in variable
# noext=${file%.m4a}

while true; do
    echo $NUM
    for FILE in *.m4a; do

       [ -f "$FILE" ] || break

       mkdir mp3 2>nul
       mkdir m4a 2>nul
       mkdir log 2>nul

       sleep 1
       NUM=`find ./mp3/ -maxdepth 1 -print | grep -i "mp3$" |wc -l`
       let "NUM++"

       BASE=${FILE%'.m4a'}

       DEST=$( printf "./mp3/%04d %s.mp3" "$NUM" "$BASE")
       echo $DEST

       ffmpeg -y -i "$FILE" -codec:a libmp3lame -q:a 0 "$DEST">./log/ffmpeg.log 2>&1

       mv "$FILE" ./m4a

    done

    echo "waiting..."
    sleep 45

done

Various strategies for converting folder hierarchies from m4a to mp3


# convert all files to mp3 in the folder hierarchy
# find . -name '*.m4a' -type f -exec bash -c 'ffmpeg -vn -y -i "$0" -codec:a libmp3lame -q:a 0 "${0%.m4a}.mp3"' {} \;
# find . -name '*.m4a' -type f -exec bash -c 'ffmpeg -vn -n -i "$0" -codec:a libmp3lame -q:a 0 "${0%.m4a}.mp3" 2>&1' {} \;

# alias convert-aac="cd ~/Downloads && aac-to-mp3"
# 
# # Convert all .aac files into .mp3 files in the current folder, don't convert if a mp3 file already exists
# aac-to-mp3(){
#     find . -type f -iname "*.aac" -exec \
#         bash -c 'file="$1"; ffmpeg -n -i "$file" -acodec libmp3lame "${file%.aac}.mp3";' _ '{}' \;
# }