Record PulseAudio Audio with FFmpeg

This article explains how to capture audio from a PulseAudio source on Linux using the FFmpeg command-line tool. You will learn how to identify your PulseAudio input devices, record from default or specific sources (such as physical microphones or desktop audio monitors), and customize the output format and quality.

1. Identify Your PulseAudio Sources

To capture audio, you must first find the correct PulseAudio source name. Run the following command in your terminal:

pactl list sources short

This command lists all available audio inputs. The output will show device indexes and names. Look for names resembling: * alsa_input.pci-0000_00_1f.3.analog-stereo (a physical microphone or line-in) * alsa_output.pci-0000_00_1f.3.analog-stereo.monitor (a “monitor” source, which captures the system’s desktop audio output)

2. Record from the Default Audio Device

If you want to record quickly from your system’s default PulseAudio input device, use default as the input target:

ffmpeg -f pulse -i default output.mp3

This command captures audio from your default mic and encodes it into an MP3 file. To stop recording, press q or Ctrl+C in your terminal.

3. Record from a Specific Source

To capture audio from a specific device identified in step 1, copy its name and pass it directly to the -i option:

ffmpeg -f pulse -i alsa_input.pci-0000_00_1f.3.analog-stereo output.wav

4. Record System Desktop Audio (What You Hear)

To capture the audio playing through your speakers or headphones, target the monitor source associated with your active output device:

ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor output.ogg

5. Customize Audio Quality and Codecs

You can control channels, sample rates, and bitrates by adding standard FFmpeg parameters.

To record high-quality, stereo MP3 audio at 192kbps, use the following configuration:

ffmpeg -f pulse -ac 2 -ar 44100 -i default -acodec libmp3lame -ab 192k output.mp3