Reliable stream playout on raspberry pi

Everything technical about radio can be discussed here, whether it's transmitting or receiving. Guides, charts, diagrams, etc. are all welcome.
Post Reply
Online
User avatar
jvok
tower block dreamin
tower block dreamin
Posts: 363
Joined: Sun Aug 16, 2020 2:44 pm
Location: Probably up a mast

Reliable stream playout on raspberry pi

Post by jvok » Fri Sep 05, 2025 12:19 pm

Anyone ever use a pi playing out a stream for linking? How did you get it to handle internet drop outs? I've tried both mplayer and vlc and they both just hang if the connection goes out, won't resume when it comes back. If it actually crashed out and returned to console it would be ok cus I could set it playing in a loop. But instead it just sits there doing nothing until I manually restart it

Both vlc and mplayer have --loop as a parameter on command line but it only works if the stream itself ends. If the connection goes down it doesn't see it as the stream ending so just carries on doing nothing

Any ideas?

King Croccy
big in da game.. trust
big in da game.. trust
Posts: 61
Joined: Sat Aug 26, 2023 3:20 pm

Re: Reliable stream playout on raspberry pi

Post by King Croccy » Fri Sep 05, 2025 2:02 pm

You are correct, VLC is not resilient enough to handle network glitches, mine used to just stop dead and you would have to log in manually. Sometimes it would stop after a week, sometimes an hour. It seems to do it on every platform (rasbian, linux mint even on mobile phone). I have seen a few threads on the net where people have told the developer but he seems to be in denial! :lol:

The way I've seen people get round the issue is to use the jack version of stereotool. There is a software called silentjack which is some kind of plugin for jack. It can detect silence and if you write a script, it can be used to refire vlc when it glitches. :tup

It would be nice if there was a plug in for vlc to make things simple but unfortunately I don't think there is any available.

Albert H
proppa neck!
proppa neck!
Posts: 3091
Joined: Tue Apr 05, 2016 1:23 am

Re: Reliable stream playout on raspberry pi

Post by Albert H » Sun Sep 14, 2025 2:33 am

Net drop-outs can be a pain, I wrote a routine for auto-reconnection, and this will normally restore the stream in a couple of seconds. I have a further routine that logs the number of drop-outs, and if they're happening too often, it'll play out a local pre-record for the balance of the hour, then continue with the recordings if a stable connection can't be obtained.

Another trick we've used is to send an hour's programme speeded up so that it gets there in a few seconds. Each programme can be uploaded to the playout Pi, so that programmes can be almost contemporaneous, just an hour or two behind!
"Why is my rig humming?"
"Because it doesn't know the words!"
;)

User avatar
EFR
no manz can test innit
no manz can test innit
Posts: 248
Joined: Mon May 20, 2024 5:39 pm

Re: Reliable stream playout on raspberry pi

Post by EFR » Sun Sep 14, 2025 5:08 pm

Anyone done it with old Android phones? I have sjoebox full of these.
Fight For Free Radio!

Online
User avatar
jvok
tower block dreamin
tower block dreamin
Posts: 363
Joined: Sun Aug 16, 2020 2:44 pm
Location: Probably up a mast

Re: Reliable stream playout on raspberry pi

Post by jvok » Sat Sep 20, 2025 2:58 am

So I took Croccy's suggestion and got Silentjack working on the Pi. The hardest part is installing it because you have to build it from source and there's not much instructions. This is how I did it in case anyone wants to copy.

This is for Raspberry Pi OS 6 (based on Debian 12). I haven't tried older versions but it probably won't work because they use a different sound server.

1. Install the packages you need to build Silentjack. Also install VLC because we'll be using it later.

Code: Select all

sudo apt install autoconf libjack-dev vlc
2. Set some environment variables you'll need to build Silentjack.

Code: Select all

export JACK_CFLAGS="-I/usr/local/include"
export JACK_LIBS="-L/usr/local/lib -ljack -lpthread"
3. Get a copy of Silentjack from Github.

Code: Select all

git clone https://github.com/njh/silentjack.git
4. Build and install Silentjack.

Code: Select all

cd silentjack
./autogen.sh
make
sudo make install
cd ..
5. Copy and paste this script into a text editor and save it as a file ending in .sh e.g. radio.sh

Code: Select all

#!/bin/bash

# Constants
STREAM_URL="https://s2.ssl-stream.com/listen/uk_bass_radio/stream" # Replace with your stream URL
SILENCE_TIME="10" # Max allowed silence time in seconds

# Get full path of current script, so we can relaunch it later
SCRIPT_PATH=$(realpath ${BASH_SOURCE})

# Clean up previous session
# (you can remove the -v option if you don't want the results printed to the console - I find it useful for confirmation)
killall -v silentjack
killall -v vlc
killall -v pw-loopback

# Create a loopback audio device to sit between VLC and the soundcard
# This ensures silentjack will have something to listen to before VLC starts
# The capture-props parameter tells pw-loopback not to connect to any input device - we'll let VLC do this
pw-loopback -n FakeDevice --capture-props='media.class=Audio/Sink' &
sleep 1 # Delay allows pw-loopback to do its thing before starting silentjack, otherwise we get errors

# Set our loopback device as the default output, so VLC will use it automatically
pactl set-default-sink input.FakeDevice

# Launch VLC on dummy interface in case we don't have a GUI running
vlc --intf dummy --loop ${STREAM_URL} &

