Record PulseAudio Audio with FFmpeg on Linux
Recording system audio or microphone input on Linux is a common task that can be easily accomplished using FFmpeg and PulseAudio. This guide provides a straightforward, step-by-step tutorial on how to identify your PulseAudio input devices and capture high-quality audio directly to a file using simple FFmpeg commands.
Step 1: Find Your PulseAudio Source Name
Before recording, you need to identify the name of the audio source you want to capture. PulseAudio distinguishes between physical inputs (like microphones) and “monitors” (which capture the audio playing out of your speakers).
Run the following command in your terminal to list all available sources:
pactl list sources shortThis will output a list of sources. Look for the name of the device you want to record.
- To record microphone/line-in input, look for a name
containing
input, such asalsa_input.pci-0000_00_1f.3.analog-stereo. - To record system output (what you hear), look for a
name ending in
.monitor, such asalsa_output.pci-0000_00_1f.3.analog-stereo.monitor.
Step 2: Record Audio Using FFmpeg
Once you have the source name, you can use FFmpeg to capture the audio.
Record from the Default Audio Device
If you simply want to record from your default PulseAudio input device, run:
ffmpeg -f pulse -i default output.mp3Record from a Specific PulseAudio Source
To record from a specific device identified in Step 1, pass the exact
source name to the -i parameter.
For example, to record system playback (desktop audio):
ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor output.wavCommand Breakdown
-f pulse: Tells FFmpeg to use the PulseAudio input device demuxer.-i <source_name>: Defines the input source. Replace<source_name>withdefaultor the specific device name from yourpactllist.output.wav/output.mp3: The destination file. FFmpeg automatically detects the desired audio codec based on the file extension you provide. You can also specify codecs manually (e.g.,-acodec libmp3lameor-acodec flac) for more control over the output format.
To stop the recording at any time, press q or
Ctrl+C in your terminal window.