I'm looking for a way to convert all alac files in a directory recursively to another format.Problem: alac as well as aac use suffix m4a, so find -name *.m4a doesn't work.
Find and convert all ALAC files to mp3 / opus / aac
bash;find;ffmpeg
You need a tool that can detect the codec in the m4a files. One such tool is avprobe which is available in debian based linuxes in package libav-tools (I use Ubuntu 14.04).Then you can do like this (if there are no newlines in file names..):find . -name \*.m4a | while read file; do avprobe $file 2>&1 |grep -q 'Audio: alac' && echo $file; doneobviously substituting echo $file for the convert command.If it's not feasible to install such a tool, you can probably estimate it with grep -q Halac $file && grep -q '$alac' $file. The few apple lossless files I tested contain those two strings, but it can match files which are not really apple lossless codec with a small probability, and I'm not quite sure apple lossless files are guaranteed to contain those strings. If that's okay, the above becomesfind . -name \*.m4a | while read file; do grep -q Halac $file && grep -q '$alac' $file && echo $file; done