A complete guide for setting up an RTSP stream viewer in kiosk mode on Raspberry Pi.
- Fullscreen RTSP stream display
- Automatic recovery from disconnections
- Error message display when camera is unreachable
- Kiosk mode for dedicated display
- SSH accessible for management
- Continuous operation without desktop interference
- Raspberry Pi with Raspberry Pi OS (with desktop)
- Connected display
- Network connection
- RTSP camera stream available
# Update package list
sudo apt-get update
# Install required packages
sudo apt-get install ffmpeg unclutter x11-xserver-utils
sudo nano /usr/local/bin/start-stream.sh
Add this content:
# Set display
export DISPLAY=:0
export XAUTHORITY=/home/naman/.Xauthority
# Disable screen blanking and mouse
xset s off
xset s noblank
xset -dpms
unclutter -idle 0 -root &
# Function to display error message using ffplay
show_error_message() {
export SDL_VIDEODRIVER=x11
# Start error message without time limit
ffplay -fs -noborder -alwaysontop -x 1920 -y 1080 -f lavfi -i "color=c=black:s=1920x1080,drawtext=text='Cannot connect to camera... Retrying':fontcolor=white:fontsize=64:x=(w-text_w)/2:y=(h-text_h)/2" &
ERROR_PID=$!
while true; do
if ping -c 1 192.168.68.100 &> /dev/null; then
kill $ERROR_PID 2>/dev/null
return 0
fi
sleep 1
done
kill $ERROR_PID 2>/dev/null
return 1
}
# Function to try connecting to camera
try_stream() {
export SDL_VIDEODRIVER=x11
ffplay -fs -noborder -alwaysontop -x 1920 -y 1080 -fflags nobuffer -flags low_delay -framedrop -rtsp_transport tcp -probesize 32 -analyzeduration 0 -buffer_size 16384 rtsp://aayushi:[email protected]:554/stream2 &
STREAM_PID=$!
while kill -0 $STREAM_PID 2>/dev/null; do
if ! ping -c 1 192.168.68.100 &> /dev/null; then
kill $STREAM_PID 2>/dev/null
return 1
fi
sleep 1
done
return 1
}
# Main loop
while true; do
if ping -c 1 192.168.68.100 &> /dev/null; then
try_stream
if [ $? -ne 0 ]; then
show_error_message
fi
else
show_error_message
fi
sleep 1
done
Make it executable:
sudo chmod +x /usr/local/bin/start-stream.sh
Create autostart file:
sudo nano /etc/xdg/autostart/kiosk.desktop
Add:
[Desktop Entry]
Type=Application
Name=Kiosk
Exec=/usr/local/bin/start-stream.sh
X-GNOME-Autostart-enabled=true
sudo nano /etc/systemd/system/stream.service
Add:
[Unit]
Description=Auto Start RTSP Stream
After=network.target graphical.target
[Service]
Type=simple
User=naman # Change to your username
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/naman/.Xauthority # Change 'naman' to your username
ExecStart=/usr/local/bin/start-stream.sh
Restart=always
RestartSec=3
[Install]
WantedBy=graphical.target
Enable and start service:
sudo systemctl enable stream.service
sudo systemctl start stream.service
# Check status
sudo systemctl status stream.service
# Stop stream
sudo systemctl stop stream.service
# Start stream
sudo systemctl start stream.service
# Restart stream
sudo systemctl restart stream.service
# View logs
journalctl -u stream.service
- Runs in fullscreen without desktop environment visible
- Auto-restarts on crashes
- Prevents screen blanking
- Hides cursor
- Keeps stream always on top
- Shows error message when camera is unreachable
- Check DISPLAY environment variable
- Verify monitor connection
- Check Xauthority path matches username
- Verify camera IP is reachable
- Test RTSP URL in VLC player
- Check network connectivity
- Review service logs
- Verify kiosk mode setup
- Check autostart configuration
- Ensure proper permissions
You can modify:
- Error message appearance
- Stream parameters
- Retry intervals
- Screen resolution
- RTSP URL and credentials
Remember to restart the service after changes:
sudo systemctl restart stream.service
- SSH access recommended for management
- Keep backup of working configuration
- Test changes in non-production first
- Monitor system resources periodically