What are the command line options for afconvert?
Audio File Convert exports to 20 audio file formats and a multitude of codecs, all of which are shown with the -hf option.

Uncompressed Audio

File formats: AIFC AIFF NeXT Sd2f WAVE RF64

The original formats for storing audio files were all uncompressed because these are easy to work with, and can be played by even very early CPUs. However, uncompressed audio files are very large, easily going up to 10 MB/minute. These formats all share similar codec options like I8 BEI16 BEI24 BEI32 BEF32 BEF64. Smaller numbers give smaller files, but larger numbers give higher quality. If you're not sure what to choose, go with BEI32 or LEI32.

Compressed Audio

File formats: 3gpp 3gp2 adts ac-3 amrf m4af m4bf caff ec-3 flac mp4f

Not every codec is supported by every file format, but you can use this as a guide to get started choosing your codec. Once you've chosen a codec, you can look at the output of afconvert -hf to pick a suitable container file format.


aac MPEG-4 Low Complexity AAC
aace MPEG-4 AAC Enhanced Low Delay (without SBR)
aacf MPEG-4 AAC Enhanced Low Delay (with SBR)
aacg 
aach MPEG-4 High Efficiency AAC
aacl MPEG-4 AAC Low Delay
aacp MPEG-4 High Efficiency AAC Version 2
ac-3 AC-3
alac Apple Lossless
alaw aLaw 2:1
drms Apple DRM
ec-3 
flac Free Lossless Audio Codec
paac 
pac3 
pec3 
samr 
sawb
QDM2 QDesign2 Music
QDMC QDesign Music
Qclp QUALCOMM PureVoice
Qclq Qualcomm QCELP


(Note: I have excluded the MPG formats such as MPG3/MP3 from this list because they just do not work.)

Syntax

Once you've chosen a file format and codec, you run afconvert like this:

afconvert -f FORMAT -d CODEC SOURCEFILE [-o DESTINATIONFILE]


It is necessary to specify both the file format and the codec, otherwise an error is shown. If you omit the -o option, afconvert will pick a name and extension based on the other inputs.

Examples

If you have an audio file called MyAudio.m4a you could try these commands.

# AIFF
afconvert -f AIFF -d BEI32 MyAudio.m4a -o MyAudio.aiff


# WAVE
afconvert -f WAVE -d LEI32 MyAudio.m4a -o MyAudio.wav


# Apple Lossless
afconvert -f m4af -d alac MyAudio.m4a -o MyAudio.m4a


# FLAC
afconvert -f flac -d flac MyAudio.m4a -o MyAudio.flac


# AAC
afconvert -f mp4f -d aac MyAudio.m4a -o MyAudio.mp4