Record Screen and Mic with FFmpeg on Windows

This guide provides a straightforward method for capturing both your Windows desktop screen and microphone audio simultaneously using FFmpeg. By leveraging the built-in Windows screen-capture filter (gdigrab) alongside DirectShow (dshow) for audio input, you can create synchronized screen recordings without installing third-party graphical capture software.

1. Identify Your Microphone Device Name

Before recording, you need the exact name of your audio input device as recognized by Windows. Open Command Prompt or PowerShell and run:

ffmpeg -list_devices true -f dshow -i dummy

Look at the output under the "DirectShow audio devices" section. Note the exact name of your microphone inside quotation marks (for example, "Microphone (Realtek High Definition Audio)").

2. Run the Recording Command

Once you have your microphone name, use the following command to record both the screen and microphone:

ffmpeg -f gdigrab -framerate 30 -i desktop -f dshow -i audio="Microphone Name" -c:v libx264 -preset veryfast -pix_fmt yuv420p -c:a aac -b:a 192k output.mp4

Replace "Microphone Name" with the exact audio device name found in Step 1.

3. Understanding the Parameters

  • -f gdigrab -framerate 30 -i desktop: Uses Windows Graphics Device Interface (GDI) to capture the entire desktop at 30 frames per second.
  • -f dshow -i audio="Microphone Name": Captures audio from the specified DirectShow microphone.
  • -c:v libx264: Encodes the video stream using the standard H.264 video codec.
  • -preset veryfast: Balances CPU usage and compression efficiency in real time.
  • -pix_fmt yuv420p: Sets the pixel format to ensure the output file is compatible with standard media players.
  • -c:a aac -b:a 192k: Encodes the microphone audio into standard AAC format at 192 kbps.
  • output.mp4: The destination file name.

4. Stopping the Capture

To end the recording session, switch to the terminal window and press q on your keyboard (or press Ctrl + C). FFmpeg will finalize the container and save output.mp4 in the directory where the command was executed.