#!/bin/sh # reference: https://superuser.com/questions/704493/ffmpeg-convert-m4a-files-to-mp3-without-significant-loss-of-information-quali/704535#704535 logfile="/mnt/bgstack15/log/m4a-to-mp3.$( date -u "+%FT%H%M%SZ" ).log" func() { for word in "$@" ; do echo "Entering item ${word}"; outdir="${word}/mp3" ; mkdir "${outdir}" || exit 1 ; find "${word}" -type f \( -regex '.*M4A' -o -regex '.*m4a' \) | while IFS='\0' read infile ; do test -f "${infile}" && echo "Found file: \"${infile}\"" || echo "INVALID! ${infile}" outfile="$( echo "${infile}" | sed -r -e "s/\.m4a/\.mp3/i" )" echo ffmpeg -i \"${infile}\" -codec:v copy -codec:a libmp3lame -q:a 2 \"${outfile}\" yes | ffmpeg -i "${infile}" -codec:v copy -codec:a libmp3lame -q:a 2 -y "${outfile}" ; test -n "${outdir}" && /bin/mv -f "${outfile}" "${outdir}/" ; sleep 2 ; done done } time func "$@" | tee -a "${logfile}"