How to Use FFmpeg PulseAudio Input on Linux
This article explains how to use the -f pulse option in
FFmpeg to record and capture audio on Linux systems running the
PulseAudio sound server. You will learn how to identify your system’s
audio input sources, write the correct FFmpeg commands for basic audio
recording, capture desktop system sounds, and combine audio with video
screen grabs.
Understanding the
-f pulse Option
The -f pulse flag tells FFmpeg to use the PulseAudio
demuxer, enabling it to grab audio directly from your Linux system’s
PulseAudio server. This is highly useful for recording microphones,
line-in inputs, or the system’s internal output (desktop audio).
Step 1: Find Your PulseAudio Device Name
Before recording, you need to identify the exact name of the audio source you want to capture. Run the following command in your terminal:
pactl list sources shortThis will output a list of available audio sources. Look for the name of your desired device in the second column. It will look similar to this:
- For a microphone:
alsa_input.pci-0000_00_1f.3.analog-stereo - For desktop audio (what you hear):
alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
If you want to use whatever device is currently set as your system
default, you can simply use the alias default.
Step 2: Record Audio from a Microphone
To record audio from your default system microphone and save it as an MP3 file, use the following command:
ffmpeg -f pulse -i default output.mp3To use a specific microphone identified in Step 1, replace
default with the device name:
ffmpeg -f pulse -i alsa_input.pci-0000_00_1f.3.analog-stereo output.wavStep 3: Record Desktop Audio (System Sounds)
To record the audio playing through your speakers or headphones (such as a browser tab, game, or video), you must capture the “monitor” of your output device.
Identify your output monitor name using the pactl
command from Step 1, then pass it to the -i option:
ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor output.mp3Step 4: Record Video with PulseAudio
A common use case is capturing desktop video using
x11grab while simultaneously recording desktop or
microphone audio using -f pulse.
The following command records the screen at 1920x1080 resolution along with the default PulseAudio input:
ffmpeg -f x11grab -video_size 1920x1080 -i :0.0 -f pulse -i default output.mp4Adjusting Recording Quality
You can customize the audio channels, sample rate, and codec of your recording by adding additional flags:
-ac: Sets the number of audio channels (e.g.,-ac 2for stereo,-ac 1for mono).-ar: Sets the audio sampling rate (e.g.,-ar 44100for CD-quality audio).-c:a: Specifies the audio codec (e.g.,-c:a libmp3lameor-c:a flac).
Example of a high-quality stereo recording:
ffmpeg -f pulse -ac 2 -ar 48000 -i default -c:a flac output.flac