Record macOS Screen with FFmpeg and AVFoundation
This article provides a step-by-step guide on how to capture your macOS screen activity using FFmpeg and the native AVFoundation framework. You will learn how to identify your input devices, configure the recording commands, and save high-quality screen recordings directly from your terminal.
Step 1: Install FFmpeg
Before you begin, 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 Input Devices
AVFoundation is the system framework used by FFmpeg to access input devices on macOS. First, you need to find the index number of your screen and audio input devices. Run the following command:
ffmpeg -f avfoundation -list_devices true -i ""This command will output a list of available video and audio devices.
Look under the [AVFoundation input device @ ...] section.
You will see something like this:
[AVFoundation input device @ 0x7f9a12c040c0] AVFoundation video devices:
[AVFoundation input device @ 0x7f9a12c040c0] [0] Capture screen 0
[AVFoundation input device @ 0x7f9a12c040c0] AVFoundation audio devices:
[AVFoundation input device @ 0x7f9a12c040c0] [0] Built-in Microphone
Note the index number in the square brackets. In this example, the
screen is 0 and the microphone is 0.
Step 3: Record the Screen
To capture only the screen activity, use the device index you
identified in the previous step (e.g., 0). Run this command
to start recording:
ffmpeg -f avfoundation -framerate 30 -i "0" output.mp4-f avfoundation: Specifies the input format framework.-framerate 30: Sets the capture frame rate to 30 frames per second.-i "0": Selects video device index0.output.mp4: The name of the output video file.
Step 4: Record Screen and Audio Simultaneously
To record your screen along with system audio or your microphone,
specify both the video and audio indexes in the format
"video_index:audio_index".
Using the indexes from Step 2 (video 0 and audio
0), run:
ffmpeg -f avfoundation -framerate 30 -i "0:0" output.mp4Step 5: Stop the Recording
Once you have finished capturing your screen activity, return to the Terminal window and press q on your keyboard. FFmpeg will safely stop recording and finalize the video file.