Added flac and mp3 output format.

This commit is contained in:
Johannes Findeisen 2026-10-15 02:49:31 +02:00
commit 3ff9ea07f5
4 changed files with 481 additions and 46 deletions

View file

@ -1,10 +1,13 @@
# tuxrecord
Record audio to a WAV file on **Linux** using **ALSA** as the recording source.
Record audio to WAV, FLAC or MP3 files on **Linux** using **ALSA** as the
recording source.
`tuxrecord` is the Linux port of the former macOS-only **macrecord** tool. The
Swift/AVFoundation code was rewritten in **C99** and now uses the native ALSA
capture API (`libasound`); it builds with **GCC**.
capture API (`libasound`); it builds with **GCC**. WAV output is written
directly, while FLAC and MP3 are encoded in real time through the system
`libFLAC` and `libmp3lame` libraries, so no intermediate WAV file is written.
macrecord was created by my good friend Armin. You can find his code here:
[https://codeberg.org/armin/macrecord](https://codeberg.org/armin/macrecord)
@ -13,6 +16,11 @@ macrecord was created by my good friend Armin. You can find his code here:
- GCC and GNU make
- ALSA development headers (`libasound2-dev` on Debian/Ubuntu,
`alsa-lib-devel` on Fedora, `alsa-lib` on Arch)
- FLAC and LAME (MP3) development headers, used for the real-time encoders
(`libflac-dev` and `libmp3lame-dev` on Debian/Ubuntu, `flac-devel` and
`lame-devel` on Fedora, `flac` and `lame` on Arch). They are only needed to
build; at run time the shared `libFLAC` / `libmp3lame` libraries are used.
- `pkg-config` (used to locate ALSA, FLAC and LAME)
## Usage
@ -32,6 +40,10 @@ tuxrecord -p myrec
# Use a specific ALSA capture device
tuxrecord -D hw:1,0
# Encode to FLAC (lossless) or MP3 (lossy) in real time
tuxrecord -f flac
tuxrecord --format mp3
# Record from PipeWire (the PipeWire sound server)
tuxrecord -D pipewire
```
@ -44,6 +56,7 @@ tuxrecord -D pipewire
| `-d <secs>` | Stop automatically after `<secs>` seconds |
| `-p <prefix>` | Filename prefix instead of `tuxrecord` |
| `-D <device>` | ALSA capture device (default: `default`; `pipewire` on PipeWire systems) |
| `-f, --format <fmt>` | Output format: `wav`, `flac` or `mp3` (default: `wav`) |
| `-h, --help` | Show help |
Run `arecord -l` to list available ALSA capture devices. On systems with
@ -55,9 +68,27 @@ or `wpctl status` (see "Recording from PipeWire" below).
- **q** - Stop recording and save the file
- **Ctrl+C** - Stop recording and save the file
The file is written as `<prefix>__<timestamp>.wav` (default prefix
`tuxrecord`). The VU meter shows the input level of the left and right channels
in real time when stderr is a terminal.
The file is written as `<prefix>__<timestamp>.<ext>` where `<ext>` is `wav`,
`flac` or `mp3` depending on `-f/--format` (default prefix `tuxrecord`, default
format `wav`). The VU meter shows the input level of the left and right
channels in real time when stderr is a terminal.
## Output formats
Audio is captured once and handed to the selected encoder as it arrives, so
FLAC and MP3 are produced **in real time** — no intermediate WAV file is
written and no second conversion pass runs afterwards. A small reusable buffer
converts the captured 16-bit samples to the layout the encoder expects.
- **wav** (default) — uncompressed 16-bit little-endian PCM in a RIFF/WAVE
container, written directly by tuxrecord.
- **flac** — lossless compression via libFLAC (streaming, default
compression level 5).
- **mp3** — lossy compression via LAME at a constant 192 kbit/s, quality 2.
`wav` and `flac` preserve the captured stream exactly; `mp3` is lossy. The
classic 4 GiB RIFF limit applies to `wav` only (the program stops cleanly
before exceeding it); `flac` and `mp3` have no such limit.
## Recording system audio
@ -128,9 +159,9 @@ tuxrecord -D pipewire
```
The `.monitor` source carries exactly what the sink is playing, so anything
your players output ends up in the WAV file. Every capture follows the same
`<prefix>__<timestamp>.wav` naming and can be stopped with `q` or **Ctrl+C**.
The default setting can be restored later with
your players output ends up in the recorded file. Every capture follows the
same `<prefix>__<timestamp>.<ext>` naming and can be stopped with `q` or
**Ctrl+C**. The default setting can be restored later with
`pactl set-default-source <your-input-source>`.
### Troubleshooting
@ -150,7 +181,8 @@ The default setting can be restored later with
```bash
make
# or directly:
# gcc -std=c99 -O2 -Wall -Wextra tuxrecord.c -o tuxrecord $(pkg-config --libs alsa) -lm
# gcc -std=c99 -O2 -Wall -Wextra tuxrecord.c -o tuxrecord \
# $(pkg-config --cflags --libs alsa flac lame) -lm
```
Install (installs to `$(PREFIX)/bin`, default `/usr/local/bin`):