0

I've got a folder called Music, that has subfolders of different artist, containing a whole lot of .flac files. I'm trying to convert all of them into the .wav file format and then convert them to Apple alac, because the direct conversion is not working correctly, but the catch is that I have converted some of them before, but not all of them.

My folder looks basically like this:

Music/ArtistX/Song1.flac

Musik/ArtistX/Song1.m4a

Musik/ArtistX/Song2.flac

Musik/ArtistY/Song1.flac

Musik/ArtistY/Song1.m4a

Basically I want a command that lets me convert only the .flac files that haven't got a corresponding .m4a file next to them. In the past I simply converted all of them again by running this crude for loop:

for f in ./**/*.flac; do ffmpeg -i "$f" "${f%.*}.wav"; done && for f in ./**/*.wav; do ffmpeg -n -i "$f" -acodec alac "${f%.*}.m4a"; done && find . -type f -name '*.wav' -delete

But this is very inefficient for my current setup.

P.S.: If it is at all possible I would prefer to use ffmpeg.

  • Have you tried using find? Try something like "find . -name '*.flac' -exec ffmp -i {} >{}.wav \;" Might be more efficient. – Lewis M Sep 24 '18 at 20:00
  • That would still run unwanted conversion to .wav for files that I already converted all the way to .m4a – bastianplettner Sep 24 '18 at 20:21
0

Why not just searching for flac files, check for existing m4a files, and convert if no m4a file exists? Just a little example:

for i in $(find $PWD -name "*.flac")
do
    # check if file was already converted and therefore a m4a file exists
    if [ ! -e $(dirname ${i})/$(basename ${i} .flac).m4a ]
    then
       # convert your file... File including path is in ${i}
       echo "Need to convert input file ${i} now..."
       WAV=$(dirname ${i})/$(basename ${i} .flac).wav
       M4A=$(dirname ${i})/$(basename ${i} .flac).m4a
       ffmpeg -i ${i} ${WAV}
       ffmpeg -n -i ${WAV} -acodec alac ${M4A}
       rm ${WAV}
    fi
done
  • This doesn't work because I have got spaces in my file and directory names, the command seems to split the variable ${i} after every space – bastianplettner Sep 24 '18 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.