Convert flac to mp4 (ALAC) with ffmpeg

 Fri, 19 Apr 2024 08:19 UTC

Convert flac to mp4 (ALAC) with ffmpeg
Image: CC BY 4.0 by cybrkyd

Both FLAC and ALAC are lossless audio formats. Conversion may be required to enable playback on systems which do not support FLAC. This is how to convert flac audio files to m4a (ALAC) with ffmpeg whilst retaining all the metadata.

To convert a single file:

$ ffmpeg -i flacfile.flac -c:v copy -c:a alac m4afile.m4a

Batch conversion

To convert multiple files, the following command can be used for files in the same directory:

$ find -name "*.flac" -exec ffmpeg -i {} -c:v copy -c:a alac {}.m4a \;

To convert multiple files and save the m4a files to a new directory called ‘m4a’:

$ mkdir m4a && find -name "*.flac" -exec ffmpeg -i {} -c:v copy -c:a alac m4a/{}.m4a \;

Cleaning up the file name ‘.flac.m4a’

With the batch conversion commands, the resulting m4a files retain the original .flac extension.

$ ls
'Clara Bow - Taylor Swift.flac'
'Clara Bow - Taylor Swift.flac.m4a'

To tidy up the file names, use the rename command.

$ rename 's/.flac//' *.m4a