Audio

Convert and Compress Audio From the Terminal on macOS (afconvert)

By the Smol team7 min read

macOS has a built-in audio converter called afconvert. To turn a WAV into a 128 kbps M4A, run afconvert -f m4af -d aac -b 128000 in.wav out.m4a in Terminal. Nothing to install. It writes AAC, ALAC, FLAC, WAV, AIFF and CAF, but not MP3.

How do I convert WAV to M4A in Terminal?

afconvert -f m4af -d aac -b 128000 song.wav song.m4a

Read it left to right. -f m4af is the file container (M4A). -d aac is the data format (AAC). -b 128000 is the total bitrate in bits per second. Then input, then output. If you leave out the output name, afconvert makes one next to the input.

On our 30 second stereo test file (a 5,292,078 byte WAV) that command produced a 427,472 byte M4A. The encoder landed under the requested rate, at about 112 kbps by afinfo. That test signal was noise plus a tone, which is harder to compress than most music, so real recordings often land smaller.

Which afconvert command should I use for each job?

JobCommandOur 30 s test result
WAV to AAC, 64 kbpsafconvert -f m4af -d aac -b 64000 in.wav out.m4a212,166 bytes
WAV to AAC, 256 kbpsafconvert -f m4af -d aac -b 256000 in.wav out.m4a946,347 bytes
WAV to AAC, variable bitrateafconvert -f m4af -d aac -s 3 -u vbrq 64 in.wav out.m4a285,250 bytes
WAV to Apple Losslessafconvert -f m4af -d alac in.wav out.m4a1,885,425 bytes
WAV to FLACafconvert -f flac -d flac in.wav out.flac1,868,687 bytes
WAV to 22.05 kHz WAVafconvert -f WAVE -d LEI16@22050 in.wav out.wav2,650,096 bytes
Anything to WAVafconvert -f WAVE -d LEI16 in.mp3 out.wavMP3 input decoded fine

The lossless rows (ALAC, FLAC) cut the WAV to roughly a third here, with no change to the sound. The lossy rows go much smaller. For the trade-off between rates, read audio bitrate explained.

What do the afconvert options mean?

  • -f: file format. Useful values are m4af (M4A), WAVE, AIFF, caff, flac. Run afconvert -hf for the full list.
  • -d: data format, optionally with a sample rate, like aac@32000 or LEI16@44100.
  • -b: total bitrate in bits per second. For stereo, 256000 means about 128000 per channel.
  • -c 1: number of channels. Use it for mono.
  • -s: bitrate strategy. 0 is constant, 1 average, 2 constrained variable, 3 variable.
  • -u vbrq 0-127: quality level when using variable bitrate.
  • -q 0-127: encoder quality, separate from bitrate.

Mono helps speech a lot. A 32 kHz mono AAC at 64 kbps (afconvert -f m4af -d aac@32000 -b 64000 -c 1 in.wav out.m4a) came out at 246,989 bytes on our test, about the full 64 kbps. The stereo 64 kbps run undershot its target, so mono is not automatically smaller at the same number. Check the result with afinfo out.m4a before you batch a whole folder.

How do I batch convert a folder of audio in Terminal?

mkdir -p out
for f in *.wav; do
  afconvert -f m4af -d aac -b 128000 "$f" "out/$(basename "$f" .wav).m4a"
done

Quote every variable so filenames with spaces work. Writing into a separate out folder means a typo never overwrites an original. Two 30 second files converted in about 0.3 seconds total on our Mac. For other input types, change the glob (*.aiff, *.flac) or loop over several.

More on loops and Automator in how to batch convert audio on a Mac.

Can afconvert make MP3 files?

No. We tried afconvert -f MPG3 -d .mp3 in.wav out.mp3 and it stopped with an error about the output format. afconvert can read MP3, so MP3 to WAV or M4A works. Writing MP3 needs another tool. If MP3 is the target, our guides for WAV to MP3 and M4A to MP3 cover the options.

When is Smol the wrong tool for this?

If you are comfortable in Terminal, afconvert is free, fast and enough for most one-off or scripted jobs. Smol is the wrong purchase if all you need is WAV to M4A in a shell loop.

Smol earns its $29 (once, one Mac) if you would rather drag a mixed folder in, get per-file savings, and have MP3, FLAC, OGG and Opus output as well as AAC, M4A and WAV, with bitrate from 16 to 512 kbps. It adds a Finder right-click action and watched folders, and nothing is uploaded. See pricing or the best audio converter for Mac comparison.

How we checked this

Ran afconvert 2.0 and afinfo on a generated 30 second stereo WAV with each command shown, compared byte sizes, and tried an MP3 output (it failed). Read the afconvert help text for option meanings. Facts last checked . We make Smol, so treat our claims about it with the same care as any vendor’s, and see our editorial policy.

afconvert and Terminal audio: common questions

Is afconvert installed on every Mac?

Yes. afconvert is part of macOS, so it needs no Homebrew or download. Type afconvert -h in Terminal to see the options and afconvert -hf for the supported formats. We ran version 2.0 for this guide.

What is the best afconvert command to shrink a WAV?

afconvert -f m4af -d aac -b 128000 in.wav out.m4a is a solid default. It turned our 5.3 MB test WAV into a 427 KB M4A. Use 64000 for speech, 256000 for music you care about. If you want no quality loss, use -d alac or FLAC instead.

Can afconvert convert M4A to MP3?

No, afconvert cannot write MP3. It can read MP3 and M4A, so you can go to WAV, AIFF, or AAC. To produce MP3 you need another tool. Our M4A to MP3 guide shows the free options on a Mac.

Does afconvert keep tags like title and artist?

We did not test tag handling, so we will not promise it. Check a converted file with afinfo or Music before deleting the originals. The command also has a media-kind option for labels such as Podcast and Audiobook.

How do I see the bitrate of a converted file?

Run afinfo file.m4a. It prints the duration, sample rate, channel count and bit rate. For our 128000 request it reported about 112 kbps, because the encoder does not always use the full rate you ask for. Check this before batching a folder.

Keep reading