14

macOS includes a tool called afconvert which describes itself this way in the man page.

Audio File Convert will convert a source audio file to a new audio file with the specified file and data types

However, that's the entire man page. What are the command line options required and supported by afconvert? What are some basic examples of how to convert audio files back and forth?

3
  • 1
    Try running afconvert --help. Many (not all, but afconvert is one of them) command line programs will print some documentation in response to the --help option. Commented Jul 30, 2019 at 15:45
  • There's always ffmpeg. Commented Jun 29, 2024 at 12:47
  • A more extended manual page can be found at ss64.com/mac/afconvert.html Commented Aug 19, 2024 at 19:36

2 Answers 2

21

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.

  • BE big endian
  • LE little endian
  • I integer
  • UI unsigned integer
  • F floating point
  • 8/16/24/32/64 bits per sample

You should only need to specify these options for these older uncompressed formats.

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.

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

Also see this answer for more info on the various codecs and where they are defined.

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 
5
  • Thank you! I tried making this into an alias, (the .m4a to .wav conversion), but wasn't able to. I keep getting "unknown error occurred" :O alias 2wav='afconvert -f WAVE -d LEI32 $1 $1.wav' Commented Nov 21, 2020 at 19:48
  • @esaruoho Try a shell function instead. 2wav() { afconvert -f WAVE -d LEI32 ${1} ${1}.wav ; } Commented Nov 21, 2020 at 20:11
  • Thanks @Nic much appreciated, seemed to work!! Commented Nov 21, 2020 at 22:07
  • To convert a whole folder of files at once you can use something like the following: for f in *.aif ; do afconvert -f WAVE -d LEI32 "$f" -o "${f%.aif}.wav"; done Commented Dec 11, 2022 at 5:44
  • @esaruoho Put the whole alias value in quotes and escape the dollar symbols with a backslash: alias 2wav="afconvert -f WAVE -d LEI32 \$1 \$1.wav". Commented Feb 2, 2024 at 17:07
1

I've run into an important caveat with afconvert.

the help text gives many options, for instance --bitrate.

These options are codec dependent, and not all options work for all codecs. I haven't been able to find any definition of what codecs support which options, i've been going by trial and error.

The error message when using an apparently-unsupported option for the codec is:

Error: Couldn't set audio converter property ('!dat') 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.