Record Audio with FFmpeg and DirectShow on Windows
This guide explains how to capture audio from your microphone on Windows using FFmpeg and the DirectShow framework. You will learn how to locate your microphone’s exact system name and run the command-line arguments required to record and save your audio to a file.
Step 1: Locate Your Microphone Device Name
Before recording, you must identify the exact name of your audio input device as recognized by DirectShow. Run the following command in your Command Prompt or PowerShell:
ffmpeg -list_devices true -f dshow -i dummyLook through the terminal output for the section labeled “DirectShow
audio devices”. You will see a list of available input devices. Locate
your microphone and copy its name exactly as it appears (for example,
"Microphone (Realtek High Definition Audio)").
Step 2: Record Audio
Once you have the device name, use the following command structure to
start recording. Replace YOUR_MICROPHONE_NAME with the
exact device name you copied in the previous step:
ffmpeg -f dshow -i audio="YOUR_MICROPHONE_NAME" output.wavFor example:
ffmpeg -f dshow -i audio="Microphone (Realtek High Definition Audio)" output.wavPress q or Ctrl + C in the command line
interface to stop the recording.
Step 3: Customize Output Formats and Quality
You can customize the output format, audio codec, and sample rate during the capture process. To record directly to an MP3 file with custom settings, use the following command:
ffmpeg -f dshow -i audio="YOUR_MICROPHONE_NAME" -acodec libmp3lame -ar 44100 -ac 2 output.mp3-f dshow: Specifies the DirectShow input format.-i audio="...": Defines the audio input source.-acodec libmp3lame: Encodes the audio to MP3 format.-ar 44100: Sets the audio sample rate to 44.1 kHz.-ac 2: Records in stereo (use1for mono).