How to List ALSA Audio Devices Using FFmpeg
To record audio on Linux, you first need to identify the correct input source. This article provides a quick and direct guide on how to list all available ALSA (Advanced Linux Sound Architecture) audio capture devices using FFmpeg, allowing you to easily find the correct device identifier for your audio recording and streaming commands.
To list all available ALSA audio capture devices, open your terminal and run the following FFmpeg command:
ffmpeg -sources alsaThis command queries the ALSA demuxer through FFmpeg’s device framework and outputs a list of recognized input sources.
Understanding the Output
The output will display the recognized devices in a structured format. Look for the lines under the source list, which will typically look like this:
Auto-detected sources for alsa:
default [Default ALSA Output (currently PulseAudio Media Role...)]
* hw:0,0 [HDA Intel PCH, ALC3232 Analog]
hw:0,2 [HDA Intel PCH, ALC3232 Alt Analog]
- Device Identifier: The string on the left (e.g.,
hw:0,0ordefault) is the short name of the device. This is the identifier you must pass to FFmpeg when recording. - Device Description: The text inside the brackets on the right provides a user-friendly description of the hardware, helping you determine which physical microphone or line-in port it refers to.
- **The Asterisk (*):** The asterisk indicates the system’s current default audio capture device.
How to Record Using the Identified Device
Once you have identified your desired ALSA device from the list, you
can use it in an FFmpeg command to capture audio. For example, to record
audio from the device hw:0,0 and save it as an MP3 file,
use the following command:
ffmpeg -f alsa -i hw:0,0 output.mp3Alternative: Using System ALSA Tools
If your version of FFmpeg was compiled without the device listing
capability, you can retrieve the exact same hardware identifiers using
the native ALSA tool arecord:
arecord -lThis will print a list of digital audio capture hardware devices,
showing the card number and device number (e.g.,
card 0: PCH ..., device 0: ALC3232 Analog), which maps
directly to the hw:0,0 format used in FFmpeg.