# Tell silentjack to listen to our loopback device. If it goes silent, it will relaunch our script
# We have to run silentjack through pw-jack to get it to play nice with Pipewire
pw-jack silentjack -c FakeDevice:output_FL -p ${SILENCE_TIME} bash ${SCRIPT_PATH}
6. The script uses the UK Bass Radio webstream as an example. You can change STREAM_URL to point to your stream. Also you might want to change SILENCE_TIME to be longer/shorter (default is 10 seconds). Make sure this is longer than any actual silence you might have in your stream.

7. Launch the script with this command. The "&" symbol at the end detaches the script from the console, so you can close the window/log out of SSH and it will keep running.

Code: Select all

bash ./radio.sh &
I've had this running for almost 2 weeks now and it hasn't missed a beat besides the 10 second drop-outs. Before it wouldn't last a day.

User avatar
EFR
no manz can test innit
no manz can test innit
Posts: 248
Joined: Mon May 20, 2024 5:39 pm

Re: Reliable stream playout on raspberry pi

Post by EFR » Sat Sep 20, 2025 9:04 am

I have one first model Rpi laying around, need to test this.
Fight For Free Radio!

User avatar
radionortheast
proppa neck!
proppa neck!
Posts: 1151
Joined: Wed Sep 09, 2015 1:38 pm

Re: Reliable stream playout on raspberry pi

Post by radionortheast » Mon Sep 22, 2025 8:35 am

there was meant to be this funny character on a raspberry that could help you do coding, think it was a cat called spratz

Gigahertz
tower block dreamin
tower block dreamin
Posts: 275
Joined: Fri May 08, 2015 6:42 pm

Re: Reliable stream playout on raspberry pi

Post by Gigahertz » Sun Oct 05, 2025 10:19 am

Came across this on a USA part 15 radio station forum.

https://experiencefm.com/

"Harness the power of the affordable, widely available Raspberry Pi with our zero-config software — no Linux skills required. Just flash, plug in, and you're streaming. Whether you're linking a studio to a remote site, broadcasting audio for holiday light displays, or DJing live to an internet station, our solution makes professional IP audio streaming simple, reliable, and accessible."

Unknown
who u callin ne guy bruv
who u callin ne guy bruv
Posts: 20
Joined: Wed Jul 23, 2025 3:31 pm

Re: Reliable stream playout on raspberry pi

Post by Unknown » Sun Oct 05, 2025 8:07 pm

Can you run rds on a pi zero with 192khz dac ?

Up_North_Radio
who u callin ne guy bruv
who u callin ne guy bruv
Posts: 27
Joined: Mon Oct 17, 2022 2:14 pm

Re: Reliable stream playout on raspberry pi

Post by Up_North_Radio » Mon Oct 06, 2025 3:48 am

If you have good 5G available and can link to the RPI a good way is with ffmpeg over netcat or socat if you need a way to ensure auto reconnect.

Live audio

Code: Select all

ffmpeg -f alsa -i hw:0 -acodec libmp3lame -b:a 320k -f mp3 - | nc rpi_ip 8000
PulseAudio

Code: Select all

ffmpeg -f pulse -i default -acodec libmp3lame -b:a 320k -f mp3 - | nc rpi_ip 8000
On the RPI (receiving audio):

Code: Select all

nc -l -p 8000 | ffplay -nodisp -
Or to output to audio device:

Code: Select all

nc -l -p 8000 | ffmpeg -i - -f alsa hw:0
One thing about netcat is there is no auto-reconnect if the network drops you can use socat for automated reconnect

Code: Select all

ffmpeg -f pulse -i default -acodec libmp3lame -b:a 320k -f mp3 - | socat - TCP:rpi_ip:8000,retry=10
Using socat (better for 5G - auto-reconnects)

Code: Select all

ffmpeg -f alsa -i hw:1 -acodec libmp3lame -b:a 320k -f mp3 - | socat - TCP:rpi_ip:8000,retry=30,interval=2
Listen and pipe to audio output

Code: Select all

socat TCP-LISTEN:8000,reuseaddr - | aplay -
Or if you need more control over output

Code: Select all

socat TCP-LISTEN:8000,reuseaddr - | ffmpeg -i - -f alsa hw:0
Should be able to do 320kbps with the -b:a 320k option.

If you just want to have some playlist and very light weight then mdp and mpc would be the choice.

Code: Select all

# Install on RPI
sudo apt install mpd mpc

# Copy music to RPI
scp -r /path/to/music/* pi@rpi_ip:/var/lib/mpd/music/

# Update library and play
mpc update
mpc add /
mpc play
Nice opensource project this one. Punching above it's weight I feel :)

https://github.com/jcorporation/myMPD :tup

King Croccy
big in da game.. trust
big in da game.. trust
Posts: 61
Joined: Sat Aug 26, 2023 3:20 pm

Re: Reliable stream playout on raspberry pi

Post by King Croccy » Mon Oct 06, 2025 5:16 pm

Unknown wrote: Sun Oct 05, 2025 8:07 pm Can you run rds on a pi zero with 192khz dac ?
I have seen it done with this but think the zero was running jmpx (rather than stereotool). I don't recommend using jmpx as the only processing seems to be adding a bit of pre-emphasis on. Most of the rigs I've seen running this setup were highly over deviating. You really need stereotool and someone that knows how to set it up properly with a deviation meter :tup

Post Reply