Installation - tomtom215/mediamtx-rtsp-setup GitHub Wiki

Installation Guide

This guide provides detailed installation instructions for the MediaMTX RTSP Audio Setup across different Linux environments.

Table of Contents

Prerequisites

Before installation, ensure you have:

  • Linux system with root/sudo access
  • USB audio device(s) connected
  • Internet connection
  • Basic terminal knowledge

Required packages:

  • git (for cloning the repository)
  • ffmpeg (installed by the scripts if missing)
  • net-tools or iproute2 (for network configuration)

Debian/Ubuntu/Raspberry Pi OS

These instructions work for Debian-based systems including Ubuntu and Raspberry Pi OS.

1. Install Dependencies

sudo apt update
sudo apt install -y git wget curl

2. Clone the Repository

git clone https://github.com/tomtom215/mediamtx-rtsp-setup.git
cd mediamtx-rtsp-setup

3. Run Installation Scripts

# Install MediaMTX
sudo bash install_mediamtx.sh

# Install Audio RTSP Service
sudo bash setup_audio_rtsp.sh

4. Verify Installation

# Check MediaMTX status
sudo systemctl status mediamtx

# Check Audio RTSP service status
sudo check-audio-rtsp.sh

CentOS/RHEL/Fedora

For RPM-based distributions like CentOS, RHEL, and Fedora.

1. Install Dependencies

# For CentOS/RHEL
sudo yum install -y git wget curl epel-release
sudo yum install -y ffmpeg

# For Fedora
sudo dnf install -y git wget curl
sudo dnf install -y ffmpeg

2. Clone the Repository

git clone https://github.com/tomtom215/mediamtx-rtsp-setup.git
cd mediamtx-rtsp-setup

3. Run Installation Scripts

# Install MediaMTX
sudo bash install_mediamtx.sh

# Install Audio RTSP Service
sudo bash setup_audio_rtsp.sh

4. Verify Installation

# Check MediaMTX status
sudo systemctl status mediamtx

# Check Audio RTSP service status
sudo check-audio-rtsp.sh

Manual Installation

If you prefer to install components manually or need more control over the installation process:

1. Manual MediaMTX Installation

# Create directories
sudo mkdir -p /usr/local/mediamtx /etc/mediamtx /var/log/mediamtx

# Determine architecture
ARCH=$(uname -m)
case "$ARCH" in
    x86_64)  ARCH_NAME="amd64" ;;
    aarch64) ARCH_NAME="arm64v8" ;;
    armv7*)  ARCH_NAME="armv7" ;;
    armv6*)  ARCH_NAME="armv6" ;;
    *)       echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac

# Download MediaMTX
VERSION="v1.12.0"
wget -O /tmp/mediamtx.tar.gz "https://github.com/bluenviron/mediamtx/releases/download/${VERSION}/mediamtx_${VERSION}_linux_${ARCH_NAME}.tar.gz"

# Extract and install
tar -xzf /tmp/mediamtx.tar.gz -C /tmp
sudo cp /tmp/mediamtx*/mediamtx /usr/local/mediamtx/
sudo chmod 755 /usr/local/mediamtx/mediamtx

# Create configuration
sudo tee /etc/mediamtx/mediamtx.yml > /dev/null << EOF
logLevel: info
logDestinations: [stdout, file]
logFile: /var/log/mediamtx/mediamtx.log

rtspAddress: :18554
rtmpAddress: :11935
hlsAddress: :18888
webrtcAddress: :18889

metrics: yes
metricsAddress: :19999

paths:
  all:
EOF

# Create system user
sudo useradd --system --no-create-home --shell /usr/sbin/nologin mediamtx

# Set permissions
sudo chown -R mediamtx: /usr/local/mediamtx /etc/mediamtx /var/log/mediamtx
sudo chmod -R 755 /usr/local/mediamtx
sudo chmod -R 750 /etc/mediamtx /var/log/mediamtx

