List ALSA Capture Devices in FFmpeg on Raspberry Pi

This guide demonstrates how to identify and list all available ALSA (Advanced Linux Sound Architecture) audio capture devices on a Raspberry Pi using FFmpeg. By querying ALSA through FFmpeg, you can retrieve the exact hardware identifiers required to configure USB microphones, audio hats, or sound cards for recording and streaming.

The FFmpeg Command

FFmpeg includes a dedicated flag to list input sources for specific demuxers. To view your ALSA capture devices, open your Raspberry Pi terminal and run:

ffmpeg -sources alsa

To suppress configuration banners and display only the relevant device information, add the -hide_banner flag:

ffmpeg -hide_banner -sources alsa

Understanding the Output

The output displays a table of detected ALSA audio devices. It typically looks like this:

Auto-detected sources for alsa:
  hw:0,0          [bcm2835 HDMI 1]
  hw:1,0          [USB PnP Sound Device]
  default         [Default ALSA Output/Input]
  • Device name (first column): The hardware identifier (such as hw:1,0 or plughw:1,0). The first number represents the card index, and the second represents the subdevice index.
  • Description (second column): The human-readable name of the connected hardware (e.g., your USB microphone).

Fallback Method: System ALSA Utilities

If your installed build of FFmpeg was compiled without device-probing support, ffmpeg -sources alsa may return an error stating that device listing is not supported. In this scenario, query the native ALSA capture list directly:

arecord -l

Locate your microphone in the list, noting the card and device numbers. For instance, card 1: Device [USB Audio Device], device 0: corresponds to the identifier hw:1,0 in FFmpeg.

Testing the Audio Capture

Once you have identified the device string, test that FFmpeg can capture audio from it using the -f alsa input format:

ffmpeg -f alsa -i hw:1,0 -t 5 test.wav

This records 5 seconds of audio from the specified ALSA device and saves it as test.wav. If you encounter sample rate or channel errors, substitute hw: with plughw: (e.g., plughw:1,0), which enables ALSA's automatic software resampling and channel conversion.