afconvert - macOS


Overview

afconvert (Audio File Convert) is a command-line utility in macOS used for converting audio files between different formats. The command allows users to specify input and output file formats, audio encoding quality, and other audio characteristics. This tool is particularly useful for developers, musicians, and audio engineers who need to manage audio files in various formats for diverse applications such as software development, music production, and media editing.

Syntax

The basic syntax of the afconvert command is as follows:

afconvert [options] input_file [output_file]
  • input_file: The path to the source audio file.
  • output_file: The path where the converted audio file will be saved. If not specified, afconvert will overwrite the input file.

Options/Flags

afconvert provides a range of options and flags that control how audio files are converted:

  • -f FORMAT: Set the output file data format (e.g., aac, wav, mp3).
  • -d FORMAT: Specify the output format for the audio data (e.g., aac, LEI16).
  • -q QUALITY: Define the quality of the output file where QUALITY can be an integer specifying the quality level (lower means better for some formats).
  • -r RATE: Set the sample rate of the output file in Hz.
  • -c NUMBER: Specify the number of output audio channels.
  • -b BITRATE: Set the audio bit rate for the output file in bits per second.
  • --help: Displays detailed usage information and exits.
  • -v: Enable verbose mode to provide more detailed output during conversion.

Examples

  1. Basic Conversion:
    Convert an audio file from WAV to AAC:

    afconvert -f m4af -d aac input.wav output.m4a
    
  2. Specifying Quality:
    Convert an MP3 file to AAC with high quality:

    afconvert -f m4af -d aac -q 127 input.mp3 high_quality.m4a
    
  3. Changing Sample Rate and Channels:
    Convert an audio file to mono WAV with a sample rate of 22050 Hz:

    afconvert -f WAVE -d LEI16 -c 1 -r 22050 input.m4a output.wav
    

Common Issues

  • Unsupported File Formats: Make sure that both the input and output formats are supported by afconvert.
  • Permission Errors: Ensure you have the necessary permissions to read the input file and write to the output directory.
  • Bit Rate Settings: Incorrect bit rate settings can lead to poor audio quality or overly large files. Always adjust the bit rate according to the needs of the project.

Integration

Combine afconvert with other commands like find for batch processing:

find . -name '*.wav' -exec afconvert -f m4af -d aac {} {}.m4a \;

This command finds all WAV files in the current directory and converts them to AAC format.

  • audiocvt: Another tool for manipulating audio files.
  • sox: A powerful cross-platform audio editing tool.

For more information and advanced options, you can refer to the official afconvert man page.