Convert FLAC to ALAC M4A for iTunes
2022-03-08
I had a bunch of .flac files (the newest the olllam album which I backed on Kickstarter in fact!). To get these on my old and beloved iPod, they can't be in FLAC format because iTunes is allergic to that. (Note: I'm just going to call Apple's Music app "iTunes" for the sake of SEO.) They need to be .aiff or ALAC (.m4a) before iTunes and my iPod will take them.
After searching through like 1,000 janky single-use apps for converting audio files, none of which quite worked for FLAC -> ALAC, a StackExchange post reminded me about the almighty ffmpeg which I've crossed paths with before during work on SlowMovie. It's a command-line audio and video conversion tool I can download with homebrew, no fuss, I just now had to find the right command to use by searching around on the web. I found it, and batch selection is built-in via bash! How nice, I don't have to rely on someone building in that feature to their app. Infitite customizability for the price of a Huge Pain In The Tookus figuring out how to do it, augmented by years of practice using the command line.
Anyway here's what worked:
for f in *.flac; do ffmpeg -i "${f}" -map_metadata 0 -vcodec copy -acodec alac -write_id3v2 1 "${f%%.*}.m4a"; done
Running this in the directory with all my .flac files creates .m4a ALAC files in the same directory. `-map_metadata 0` and `-vcodec copy` attempt to keep the same iTunes-related metadata on the files, which seems to have worked except for "Composer" for some reason.
Now my new lossless album will live happily in iTunes (okay "Music.app", whatever) and can by synced onto my iPod for my listening pleasure!
Oh but also iPod classics can't play lossless audio with higher than 48Khz sampling rate, so I'm just having Finder convert these to AAC during sync. At least that'll save space on the iPod and I can keep the lossless files around on my computer where there's more storage.