14

I am looking for a free tool that would allow me to convert large amounts of FLAC files to ALAC (Apple Lossless Audio Codec) while preserving the meta information and optionally adding new information from CDDB or similar sources.

At this moment I'm more interested in a Windows utility but you are free to recommend OS X ones. Please use different answers for different tools.

8 Answers 8

21

If you're happy using the Terminal, then you could try the following command loop:

for f in *.flac; do ffmpeg -i "$f"  -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac "${f%.flac}.m4a"; done

This will simply cycle through all the .flac files sitting in the current directory and convert them all to .alac until they're all done. I can confirm that this works in Linux where ffmpeg is freely available in the repositories. For OSX, you can install ffmpeg via homebrew, and there are also static builds for Windows, OSX and Linux listed on the ffmpeg website.

This will preserve the metadata, but the way that M4A stores cover images is fundamentally different from the way that FLAC (and most other audio formats) do it. Unfortunately, FFmpeg is currently unable to handle this. Fortunately, you can extract the cover as a jpeg image on the same step as transcoding the audio, and then use another command-line tool (AtomicParsley) to merge the cover into the M4A.

ffmpeg -i input.flac -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac output.m4a cover.jpg
AtomicParsley output.m4a --artwork cover.jpg --overWrite

This can similarly be put into a for loop; the &&s mean that the next command will only be performed if the previous command succeeds.

for f in *.flac; do ffmpeg -i "$f" -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac "${f/%flac/m4a}" "${f/%flac/jpg}" && \
AtomicParsley "${f/%flac/m4a}" --artwork "${f/%flac/jpg}" --overWrite && \
rm "${f/%flac/jpg}"; done
4
  • 1
    The ever-useful ffmpeg.
    – Mechanical snail
    Jul 13, 2011 at 23:06
  • 3
    On Windows, do: for %f in (*.flac) do ffmpeg.exe -i "%f" -acodec alac "%~nf.m4a"
    – Ilya
    Oct 20, 2012 at 17:43
  • 5
    Can confirm this worked for me (OS X 10.8.2), using brew install ffmpeg. It installed the dependencies texi2html, yasm, x264, faac, lame and xvid. All up it took around 10 minutes to install.
    – CaptainCasey
    Nov 17, 2012 at 11:58
  • I would only add that -vn (do not handle video0 is sometimes useful if the .flac has a mjpeg in the stream. Hopefully, Apple iTunes can get the album artwork for you or you can merge it in yourself from another source.
    – Sun
    Dec 7, 2015 at 5:13
7

X Lossless Decoder (XLD) is a great prefect lossless ripping and batch conversion tool for the Mac.

I've heard great things about getting perfect lossless rips using Exact Audio Copy (EAC) on Windows, though I'm not sure if it supports conversion.

3
  • Big fan of XLD. I've been using it for years to move Phish concerts in to my iTunes library.
    – Ian C.
    Apr 8, 2011 at 16:09
  • is it possible to go straight from flac to alac with xld though? seems like you have to go via wav/aiff first
    – Anentropic
    Jul 28, 2015 at 21:45
  • never mind... it comes with a GUI frontend and can in fact transcode direct to ALAC m4a files
    – Anentropic
    Jul 28, 2015 at 22:03
5

if you want convert everything flac file in folders and subfolders recursively add the /r to the for loop command like so:

for /r %%a in (".flac") do ffmpeg -i "%%a" -acodec alac "%%a.m4a" -map_metadata input.flac:output.m4a

The only problem i have with this is that filenames come out like

output.flac.m4a

I have no idea how to fix that at the end, but from what I've seen it doesn't HURT the file to be named this way.

EDIT: Replacing the output code with

"%%~na.m4a"

so that the full code looks like

for /r %%a in (".flac") do ffmpeg -i "%%a" -acodec alac "%%~na.m4a" -map_metadata input.flac:output.m4a

WILL make file names look like

output.m4a

BUT will save the converted copies to the ROOT of the folder you have the command run. To clarify flac file is located in

C:\music\foo\bar.flac

alac file will save to

C:\music\bar.m4a
1
  • This example does convert, but saves the output in the folder you start from, not the folder the original file is in. You also might want to make your final code the first example. You can get to the point first, then explain later if you want.
    – Sun
    Nov 19, 2014 at 16:18
4

Here's the Windows variant of boehj's answer:

for %f in (*.flac) do ffmpeg.exe -i "%f" -acodec alac "%~nf.m4a"
1
  • Can't comment on Ilya's post so I have to leave another answer... the variant for Powershell instead of cmd for windows would be: Get-ChildItem . -filter *.flac | ForEach-Object { ffmpeg -i "$_" -acodec alac "$($_.basename).m4a" }
    – BoteRock
    Feb 5, 2017 at 6:59
2

There are a wide range of applications for Windows and for OSX -

you could try Audio Transcoder

or Max

or a range of others (google will find many)

Or you could convert FLAC to WAV and then let iTunes do the rest

2

I went to the FFmpeg site to download the latest ffmpeg Win32 from 11/20/2012.

You may need 7zip to extract the EXEs and place them in a path that is recognized.

Still can't figure out how to recursively run the command. I've tried using an old DOS command called sweep and also forfiles -s -c but neither work correctly.

I ended up generating a list of flac files including their path using this DOS command:

m:\flac> dir *.flac /b /s > flac_convert.bat

I used the macro feature in NotePad++ (freeware) to change the line

from:

M:\flac\Art Of Noise\Moments In Love.flac

to:

ffmpeg -i "M:\flac\Art Of Noise\Moments In Love.flac" -acodec alac "M:\flac\Art Of Noise\Moments In Love.m4a"

Once I used the macro to change every line, I saved and ran flac_convert.bat

The solution is not elegant, but it does work using only free tools.

2

XRECODE does a great job of batch conversion. I'm pretty sure it is just a front end for ffmpeg. It keeps your tags and embedded images (for most formats - see this answer for exceptions) during conversion.

The current version has a non-expiring fully functional trial (complete with nag screen), but you can download the previous version for free.

I have not tried the conversion to ALAC, but it does a great job at FLAC, MP3, WMA, and OGG conversion.

1

For Windows DOS batch users, this will convert all FLAC from the current directory and recurse to save the output in the same directory that the FLAC is in. I put the echo in the command line so you can test the output before you actually start processing. Remove the echo if you are satisfied with the results.

for /r "." %x in (*.flac) do echo ffmpeg -i "%~fx" -acodec alac "%~dpnx.m4a"

  • for /r will loop through files (recurse subfolders)
  • . is the current path, but you can specify something specific like c:\flac
  • %x is your replaceable parameter. In batch files, add another % so it is %%x.
  • *.flac will only look for files with the extension flac in the current and subdirectories
  • what comes after do is the actual command that will be executed
  • %~fx is a parameter extension that will expand the %x variable to a fully qualified path name (e.g. c:\flac\song.flac)
  • %~dpnx is another parameter extension that is combined to 1) display the drive letter only, display path only with trailing backslash, and finally a file name without a file extension. In our example, c:\flac\song.flac now becomes c:\flac\song
  • we finally add .m4a manually to indicate the output extension we want.
  • The final constructed command will look like: ffmpeg -i "c:\flac\song.flac" -acodec alac "c:\flac\song.m4a"

warning since there is a 255 character limit for file paths, your files may not be processed if the directory structure is deep.

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