# Create service file
sudo tee /etc/systemd/system/mediamtx.service > /dev/null << EOF
[Unit]
Description=MediaMTX RTSP/RTMP/HLS/WebRTC streaming server
After=network.target
StartLimitIntervalSec=300
StartLimitBurst=5

[Service]
Type=simple
User=mediamtx
ExecStart=/usr/local/mediamtx/mediamtx /etc/mediamtx/mediamtx.yml
WorkingDirectory=/usr/local/mediamtx
Restart=on-failure
RestartSec=10
StandardOutput=append:/var/log/mediamtx/mediamtx.log
StandardError=append:/var/log/mediamtx/mediamtx.log

[Install]
WantedBy=multi-user.target
EOF

# Start service
sudo systemctl daemon-reload
sudo systemctl enable mediamtx.service
sudo systemctl start mediamtx.service

2. Manual Audio RTSP Service Installation

Follow the installation instructions in the README.md file for setting up the audio RTSP service.

Docker Installation

For those preferring containerized deployment, here's how to run MediaMTX in Docker:

Note: The audio service requires access to host audio devices and runs better outside Docker. This section covers only the MediaMTX component.

1. Pull the MediaMTX Docker image

docker pull bluenviron/mediamtx:1.12.0

2. Create a configuration directory

mkdir -p ~/mediamtx-config

3. Create a configuration file

cat > ~/mediamtx-config/mediamtx.yml << EOF
logLevel: info

# Set custom ports
rtspAddress: :18554
rtmpAddress: :11935
hlsAddress: :18888
webrtcAddress: :18889
metrics: yes
metricsAddress: :19999

# Optional: Enable metrics & Prometheus
metricsAddress: :9998

paths:
  all:
EOF

4. Run the container

docker run --rm -it \
  --name mediamtx \
  -p 18554:18554/tcp \
  -p 18554:18554/udp \
  -p 11935:11935/tcp \
  -p 18888:18888/tcp \
  -p 18889:18889/tcp \
  -p 19999:19999/tcp \
  -v ~/mediamtx-config:/mediamtx \
  bluenviron/mediamtx:1.12.0

5. Run as a service

To run as a service with auto-restart:

docker run -d \
  --name mediamtx \
  --restart unless-stopped \
  -p 18554:18554/tcp \
  -p 18554:18554/udp \
  -p 11935:11935/tcp \
  -p 18888:18888/tcp \
  -p 18889:18889/tcp \
  -p 19999:19999/tcp \
  -v ~/mediamtx-config:/mediamtx \
  bluenviron/mediamtx:1.12.0

6. Set up audio service

Install the audio service on the host following the instructions in the README.md file. Modify the RTSP_PORT in the configuration to match the Docker exposed port.

Verification

After installation, verify that everything is working correctly:

1. Check MediaMTX Service

sudo systemctl status mediamtx

Expected output should show the service as "active (running)".

2. Check RTSP Port

sudo netstat -tuln | grep 18554
# or
sudo ss -tuln | grep 18554

You should see that port 18554 is open and listening.

3. Check Audio RTSP Service

sudo check-audio-rtsp.sh

This should show:

  • The service status
  • Any detected audio devices
  • Active RTSP streams

4. Test a Stream

You can test a stream using ffplay (part of ffmpeg):

# Replace STREAM_NAME with an actual stream name from check-audio-rtsp.sh output
ffplay rtsp://localhost:18554/STREAM_NAME

Or using VLC Media Player:

  1. Open VLC
  2. Click Media > Open Network Stream
  3. Enter the RTSP URL: rtsp://localhost:18554/STREAM_NAME
  4. Click Play

Troubleshooting Failed Verification

If verification fails:

  1. Check if MediaMTX is running:

    sudo systemctl status mediamtx
    
  2. Check if audio devices are detected:

    arecord -l
    
  3. Check audio service logs:

    sudo tail -f /var/log/audio-rtsp/audio-streams.log
    
  4. Restart services:

    sudo systemctl restart mediamtx
    sudo systemctl restart audio-rtsp
    

See the DOCUMENTATION.md file for more detailed troubleshooting steps.