afconvert

On a Mac OS X system, if you want to convert an audio file from one format to another from a command line interface (CLI), you can open a Terminal window - you can find the Terminal application in the /Applications directory - and run the afconvert command. The afconvert man page provides minimal information on the program's usage; issue the command afconvert -help at a Terminal window shell prompt to obtain details on the program's usage.

Aiseesoft Video Converter Ultimate 120x600

Over Eight Million Books w/ Free Shipping

Save Big at BiggerBooks.com
$ afconvert -help

    Audio File Convert
    Version: 2.0
    Copyright 2003-2013, Apple Inc. All Rights Reserved.
    Specify -h (-help) for command options

Usage:
afconvert [option...] input_file [output_file]
    Options may appear before or after the direct arguments. If output_file
    is not specified, a name is generated programmatically and the file
    is written into the same directory as input_file.
afconvert input_file [-o output_file [option...]]...
    Output file options apply to the previous output_file. Other options
    may appear anywhere.

General options:
    { -d | --data } data_format[@sample_rate][/format_flags][#frames_per_packet]
        [-][BE|LE]{F|[U]I}{8|16|24|32|64}          (PCM)
            e.g.   BEI16   F32@44100
        or a data format appropriate to file format (see -hf)
        format_flags: hex digits, e.g. '80'
        Frames per packet can be specified for some encoders, e.g.: samr#12
        A format of "0" specifies the same format as the source file,
            with packets copied exactly.
        A format of "N" specifies the destination format should be the
            native format of the lossless encoded source file (alac, FLAC only)
    { -c | --channels } number_of_channels
        add/remove channels without regard to order
    { -l | --channellayout } layout_tag
        layout_tag: name of a constant from CoreAudioTypes.h
          (prefix "kAudioChannelLayoutTag_" may be omitted)
        if specified once, applies to output file; if twice, the first
          applies to the input file, the second to the output file
    { -b | --bitrate } total_bit_rate_bps
         e.g. 256000 will give you roughly:
             for stereo source: 128000 bits per channel
             for 5.1 source: 51000 bits per channel
                 (the .1 channel consumes few bits and can be discounted in the
                 total bit rate calculation)
    { -q | --quality } codec_quality
        codec_quality: 0-127
    { -r | --src-quality } src_quality
        src_quality (sample rate converter quality): 0-127 (default is 127)
    { --src-complexity } src_complexity
        src_complexity (sample rate converter complexity): line, norm, bats
    { -s | --strategy } strategy
        bitrate allocation strategy for encoding an audio track
        0 for CBR, 1 for ABR, 2 for VBR_constrained, 3 for VBR
    --prime-method method
        decode priming method (see AudioConverter.h)
    --prime-override samples_prime samples_remain
        can be used to override the priming information stored in the source
        file to the specified values. If -1 is specified for either, the value
        in the file is used.
    --no-filler
        don't page-align audio data in the output file
    --soundcheck-generate
        analyze audio, add SoundCheck data to the output file
    --media-kind "media kind string"
        media kinds are: "Audio Ad", "Video Ad" 
    --anchor-loudness
        set a single precision floating point value to
        indicate the anchor loudness of the content in dB
    --generate-hash
        generate an SHA-1 hash of the input audio data and add it to the output file.
    --codec-manuf codec_manuf
        specify the codec with the specified 4-character component manufacturer
        code
    --dither algorithm
        algorithm: 1-2
    --mix
        enable channel downmixing
    { -u | --userproperty } property value
        set an arbitrary AudioConverter property to a given value
        property is a four-character code; value can be a signed
        32-bit integer or a single precision floating point value.
        e.g. '-u vbrq <sound_quality>' sets the sound quality level
             (<sound_quality>: 0-127)
        May not be used in a transcoding situation.
    -ud property value
        identical to -u except only applies to a decoder. Fails if there is no
        decoder.
    -ue property value
        identical to -u except only applies to an encoder. Fails if there is no
        encoder.

Input file options:
    --read-track track_index
        For input files containing multiple tracks, the index (0..n-1)
        of the track to read and convert.
    --offset number_of_frames
        the starting offset in the input file in frames. (The first frame is
        frame zero.)
    --soundcheck-read
         read SoundCheck data from source file and set it on any destination
         file(s) of appropriate filetype (.m4a, .caf).
    --copy-hash
         copy an SHA-1 hash chunk, if present, from the source file to the output file.
    --gapless-before filename
        file coming before the current input file of a gapless album
    --gapless-after filename
        file coming after the current input file of a gapless album

Output file options:
    -o filename
        specify an (additional) output file.
    { -f | --file } file_format
        use -hf for a complete list of supported file/data formats
    --condensed-framing field_size_in_bits
        specify storage size in bits for externally framed packet sizes.
        Supported value is 16 for aac in m4a file format.

Other options:
    { -v | --verbose }
        print progress verbosely
    { -t | --tag }
        If encoding to CAF, store the source file's format and name in a user
        chunk. If decoding from CAF, use the destination format and filename
        found in a user chunk.
    { --leaks }
        run leaks at the end of the conversion
    { --profile }
        collect and print performance information

Help options:
    { -hf | --help-formats }
        print a list of supported file/data formats
    { -h | --help }
        print this help
$

If you want to see the file formats and audio encodings it supports, you can issue the command afconvert -hf or afconvert --help-formats .

$ afconvert -hf
Audio file and data formats:
    '3gpp' = 3GP Audio (.3gp)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl' 
                             'aacp' 'samr' 
    '3gp2' = 3GPP-2 Audio (.3g2)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl' 
                             'aacp' 'samr' 
    'adts' = AAC ADTS (.aac, .adts)
               data_formats: 'aac ' 'aach' 'aacp' 
    'ac-3' = AC3 (.ac3)
               data_formats: 'ac-3' 
    'AIFC' = AIFC (.aifc, .aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 UI8 'ulaw' 
                             'alaw' 'MAC3' 'MAC6' 'ima4' 'QDMC' 'QDM2' 
                             'Qclp' 'agsm' 
    'AIFF' = AIFF (.aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 
    'amrf' = AMR (.amr)
               data_formats: 'samr' 'sawb' 
    'm4af' = Apple MPEG-4 Audio (.m4a, .m4r)
               data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp' 
                             'alac' 'paac' 
    'm4bf' = Apple MPEG-4 AudioBooks (.m4b)
               data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp' 
                             'paac' 
    'caff' = CAF (.caf)
               data_formats: '.mp1' '.mp2' '.mp3' 'QDM2' 'QDMC' 'Qclp' 
                             'Qclq' 'TS\x00\x02' 'TS\x00\x11' 'TS\x00E' 
                             'WMA1' 'WMA2' 'WMA3' 'WMAL' 'aac ' 'aace' 
                             'aacf' 'aach' 'aacl' 'aacp' 'alac' 'alaw' 
                             'dvi8' 'ilbc' 'ima4' I8 BEI16 BEI24 BEI32 
                             BEF32 BEF64 LEI16 LEI24 LEI32 LEF32 LEF64 
                             'ms\x00\x02' 'ms\x00\x11' 'ms\x001' 'paac' 
                             'qaac' 'qach' 'qacp' 'samr' 'ulaw' 'zaac' 
                             'zach' 'zacp' 
    'MPG1' = MPEG Layer 1 (.mp1, .mpeg, .mpa)
               data_formats: '.mp1' 
    'MPG2' = MPEG Layer 2 (.mp2, .mpeg, .mpa)
               data_formats: '.mp2' 
    'MPG3' = MPEG Layer 3 (.mp3, .mpeg, .mpa)
               data_formats: '.mp3' 
    'mp4f' = MPEG-4 Audio (.mp4)
               data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp' 
    'NeXT' = NeXT/Sun (.snd, .au)
               data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 'ulaw' 
    'Sd2f' = Sound Designer II (.sd2)
               data_formats: I8 BEI16 BEI24 BEI32 
    'WAVE' = WAVE (.wav)
               data_formats: UI8 LEI16 LEI24 LEI32 LEF32 LEF64 'ulaw' 
                             'alaw' 
$

For the supported file formats, you will see the name, e.g. "WAVE", the recognized file extensions, e.g., .wav for Waveform Audio File Format, i.e. WAVE or WAV, which reflects the commonly used file extension, then the data formats, which are UI8, LEI16 LEI24 LEI32 LEF32 LEF64 'ulaw', and 'alaw' for WAV files. The data formats are character codes such as "ulaw" or all capital letter strings for a Linear pulse-code modulation (LPCM) format. The LPCM formats are descibed in terms of endianness, value type, and sample size in bits. On PCs, LPCM often refers to the format used in WAV and AIFF audio container formats, but LPCM data may also be stored in other formats such as AU, raw audio format, and various multimedia container formats. The μ-law encoding is a very old encoding which reduces the dynamic range of an audio signal. The A-law algorithm is also used to modify the dynamic range of an analog signal. For further information on the afconvert utility, see pages 97 through 99 of Learning Core Audio: A Hands-On Guide to Audio Programming for Mac and iOS 1st Edition 1x1px by Chris Adamson and Kevin Avila.

If I have an MPEG-4 Part 14 .m4a file that I would like to convert to a WAV file, I can use the afconvert command below. The utility recognizes I want a WAV file from the extension and the data format for the output file is specified with -d LEI16. If I then wish to view information on the example.wav output file, I can examine it with the afinfo command - see Obtaining info on an audio file with afinfo.

$ afconvert "example.m4a" -d LEI16 "example.wav"
$ afinfo example.wav
File:           example.wav
File type ID:   WAVE
Num Tracks:     1
----
Data format:     2 ch,  44100 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
                no channel layout.
estimated duration: 4.085261 sec
audio bytes: 720640
audio packets: 180160
bit rate: 1411200 bits per second
packet size upper bound: 4
maximum packet size: 4
audio data file offset: 4096
optimized
source bit depth: I16
----
$

The afinfo command shows the duration of the audio file, which in this case is merely a few seconds, and the bit rate. The data rate, which is "16-bit little-endian signed integer" and the source bit depth, "I16" are also displayed. They were specified with the -d LEI16 parameter to the afconvert command; the "LE" stands for "Little Endian" and the "I" stands for "Integer". The codes for the LPCM formats, such as the UI8 LEI16 LEI24 LEI32 LEF32 LEF64 formats for WAV files, can be decoded from the following table:

LELittle Endian
BEBig Endian
FFloating point
IInteger
UIUnsigned Integer
8/16/24/32/64Number of bits

If I wanted to listen to the audio file using a command line utility, I could use the afplay command to play it - see Audio File Play - afplay.

Suppose I wanted to convert the .m4a file to an MP3 file, instead. From the output of the afconvert -hf command it appears the MP3 format is supported. But, if I try to convert the file to an .mp3 file, I get an error message:

$ afconvert "example.m4a" -d .mp3 "example.mp3"
Error: ExtAudioFileSetProperty ('cfmt') failed ('fmt?')
$

So why did I get an error message when the MP3 format appears to be supported? Some formats have restrictions. From Apple's Core Audio Services web page:

In many cases, you use Extended Audio File Services, which provides the simplest interface for reading and writing audio data. Files read using this API are automatically uncompressed and/or converted into linear PCM format, which is the native format for audio units. Similarly, you can use one function call to write linear PCM audio data to a file in a compressed or converted format. Supported Audio File and Data Formats in OS X lists the file formats that Core Audio supports by default. Some formats have restrictions; for example, by default, Core Audio can read, but not write, MP3 files.

You can see audio data types for which the utility can not encode from LCPM in the following table from Supported Audio File and Data Formats in OS X:

Udemy


Empire: Total War - Gold Edition

Audio data type

Encode from linear PCM?Decode to linear PCM?

MPEG Layer 3 ('.mp3')

No

Yes

MACE 3:1 ('MAC3')

Yes

Yes

MACE 6:1 ('MAC6')

Yes

Yes

QDesign Music 2 ('QDM2')

Yes

Yes

QDesign ('QDMC')

No

Yes

Qualcomm PureVoice ('Qclp')

Yes

Yes

Qualcomm QCELP ('qclq')

No

Yes

AAC ('aac ')

Yes

Yes

Apple Lossless ('alac')

Yes

Yes

Apple GSM 10:1 ('agsm')

No

Yes

ALaw 2:1 ('alaw')

Yes

Yes

Apple DRM Audio Decoder ('drms')

No

Yes

AC-3

No

No

DVI 4:1 ('dvi ')

No

Yes

Apple IMA 4:1 ('ima4')

Yes

Yes

LPC 23:1 ('lpc ')

No

Yes

Microsoft ADPCM

No

Yes

DVI ADPCM

Yes

Yes

GSM610

No

Yes

AMR Narrowband ('samr')

Yes

Yes

μLaw 2:1 ('ulaw')

Yes

Yes

 

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px