How to Use FFmpeg AVFoundation on macOS

The avfoundation input device in FFmpeg allows users to capture real-time audio and video streams on macOS, including screen recordings, webcam feeds, and microphone inputs. This article provides a direct, step-by-step guide on how to list your available macOS hardware devices, configure input settings, and run commands to record video and audio using the -f avfoundation option.

Step 1: List Available Devices

Before recording, you must identify the device index numbers or names assigned to your hardware by macOS. Run the following command in your terminal to list all available video and audio input devices:

ffmpeg -f avfoundation -list_devices true -i ""

The output will display two categorized lists: AVFoundation video devices and AVFoundation audio devices. Each device will have a corresponding index number (e.g., [0] or [1]).

Step 2: Record Video Only

To capture video from a specific device, use the -f avfoundation format option followed by the video device index.

For example, to record from the webcam at video index 0:

ffmpeg -f avfoundation -i "0" output.mp4

To stop the recording at any time, press q or Ctrl+C in your terminal.

Step 3: Record Video and Audio Together

To capture both video and audio simultaneously, specify their device indexes in the input option using the format "[video_index]:[audio_index]".

For example, to record video from device 0 and audio from microphone device 1:

ffmpeg -f avfoundation -i "0:1" output.mp4

Step 4: Capture the macOS Screen

AVFoundation also lists your system screen as a video device (often labeled “Capture screen 0”). To record your desktop screen, locate its index number from the device list and run:

ffmpeg -f avfoundation -i "1" screen_record.mp4

(Note: Replace 1 with the actual index of your screen device from Step 1).

Step 5: Adjust Framerate and Resolution

You can customize the recording quality by specifying the framerate and video resolution before the input option.

To record screen capture at 30 frames per second with a resolution of 1280x720:

ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "1" output.mp4