brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: afconvert converts audio files on a Mac without extra software

Terminal
~/tips/tip-macos-afconvert-audio

afconvert -f m4af -d aac -b 256000 recording.wav recording.m4a

Converts audio, for example WAV to AAC, with a converter that already comes with macOS.

Before installing ffmpeg on a fresh Mac just to turn one WAV file into something smaller, it’s worth knowing that macOS already has an audio converter built in. It’s called afconvert, it uses Apple’s own Core Audio encoders, and it’s one of those tools I wish more people knew about.

You give it a file format with -f, a data format with -d, and optionally a bitrate with -b in bits per second. This turns a WAV recording into an AAC file at 256 kbps in an .m4a container:

afconvert -f m4af -d aac -b 256000 recording.wav recording.m4a

The result plays in Music, QuickTime and on an iPhone without fuss. If you want lossless instead, Apple Lossless is the alac data format in the same m4af container. To see every file type and which data formats each one accepts, run afconvert -hf. That list is long and it’s the real documentation, so I’d keep it open while you work out a command.

Converting a whole folder is a small loop:

for f in *.wav; do afconvert -f m4af -d aac "$f" "${f%.wav}.m4a"; done

The caveat: there’s no MP3 encoder in afconvert. It reads MP3 fine, it just can’t write it, so for MP3 output you still need something like LAME or ffmpeg. Also give the output file the right extension yourself. afconvert writes to whatever name you type, and other apps are a lot less forgiving about a mismatch.

Further reading: afconvert man page (SS64)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link