How to Record ALSA Audio with FFmpeg on Linux

Recording audio from the Advanced Linux Sound Architecture (ALSA) using FFmpeg is an efficient way to capture microphone input or system sound directly from the command line. This guide provides a straightforward walkthrough on how to identify your ALSA input devices, construct the correct FFmpeg command, and customize your recording settings for optimal audio quality.

Step 1: Identify Your ALSA Input Device

Before recording, you need to find the designation of your audio hardware. Open your terminal and run the following command to list all capture hardware devices:

arecord -l

The output will list your soundcards and digital audio devices. Look for the card number and device number. For example, if you see card 0: PCH [HDA Intel PCH], device 0: ALC3232 Analog [ALC3232 Analog], your device identifier is hw:0,0.

Alternatively, you can use default to use the system’s default ALSA recording device.

Step 2: Run the Basic FFmpeg Recording Command

To capture audio using the default ALSA device and save it as a WAV file, use the following command:

ffmpeg -f alsa -i default output.wav

If you want to target a specific hardware device identified in Step 1 (such as card 0, device 0), replace default with hw:0,0:

ffmpeg -f alsa -i hw:0,0 output.wav

Press q in the terminal window to stop recording at any time.

Step 3: Customize Channels, Sample Rate, and Codec

To control the quality and format of your recording, you can pass additional parameters to FFmpeg.

Here is an example of recording high-quality stereo MP3 audio at 44.1 kHz:

ffmpeg -f alsa -ac 2 -ar 44100 -i hw:0,0 -c:a libmp3lame -b:a 192k output.mp3

Troubleshooting Common Issues