Audio over IP (AoIP) is the distribution of digital audio across an IP network, local or even the Internet. Many proprietary systems came into existence for transporting high-quality audio over IP based on Transmission Control Protocol (TCP), User Datagram Protocol (UDP) or Real-time Transport Protocol (RTP). Even European Broadcasting Union (EBU) published an interoperable standard for audio over IP using RTP the N/ACIP or Tech3326. In this post we will use MediaMTX Server in combination with FFMPEG to stream an audio input channel over network.
How it works
Simply connect your audio source—whether it’s a mixer, microphone, or music player—to your Raspberry Pi’s USB audio card using a standard 3.5mm jack (AUX IN or Mic IN). Then, tune in from any device on the same network by visiting http://[device_ip]:8889/stream01/ and your broadcast will be live in seconds!
No complicated setup needed—just plug in the audio source, power on, and the stream starts automatically using Audio over IP. With low latency (3 seconds), you’ll enjoy near real-time audio, perfect for live announcements, radio streaming, or whole-house audio. Set it up once, and it just works!
Bill of Materials
- Raspberry PI (any Raspberry PI after model 2B should be suitable and sufficient), version 5 is preffered because of the on board Power-off button, otherwise Network tap‘s implementation of power button could be used.
- Micro SD Card and Power Supply (as per documentation)
- Raspberry Pi Bumper
- USB Audio Card, I used a generic one from Ali Express with a single channel AUX in but any USB Card should be suitable.
- 3.5mm audio jack extension cord or adapter for your specific input.
Operating System – Versions
Raspberry PI Imager v.1.8.5
Raspberry PI OS Lite (64bit)
Release: 13/05/2025
Preparation
1) Using the official Raspberry PI Imager tool, prepare a new microSD Card with Raspberry PI OS Lite (64bit). I used the following settings but feel free to change them at will.
2) Place your microSD card back into the Raspberry PI and plug the power cable.
3) Establish a terminal connection to your Raspberry using SSH.
4) After establishing the connection and logging in, update your repositories and distribution using the commands :
sudo apt update
sudo apt upgrade -y
5) Make a new directory for the MediaMTX Server and set the owner to the current user:
sudo mkdir /opt/mediamtx
sudo chown $USER:$USER /opt/mediamtx
cd /opt/mediamtx
6) From the official MediaMTX repository download the latest Linux ARM version (ending in linux_arm64.tar.gz). Latest version as of writing is 1.12.3 released on 27th of May. Use the following command to download it to your raspberry:
wget https://github.com/bluenviron/mediamtx/releases/download/v1.12.3/mediamtx_v1.12.3_linux_arm64.tar.gz
7) Extract the contents of the archive:
tar -xzf mediamtx_v1.12.3_linux_arm64.tar.gz
8) Edit mediamtx.yml
configuration file:
sudo nano /opt/mediamtx/mediamtx.yml
9) and append the path for the specific stream, below paths:
(use Ctrl + W to search for the term) :
stream01:
source: publisher
Warning configuration file is in yml format, whitespace matters!! Don’t add or remove any extra spaces. Your configuration should look like the following screenshot.
10) Run mediamtx to verify it’s functionality:
./mediamtx
11) Leave the mediamtx server running and open a new SSH connection to your Raspberry.
12) Install ffmpeg using the command:
sudo apt install -y ffmpeg
Device Configuration
First of all plug your USB Audio Card to Raspberry PI and verify that is working and is recognized by Raspberry PI OS by running:
lsusb
To list all all PCMs (Pulse-code modulation, hardware and virtual audio recording devices) that can be used for capturing sound use the command (notice that L is upper case):
arecord -L
As you can see hw:CARD=Device,DEV=0 is the plugged USB device. From now on we will refer to the Audio Device as hw:Device,0
. To view all available specs and parameters for this device, simply run:
arecord -D hw:Device,0 --dump-hw-params
The command reveals detailed audio specs—including Format, Sample Bits, Input Channels, Bit Rate, and more—as shown in the screenshot below.
Streaming Audio to MediaMTX
We will use the arecord
binary to capture audio input, transfer it to FFMPEG for re-encoding using the Opus Codec, and finally forward it using the RTSP protocol to Media MTX. This can all be accomplished with the following command:
arecord -D hw:Device,0 -f S16_LE -r 48000 -c 1 | \
ffmpeg -re -f s16le -ar 48000 -ac 1 -i - -acodec libopus \
-b:a 64k -application lowdelay \
-f rtsp rtsp://127.0.0.1:8554/stream01
All parameters of the arecord
command correspond to the audio card’s specifications. You should replace them with your card’s specifications. The same applies to the corresponding parameters in FFMPEG.
arecord Parameter | Specification | Value | FFMPEG parameter |
---|---|---|---|
-f | FORMAT | S16_LE | -f |
-r | RATE | 48000 | -ar |
-c | CHANNELS | 1 | -ac |
Navigate to http://[device_ip]:8889/stream01/ using your preferred browser. You should then be able to listen to your stream—just make sure it’s not muted.
Now that everything works, it’s time to stop both FFMPEG and MediaMTX (use {ctrl}
+{c}
) and automate the procedure.
Configure MediaMTX and FFMPEG to start on boot
Now, we should configure MediaMTX to start on boot.
1) First Create a new service file:
sudo nano /etc/systemd/system/mediamtx.service
2) and append the following content:
[Unit]
Description=MediaMTX WebRTC Server
After=network.target
[Service]
ExecStart=/opt/mediamtx/mediamtx /opt/mediamtx/mediamtx.yml
Restart=always
[Install]
WantedBy=multi-user.target
3) Finally, enable and start the service:
sudo systemctl enable mediamtx
sudo systemctl start mediamtx
4) Next, create the FFmpeg Streaming Service for the specific stream
sudo nano /etc/systemd/system/stream01.service
5) append the following content (you should modify DEVICE, and STREAM variables as well as the parameters of arecord and ffmpeg as before):
[Unit]
Description=FFmpeg Audio Streaming
After=network.target sound.target mediamtx.service
Wants=mediamtx.service
Requires=network.target sound.target
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
Environment="DEVICE=hw:Device,0"
Environment="STREAM=stream01"
Environment="STREAM_URL=rtsp://127.0.0.1:8554/"
ExecStart=/bin/bash -c "/usr/bin/arecord -D $DEVICE -f S16_LE -r 48000 -c 1 | /usr/bin/ffmpeg -re -f s16le -ar 48000 -ac 1 -i - -acodec libopus -b:a 64k -application lowdelay -flags low_delay -vn -f rtsp $STREAM_URL$STREAM"
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
6) Next, enable and start the service:
sudo systemctl enable stream01
sudo systemctl enable stream01
7) Verify that MediaMTX service is active:
sudo systemctl status mediamtx
8) Verify that stream01 service is active:
sudo systemctl status stream01
9) Congratulations, your device is ready, everything will automatically start once the device boot.
Adding more streams
You can add as many streams as you want by:
1) Adding a new audio source to your Raspberry.
2) Adding the new path in /opt/mediamtx/mediamtx.yml
below paths:
:
stream02:
source: publisher
3) Copying the stream01.service
file and adding a new service :
sudo cp /etc/systemd/system/stream01.service /etc/systemd/system/stream02.service
4) Editing the new stream02.service
and modifying DEVICE and STREAM variables
Environment="DEVICE=hw:Device,0"
Environment="STREAM=stream02"
5) Reloading the service daemon configuration
sudo systemctl daemon-reload
6) Restarting the mediamtx.service
sudo systemctl restart mediamtx.service
7) Enabling and starting the new service
sudo systemctl enable stream02
sudo systemctl start stream02
8) Listen to your new stream by navigating to http://[device_ip]:8889/stream02/