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 ffmpegStep 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:
[0] Capture screen 0(Your main display)[1] FaceTime HD Camera[0] Built-in Microphone
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-f avfoundation: Specifies the input format library.-framerate 30: Sets the capture frame rate to 30 FPS.-i "0": Selects video device index0(screen) with no audio device.-pix_fmt yuv420p: Ensures the output video uses a pixel format compatible with most standard media players.
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.mp4If 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.