Capture macOS Audio with FFmpeg and CoreAudio
This guide provides a straightforward walkthrough on how to capture system and input audio on macOS using FFmpeg and the native CoreAudio framework via the AVFoundation device. You will learn how to identify your Mac’s audio devices, configure the correct FFmpeg commands, and record high-quality audio directly from the terminal.
Step 1: List Available Audio Devices
FFmpeg interfaces with macOS CoreAudio using the
avfoundation input device. First, you must list the
available hardware and virtual audio devices connected to your system to
find their index numbers or names.
Open your Terminal and run the following command:
ffmpeg -f avfoundation -list_devices true -i ""The output will display a list of video and audio devices. Look under
the AVFoundation audio devices section. Note the index
number or the exact name of the device you want to capture (for example,
[1] MacBook Pro Microphone).
Step 2: Record Audio from an Input Device
Once you have identified the device index, you can start recording.
In AVFoundation, the input option -i uses the format
"[video_index]:[audio_index]". To record audio only, leave
the video index blank and put a colon before the audio index.
Run the following command to record audio using device index
1 and save it as an MP3 file:
ffmpeg -f avfoundation -i ":1" output.mp3To record using the device name instead of the index, use:
ffmpeg -f avfoundation -i ":Built-in Microphone" output.wavPress q in your terminal window to stop the recording at
any time.
Step 3: Capture System Audio (Internal Sound)
By default, macOS CoreAudio does not allow direct recording of system output (the sound coming out of your speakers) due to security restrictions. To capture system audio with FFmpeg, you must install a virtual audio loopback driver such as BlackHole (an open-source audio driver).
Install BlackHole (e.g., BlackHole 2ch) via Homebrew:
brew install blackhole-2chOpen Audio MIDI Setup on your Mac (found in Applications > Utilities).
Click the
+icon in the bottom left and select Create Multi-Output Device.Check the box for both your primary output device (e.g., MacBook Pro Speakers) and BlackHole 2ch. This allows you to hear the audio while routing it to the virtual driver.
Set your Mac’s system output to this new Multi-Output Device.
Run the list command again to find the index of BlackHole:
ffmpeg -f avfoundation -list_devices true -i ""Start recording the system audio using the BlackHole index (assuming BlackHole is index
2):ffmpeg -f avfoundation -i ":2" system_audio.wav