How to Use Afconvert

How to Use Afconvert

with 2 Comments

Afconvert is a command-line utility built into the Mac OS. I find it useful for batch converting the sampling rate and format of audio files.

Examples

Note: All of these examples assume that the files you wish to convert are in your home directory. If they are not, you will have to provide the path to them (or cd to the directory where the sound files are located).


To convert a sound file from .caf to .wav:

afconvert -f WAVE -d LEI24 "Audio File.caf" "Audio File.wav"

Change “Audio File” to the name of your audio file.


To convert a sound file from .caf to .wav and from 96kHz/24bit to 48kHz/24bit:

afconvert -f WAVE -d LEI24@48000 "Audio File.caf" "Audio File.wav"

Change “Audio File” to the name of your audio file.


To convert multiple sound files from .caf to .wav and from 96kHz/24bit to 48kHz/24bit:

for i in *.caf; do baseFilename=`basename "${i}" .caf` && afconvert -f WAVE -d LEI24@48000 "${i}" "${baseFilename}.wav"; done
for i in *.caf; do baseFilename=`basename "${i}" .caf` && afconvert -f WAVE -d LEI24@48000 --src-complexity bats -r 127 "${i}" 48kWavVersions/"${baseFilename}.wav"; done

This is the same as the example above, however it puts the new files in a folder called “48kWavVersions” (make sure you have a folder called “48kWavVersions” in the same directory). Also, it uses the highest settings available in afconvert for sample-rate conversion (src) quality and complexity.

The image at the top of this post is of three sonograms of a 10-second sine-wave sweep from 0 to 48kHz that was converted from 96kHz/24bit to 48kHz/24bit using the three src complexity settings that afconvert offers: “line,” “norm,” and “bats” (from top to bottom respectively). The src quality, on the other hand, was kept constant at the highest setting of 127 (which is also the default). Note how the signal folds back into the spectrum when it reaches the top of the frequency range of the “line” setting spectrogram. This is a distortion of the signal known as aliasing. Note how the aliasing is greatly reduced in the “norm” setting spectrogram, and essentially absent in the “bats” setting spectrogram.


To convert multiple sound files from .aif to .wav and from 128kHz/24bit to 44.1kHz/24bit:

for i in *.aif; do afconvert -f WAVE -d LEI24@44100 --src-complexity bats -r 127 "${i}"; done

This will place the converted sound files in the same directory as the original sound files (the original files will not be erased). Each new sound file will have the same base name as the original, but the suffix will be changed to .wav.


To convert multiple sound files from .wav to .m4a (using AAC for the data format):

for i in *.wav; do afconvert -v -f m4af -d aac -b 192000 -q 127 -s 2 "${i}"; done

The flags mean: print progress info verbosely in the Terminal during processing (-v), use the MP4 file format with the audio-only designation in the suffix (-f m4af), use the AAC data format (-d aac), encode at a bitrate of 192 kbps for all the channels combined (-b 192000),* use the highest quality for the codec (-q 127), use VBR constrained (-s 2).

*In this case, a mono audio file will have a bitrate of approximately 192 kbps, a stereo file will have a bitrate of approximately 96 kbps per channel, and so forth.

See:
http://support.moonpoint.com/os/os-x/audio/afconvert.php
https://apple.stackexchange.com/questions/46076/what-are-the-afconvert-settings-for-the-itunes-plus-aac-encoding-setting


Further info

For general help on afconvert:

afconvert -h

For help on the file formats:

afconvert -hf

2 Responses

  1. Jason
    | Reply

    This explanation and examples worked great. I was able to convert an entire library of music. I even made aliases for the commands and formats I needed, so now it’s a snap. Thank you!!

    • John
      | Reply

      I’m happy to hear it was useful!

Leave a Reply