How to Use the afconvert Command on Mac to Batch Convert and Compress Audio Files in Terminal

Transforming uncompressed high-resolution audio files (such as 24-bit 96 kHz WAV or AIFF) into compact, streaming-ready formats like AAC, MP3, or Apple Lossless (ALAC) typically leads users to install third-party applications like Audacity, HandBrake, or FFmpeg. However, macOS includes an enterprise-grade, hardware-accelerated audio conversion engine built directly into the operating system: afconvert (Audio File Convert). Available from any Terminal shell, afconvert provides deep access to Apple’s Core Audio framework for precision audio transcoding, bit-depth dithering, and automated batch scripting.

Understanding afconvert and the Core Audio Pipeline

Unlike third-party converters that rely on external software codecs, afconvert connects directly to Apple’s proprietary AudioToolbox and Core Audio libraries. This integration provides several key benefits:

  • Apple AAC Codec Excellence: Core Audio’s AAC encoder is widely recognized by sound engineers as one of the highest-fidelity perceptual audio encoders available, outperforming standard open-source AAC encoders at identical bitrates.
  • Zero External Dependencies: Present out-of-the-box on every modern macOS installation (from OS X through macOS Sequoia) with no Homebrew or Xcode requirements.
  • Broad Format Compatibility: Reads and writes standard container formats including AIFF (.aif), WAVE (.wav), Core Audio Format (.caf), MPEG-4 Audio (.m4a), and NeXT/Sun audio (.au).

Basic Command Syntax and Format Flags

The standard syntax for converting an audio file requires specifying the output file format (-f) and the underlying audio data format (-d):

afconvert -f [file_format] -d [data_format] [options] input_file [output_file]

To inspect all available container file formats supported by your system’s Core Audio engine:

afconvert -hf

To view all available encoding data formats (such as AAC, ALAC, Linear PCM, and IMA 4:1):

afconvert -hd

Converting WAV or AIFF to High-Quality AAC (M4A)

To compress an uncompressed master recording into a high-quality AAC file wrapped inside an MPEG-4 container:

afconvert -f m4af -d aac -b 256000 input.wav output.m4a

The parameters operate as follows:

  • -f m4af: Sets the container format to MPEG-4 Audio (.m4a).
  • -d aac: Applies the Advanced Audio Coding (AAC) compression algorithm.
  • -b 256000: Sets the target constant bitrate to 256 kbps (Apple Music standard quality).

For even greater fidelity and dynamic efficiency, enable True Variable Bitrate (VBR) encoding by specifying the -u (user property) flag:

afconvert -f m4af -d aac -u pgcm 2 -q 127 -b 256000 master.wav master_vbr.m4a

Where -q 127 commands the Core Audio encoder to operate at maximum algorithmic precision.

Converting to Apple Lossless Audio Codec (ALAC)

If you need to compress large studio masters without discarding a single bit of acoustic data, transcode into Apple Lossless (ALAC):

afconvert -f m4af -d alac input.wav output_lossless.m4a

This typically halves the physical file footprint compared to raw Linear PCM while maintaining mathematically identical waveforms upon decompression.

Resampling and Sample-Rate Conversion

Studio audio recorded at 96 kHz or 192 kHz frequently requires downsampling to standard red-book 44.1 kHz or broadcast 48 kHz:

afconvert -f WAVE -d LEI16@44100 --src-complexity bats input.wav output_44k.wav

Where:

  • LEI16@44100: Specifies Little-Endian 16-bit integer PCM at a 44,100 Hz sample rate.
  • --src-complexity bats: Instructs the Sample Rate Converter (SRC) to use “Best Quality (Bats)” sinc-interpolation filters, ensuring zero audible aliasing or phase distortion.

Automating Batch Audio Conversion with a Bash Loop

Because afconvert processes a single file per execution, transcode an entire directory of WAV files into AAC using a simple terminal shell loop:

for f in *.wav; do
    echo "Transcoding ${f}..."
    afconvert -f m4af -d aac -b 256000 "${f}" "${f%.wav}.m4a"
done

This shell script iterates across all .wav files in the current folder, generates corresponding .m4a files, and preserves the original lossless master files untouched.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.