How to Record Screen on Mac Using FFmpeg

This article provides a quick guide on how to capture your macOS desktop screen using FFmpeg, a powerful command-line tool for handling multimedia. You will learn how to identify your system’s video and audio inputs using the AVFoundation framework and execute the exact FFmpeg commands needed to record high-quality screen captures with or without audio.

Step 1: Install FFmpeg on macOS

Before starting, ensure you have FFmpeg installed. The easiest way to install it on macOS is via Homebrew. Open your Terminal and run:

brew install ffmpeg

Step 2: List Available Input Devices

macOS uses the avfoundation device driver to capture input. To record your screen, you first need to find the device index numbers for your screen and microphone. Run the following command in Terminal:

ffmpeg -f avfoundation -list_devices true -i ""

This command will output a list of available video and audio devices. Look for the section labeled AVFoundation video devices and AVFoundation audio devices. Note the index numbers: * Screen Index: Usually labeled “Capture screen 0” or similar (e.g., [0] Capture screen 0). * Audio Index: Usually your built-in microphone (e.g., [1] Built-in Microphone).

Step 3: Record the Screen (Video Only)

Once you have the screen index, you can start recording. If your screen index is 1, use the following command:

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

Step 4: Record Screen and Audio Simultaneously

To record your desktop screen along with your microphone audio, combine the video and audio indexes using the format "[video_index]:[audio_index]".

For example, if your screen index is 1 and your microphone index is 0, run:

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

Step 5: Stop the Recording

To stop the recording, press q or Ctrl + C in your Terminal window. FFmpeg will safely finish writing the file and save the recording to your current directory.