Record macOS Screen with FFmpeg AVFoundation

This article provides a quick, step-by-step guide on how to record your macOS screen and audio using FFmpeg’s avfoundation input device. You will learn how to identify your system’s hardware device indexes and run the precise command-line inputs required to capture high-quality screencasts directly from your terminal.

Step 1: Install FFmpeg

Ensure you have FFmpeg installed on your Mac. The easiest way to install it is via Homebrew. Open your Terminal and run:

brew install ffmpeg

Step 2: List Available Capture Devices

Before recording, you must identify the index numbers of your screen and audio inputs. Run the following command to list all available AVFoundation devices:

ffmpeg -f avfoundation -list_devices true -i ""

Your terminal will output a list of AVFoundation video and audio devices. Look for the index numbers under the “AVFoundation video devices” and “AVFoundation audio devices” sections. For example:

Step 3: Record Screen Only

To capture only your main screen (index 0) at 30 frames per second and save it as an MP4 file, use the following command:

ffmpeg -f avfoundation -framerate 30 -i "0" -pix_fmt yuv420p output.mp4

Step 4: Record Screen with Audio

To record your screen (index 0) along with your system’s microphone (index 0), combine them in the input parameter using the "video_index:audio_index" syntax:

ffmpeg -f avfoundation -framerate 30 -i "0:0" -pix_fmt yuv420p output.mp4

If you want to use a different audio device, replace the second 0 with the corresponding index from your device list.

Step 5: Stop the Recording

To stop recording at any time, click on your Terminal window and press Ctrl + C or press q. FFmpeg will safely stop capturing, finalize the encoding, and save the video file to your active directory.