Streaming Audio Over a Network

Streaming Audio Over a Network on Linux

For a bit of background, I wanted to stream the audio received from the line-in port of my server (old PC + record player/radio) to any device on my local network.

All of the guides/posts I found were out of date, not directly applicable (PipeWire instead of PulseAudio on Ubuntu) or just seemed overly complex (PipeWire/PulseAudio + Roc/jack/airplay/initscripts/etc) for what I know to be a simple task as I have previously done a similar thing with tsduck + ffmpeg.

After trying to do it the "correct" way, I just fell back to what I knew.

Server Configuration

Hardware

Firstly, either with alsamixer or some GUI, setup the default input device and make sure the levels are set so that audio isn't clipping.

Software

To stream, arecord and ffmpeg must be present.
To test that the input-device is correctly setup:

arecord -f dat | aplay
If you hear nothing and you know that there is audio, you'll have to figure out what's going on before continuing.

To stream the audio the simplest way is:

arecord -f dat | ffmpeg -i - -c:a libmp3lame -f rtp rtp://224.0.0.10:1900
You should see something like this:

This is taking stereo, PCM S16LE, 48000KHz audio (muxed into a wav file format) recording, piping it to ffmpeg, converting to mp3 (128kbps by default) and multicasting to the local network via rtp.
If you want to stream in a different format/bitrate/etc, refer to the ffmpeg help, but you will likely have to configure an sdp file for other codecs.
The actual command I am using is:

arecord -f dat | ffmpeg -hide_banner -i - -c:a libmp3lame -b:a 192k -cutoff 20000 -ac 2 -ar 48000 -f rtp rtp://224.0.0.10:1900

Client

Playing the rtp stream is a simple affair. There are possibly a near infinite ways to play an rtp stream, these are 2:

ffplay

ffplay is bundled with the ffmpeg package.

VLC

Go to "Media->Open Network Stream...", then to the "Network" tab and enter the multicast address:port. Or via the command line

(c)vlc rtp://224.0.0.10:1900

In the android app, add a new stream with the address:port.

Notes

If you're trying to save a bit on bandwidth, using the udp format in ffmpeg can help, although vlc can be tricky playing the resultant stream.

There is a bit of lag that can vary between clients. This may be important to you if you plan to have multiple devices playing the stream at the same time.