Added flac and mp3 output format.

This commit is contained in:
Johannes Findeisen 2026-10-15 02:31:32 +02:00
commit d1dca0f477
10 changed files with 745 additions and 128 deletions

View file

@ -1,13 +1,14 @@
# tuxrecord2
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.
`tuxrecord2` is the **Rust** port of `tuxrecord`, the Linux port of the former
macOS-only **macrecord** tool. The original port was written in C99; this rewrite
keeps the same command-line interface and behaviour but is implemented in Rust
on top of the safe [alsa](https://crates.io/crates/alsa) bindings and a small
amount of `libc` for terminal, polling and signal handling. It builds with
**Cargo**.
amount of `libc` for terminal, polling and signal handling. FLAC and MP3 output
is encoded in real time through small FFI shims over the system `libFLAC` and
`libmp3lame` libraries. It builds with **Cargo**.
macrecord was created by my good friend Armin. You can find his code here:
[https://codeberg.org/armin/macrecord](https://codeberg.org/armin/macrecord)
@ -17,6 +18,12 @@ macrecord was created by my good friend Armin. You can find his code here:
- ALSA development headers and `pkg-config`
(`libasound2-dev` on Debian/Ubuntu, `alsa-lib-devel` on Fedora,
`alsa-lib` on Arch)
- FLAC and LAME (MP3) development headers and `pkg-config`, used for the
bundled 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.
## Usage
@ -36,6 +43,10 @@ tuxrecord2 -p myrec
# Use a specific ALSA capture device
tuxrecord2 -D hw:1,0
# Encode to FLAC (lossless) or MP3 (lossy) in real time
tuxrecord2 -f flac
tuxrecord2 --format mp3
# Record from PipeWire (the PipeWire sound server)
tuxrecord2 -D pipewire
```
@ -48,6 +59,7 @@ tuxrecord2 -D pipewire
| `-d <secs>` | Stop automatically after `<secs>` seconds |
| `-p <prefix>` | Filename prefix instead of `tuxrecord2` |
| `-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
@ -59,9 +71,26 @@ 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
`tuxrecord2`). 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 `tuxrecord2`). 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.
- **wav** (default) — uncompressed 16-bit little-endian PCM in a RIFF/WAVE
container.
- **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
@ -132,9 +161,9 @@ tuxrecord2 -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