Configuration
Customize audio quality, device settings, environment variables, and MediaMTX integration.
Audio Device Configuration
Device-specific audio settings live in /etc/mediamtx/audio-devices.conf.
This file uses a simple KEY=VALUE format (bash environment variables) that
the stream manager reads at startup.
Auto-Generate Configuration (Recommended)
The lyrebird-mic-check.sh script detects your hardware capabilities and writes an optimal configuration:
# Generate with normal quality (recommended default)
sudo ./lyrebird-mic-check.sh -g
# Generate with high quality (more bandwidth)
sudo ./lyrebird-mic-check.sh -g --quality=high
# Generate with low quality (speech / bandwidth-constrained)
sudo ./lyrebird-mic-check.sh -g --quality=low
# Preview what would be generated without writing (dry-run)
./lyrebird-mic-check.sh -g --dry-run
Manual Configuration Format
Settings use a DEVICE_<NAME>_<PARAMETER>=value pattern. Device names are sanitized
(special characters → underscores, uppercased).
# /etc/mediamtx/audio-devices.conf
# ── Device-specific settings (by friendly name) ──────────────────
DEVICE_USB_MICROPHONE_SAMPLE_RATE=48000
DEVICE_USB_MICROPHONE_CHANNELS=2
DEVICE_USB_MICROPHONE_BITRATE=192k
DEVICE_USB_MICROPHONE_CODEC=opus
# ── Device-specific settings (by full device ID, guaranteed unique) ──
DEVICE_USB_MANUFACTURER_MODEL_SERIAL_00000000_SAMPLE_RATE=48000
DEVICE_USB_MANUFACTURER_MODEL_SERIAL_00000000_CHANNELS=2
DEVICE_USB_MANUFACTURER_MODEL_SERIAL_00000000_BITRATE=128k
# ── Fallback defaults ─────────────────────────────────────────────
DEFAULT_SAMPLE_RATE=48000
DEFAULT_CHANNELS=2
DEFAULT_BITRATE=128k
DEFAULT_CODEC=opus
DEFAULT_THREAD_QUEUE=8192
The stream manager tries settings in this order: (1) friendly name config, (2) full device ID config, (3) defaults. This lets you set one value for a device regardless of which USB port it's plugged into.
Available Parameters
| Parameter | Values | Default | Description |
|---|---|---|---|
SAMPLE_RATE | 16000, 44100, 48000, 96000 | 48000 | Audio sample rate in Hz |
CHANNELS | 1 (mono), 2 (stereo) | 2 | Number of audio channels |
BITRATE | 64k, 96k, 128k, 192k, 256k | 128k | Encoder bitrate |
CODEC | opus, aac, mp3, pcm | opus | Audio codec |
THREAD_QUEUE | Integer (power of 2) | 8192 | FFmpeg thread queue size (buffer) |
ANALYZEDURATION | Integer (microseconds) | 5000000 | FFmpeg input analysis duration |
PROBESIZE | Integer (bytes) | 5000000 | FFmpeg input probe size |
Validate Configuration
# Check configuration against detected hardware capabilities
sudo ./lyrebird-mic-check.sh -V
# Also validates MediaMTX config
/usr/local/bin/mediamtx --check /etc/mediamtx/mediamtx.yml
Configuration Files
| File | Format | Purpose |
|---|---|---|
/etc/mediamtx/mediamtx.yml |
YAML | MediaMTX main configuration (ports, protocols, auth) |
/etc/mediamtx/audio-devices.conf |
Bash env vars | Per-device audio codec and quality settings |
/etc/udev/rules.d/99-usb-soundcards.rules |
udev | USB device persistence rules (persistent symlinks) |
/etc/systemd/system/mediamtx.service |
systemd unit | MediaMTX server service definition |
/etc/systemd/system/mediamtx-audio.service |
systemd unit | Stream manager service with watchdog support |
/etc/lyrebird/alerts.conf |
Bash env vars | Webhook alert configuration |
Runtime State Files
| Path | Purpose |
|---|---|
/run/mediamtx-audio.pid | Stream manager PID |
/run/mediamtx-audio.lock | Concurrency lock file |
/var/lib/mediamtx-ffmpeg/ | Per-device FFmpeg PID files and wrapper scripts |
/var/log/mediamtx.out | MediaMTX output log |
/var/log/lyrebird-stream-manager.log | Stream manager log |
/var/log/lyrebird/ | Per-device FFmpeg logs |
/var/log/lyrebird-orchestrator.log | Orchestrator log |
/var/log/lyrebird-diagnostics.log | Diagnostics output |
Environment Variables
All configuration can be overridden via environment variables. This is useful for custom deployments, Docker-adjacent setups, or testing alternative values.
Stream Manager
# MediaMTX paths
MEDIAMTX_BINARY="/usr/local/bin/mediamtx"
MEDIAMTX_CONFIG_DIR="/etc/mediamtx"
MEDIAMTX_CONFIG_FILE="/etc/mediamtx/mediamtx.yml"
MEDIAMTX_DEVICE_CONFIG="/etc/mediamtx/audio-devices.conf"
MEDIAMTX_LOG_FILE="/var/log/mediamtx.out"
MEDIAMTX_HOST="localhost"
MEDIAMTX_API_PORT="9997"
# Process management
MEDIAMTX_PID_FILE="/run/mediamtx-audio.pid"
MEDIAMTX_LOCK_FILE="/run/mediamtx-audio.lock"
MEDIAMTX_FFMPEG_DIR="/var/lib/mediamtx-ffmpeg"
# Timing
STREAM_STARTUP_DELAY=10 # Seconds before starting streams
USB_STABILIZATION_DELAY=5 # Seconds to wait after USB events
RESTART_STABILIZATION_DELAY=15 # Seconds between restart attempts
# Recovery
MAX_WRAPPER_RESTARTS=50 # Max auto-restarts before giving up
WRAPPER_SUCCESS_DURATION=300 # Seconds to count as "successful run"
MAX_CONSECUTIVE_FAILURES=5 # Max failures before escalation
INITIAL_RESTART_DELAY=10 # Starting exponential backoff (seconds)
MAX_RESTART_DELAY=300 # Maximum backoff delay (5 minutes)
# Resource thresholds
MAX_FD_WARNING=500 # File descriptor warning level
MAX_FD_CRITICAL=1000 # File descriptor critical level
MAX_CPU_WARNING=20 # CPU % warning per stream
MAX_CPU_CRITICAL=40 # CPU % critical per stream
# Audio defaults (when not in config file)
DEFAULT_SAMPLE_RATE=48000
DEFAULT_CHANNELS=2
DEFAULT_CODEC=opus
DEFAULT_BITRATE=128k
DEFAULT_THREAD_QUEUE=8192
# Debugging
DEBUG=1 # Enable verbose output
Usage Examples
# Use custom log location
FFMPEG_LOG_DIR=/mnt/storage/logs sudo ./lyrebird-stream-manager.sh start
# Increase startup delay for slow USB hubs
STREAM_STARTUP_DELAY=20 sudo ./lyrebird-stream-manager.sh start
# Enable debug output
export DEBUG=1
sudo ./lyrebird-stream-manager.sh start
# Install MediaMTX to a custom prefix
MEDIAMTX_PREFIX=/opt/mediamtx sudo ./install_mediamtx.sh install
MediaMTX Integration
MediaMTX serves RTSP, WebRTC, HLS, and RTMP. LyreBirdAudio configures and manages the MediaMTX
process. The main configuration is at /etc/mediamtx/mediamtx.yml.
Default Port Assignments
| Protocol | Default Port | Purpose |
|---|---|---|
| RTSP | 8554 | Stream consumption (VLC, FFplay, etc.) |
| HTTP API | 9997 | REST API for stream management |
| WebRTC | 8889 | Browser-based streaming |
| RTP / RTCP | 8000–8001 | Media transport |
Management Modes
| Mode | Best For | How to Use |
|---|---|---|
| Stream Manager (default) | Audio streaming with automatic recovery | ./lyrebird-stream-manager.sh start |
| Systemd Direct | General MediaMTX usage without audio scripts | systemctl start mediamtx |
| Manual | Development / debugging | /usr/local/bin/mediamtx /etc/mediamtx/mediamtx.yml |
MediaMTX API
The REST API (port 9997) is available for programmatic stream management:
# List all active paths/streams
curl http://localhost:9997/v3/paths/list
# Get info for a specific stream
curl http://localhost:9997/v3/paths/get/Device_1
# Check MediaMTX health
curl http://localhost:9997/v3/config/global/get
Quality Tiers
The capability checker provides three quality presets. Choose based on your use case:
| Tier | Sample Rate | Bitrate | Best For |
|---|---|---|---|
| low | 16,000 Hz | 64 kbps | Speech, monitoring, bandwidth-constrained |
| normal | 48,000 Hz | 128 kbps | General purpose, balanced (default) |
| high | 48,000 Hz+ | 256 kbps+ | Music, high-quality recording |
Codec Comparison
| Codec | Quality/Bitrate | Compatibility | Latency |
|---|---|---|---|
| Opus | Best (recommended) | Modern clients, VLC, FFplay | Very low |
| AAC | Good | Widest (iOS, browsers) | Moderate |
| PCM | Lossless | All FFmpeg-capable clients | Lowest |
| MP3 | Good | Universal | Moderate |
High-Quality Example
# High quality music streaming
DEVICE_STUDIO_MIC_SAMPLE_RATE=96000
DEVICE_STUDIO_MIC_CHANNELS=2
DEVICE_STUDIO_MIC_BITRATE=256k
DEVICE_STUDIO_MIC_CODEC=opus
Low-Bandwidth Speech Example
# Speech/monitoring (bandwidth-constrained)
DEVICE_FIELD_MIC_SAMPLE_RATE=16000
DEVICE_FIELD_MIC_CHANNELS=1
DEVICE_FIELD_MIC_BITRATE=64k
DEVICE_FIELD_MIC_CODEC=opus