Capture Audio and Video on macOS Using FFmpeg AVFoundation

This article provides a step-by-step guide on how to simultaneously capture video and audio on macOS using FFmpeg’s AVFoundation framework. You will learn how to locate your connected hardware input devices, map the audio and video sources correctly, and run a single command to record them into a synchronized media file.

Step 1: List Available Input Devices

Before capturing, you need to identify the index numbers of your video and audio input devices. Open your Terminal and run the following command to query AVFoundation:

ffmpeg -f avfoundation -list_devices true -i ""

This command will output a list of available AVFoundation video and audio devices. The output will look similar to this:

[AVFoundation indev @ 0x7f9a12345678] AVFoundation video devices:
[AVFoundation indev @ 0x7f9a12345678] [0] FaceTime HD Camera
[AVFoundation indev @ 0x7f9a12345678] [1] Capture screen 0
[AVFoundation indev @ 0x7f9a12345678] AVFoundation audio devices:
[AVFoundation indev @ 0x7f9a12345678] [0] MacBook Pro Microphone

Note the index numbers in the square brackets (e.g., [0] or [1]) for both the video and audio devices you want to use.

Step 2: Run the Capture Command

To capture video and audio simultaneously, use the index numbers you found in the previous step. The input syntax for AVFoundation uses the format "[video_index]:[audio_index]".

For example, to capture video from the “FaceTime HD Camera” (index 0) and audio from the “MacBook Pro Microphone” (index 0), use the following command:

ffmpeg -f avfoundation -framerate 30 -i "0:0" -c:v libx264 -pix_fmt yuv420p -c:a aac output.mp4

Explaining the Command Flags:

Step 3: Stop the Recording

Once the command is running, FFmpeg will continuously record the input. To stop the recording safely and finalize the output file, press q or Ctrl + C in your Terminal window.