How to Record Audio with `ffmpeg` on Arch Linux
ffmpeg on Arch LinuxCategories:
4 minute read
Recording audio on Arch Linux using ffmpeg is a powerful and flexible solution for many use cases — from simple voice recordings and podcasts to complex multi-source audio captures. While ffmpeg is primarily known as a video processing tool, its capabilities extend well into audio recording and manipulation.
This article provides a comprehensive guide on how to record audio using ffmpeg on Arch Linux. Whether you’re capturing sound from your microphone, mixing audio sources, or encoding the output in different formats, this guide has you covered.
Why Use ffmpeg for Audio Recording?
There are several reasons why ffmpeg is a great choice for audio recording:
- Flexibility: Record from any input source (microphone, desktop audio, USB audio interface).
- Format Support: Encode audio in MP3, FLAC, AAC, WAV, and more.
- Scriptable: Ideal for automation and batch processing.
- Lightweight: No need for bulky GUIs or additional software.
- Powerful Filters: Apply audio filters and effects on the fly.
Prerequisites
Before you start recording, ensure your system meets the following prerequisites:
- Arch Linux (or an Arch-based distro like Manjaro or EndeavourOS).
ffmpeginstalled.- Optional: PulseAudio, PipeWire, or ALSA for audio management.
To install ffmpeg:
sudo pacman -S ffmpeg
Understanding Audio Devices in Linux
On Linux, audio devices are typically managed through ALSA, PulseAudio, or PipeWire.
- ALSA (Advanced Linux Sound Architecture) is the core audio subsystem.
- PulseAudio and PipeWire are sound servers that sit on top of ALSA, providing features like per-app volume control, network streaming, and virtual devices.
For most desktop users, either PulseAudio or PipeWire will be in use.
Listing Available Audio Devices
You can list audio devices with the following commands depending on your audio system:
ALSA
arecord -l
This will list hardware capture devices.
PulseAudio
pactl list sources short
You’ll see output like:
1 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
Note the source name for use with ffmpeg.
Basic Audio Recording from Microphone
To record audio using ALSA (directly), run:
ffmpeg -f alsa -i default output.wav
Here:
-f alsa: Specifies ALSA input.-i default: Uses the default capture device.output.wav: Saves the recording as a WAV file.
To record from a specific device (e.g., card 1, device 0):
ffmpeg -f alsa -i hw:1,0 output.wav
Advanced Examples
Recording with PulseAudio
PulseAudio provides more control over input sources.
List sources:
pactl list sources short
Use a specific source with:
ffmpeg -f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo output.wav
Or to use the default source:
ffmpeg -f pulse -i default output.wav
You can also set the sample rate and format:
ffmpeg -f pulse -ar 44100 -ac 2 -i default output.wav
Recording System Audio (What You Hear)
To record the output stream (what’s playing on your system), use the monitor source:
pactl list sources short | grep monitor
Then record with:
ffmpeg -f pulse -i <monitor-source-name> output.wav
For example:
ffmpeg -f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor output.wav
Mixing Microphone and System Audio
You can mix multiple inputs using ffmpeg’s amerge filter.
Example:
ffmpeg \
-f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo \
-f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
-filter_complex "[0:a][1:a]amerge=inputs=2[aout]" \
-map "[aout]" -ac 2 output.wav
This mixes mic and system audio into a stereo file.
Choosing Audio Codecs and Formats
ffmpeg supports various formats and codecs:
| Format | Codec | Example Output |
|---|---|---|
| WAV | PCM | output.wav |
| MP3 | libmp3lame | output.mp3 |
| AAC | aac | output.aac |
| FLAC | flac | output.flac |
| OGG | vorbis | output.ogg |
Specify codec using -c:a. Example:
ffmpeg -f pulse -i default -c:a libmp3lame -b:a 192k output.mp3
This encodes audio as 192 kbps MP3.
Tips for Better Audio Quality
- Use a good microphone – Avoid noisy or low-quality built-in mics.
- Choose proper sample rate – Use 44100 Hz or 48000 Hz for best compatibility.
- Control background noise – Record in a quiet environment.
- Monitor audio levels – Use tools like
pavucontrolto ensure levels are not too low or clipping. - Use filters if needed – Normalize, reduce noise, or compress audio.
For normalization:
ffmpeg -i input.wav -filter:a loudnorm output.wav
Troubleshooting
ffmpeg Cannot Detect Audio Device
Ensure the correct backend is used:
- For ALSA: use
-f alsa - For PulseAudio: use
-f pulse
Input Device Is Silent
- Check mic input level in
pavucontroloralsamixer. - Ensure the device is not muted.
- Try switching to another source.
Device busy Error
- Close other applications that might be using the mic.
- Use a virtual sink or loopback device.
PipeWire Users
If you’re using PipeWire, it emulates PulseAudio, so PulseAudio commands still work.
To verify:
pactl info
Look for Server Name: PulseAudio (on PipeWire...).
Conclusion
Recording audio with ffmpeg on Arch Linux is both powerful and efficient, providing users with total control over their audio sources and output. Whether you’re capturing a podcast, streaming, or just doing basic audio logging, ffmpeg offers a suite of options that are hard to beat.
Thanks to Arch Linux’s modular design and access to the latest packages, you can mix and match tools like ffmpeg, PulseAudio, PipeWire, and ALSA to suit your exact needs.
Remember, with great power comes a bit of a learning curve, but once you’re familiar with the command-line syntax and audio routing concepts, ffmpeg becomes an indispensable tool in your Linux toolkit.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.