#!/bin/bash
export DISPLAY=:0
# Remove previous test stream grab
rm /home/pi/snapshot.png
myip="192.168.0.67"
STATUS=0
while [ $STATUS == 0 ]; do
# Test stream by taking image grab
ffmpeg -i rtsp://192.168.0.67$myip:8080/h264_ulaw.sdp -frames 1 /home/pi/snapshot.png
# Check to see if image grab has worked
file="/home/pi/snapshot.png"
if [ -f "$file" ]
then
echo "$file found."
# Start stream if up
vlc rtsp://192.168.0.67$myip:8080/h264_ulaw.sdp --fullscreen &
STATUS_INNER=0
while [ $STATUS_INNER == 0 ]; do
rm /home/pi/snapshot.png
ffmpeg -i rtsp://192.168.0.67$myip:8080/h264_ulaw.sdp -frames 1 /home/pi/snapshot.png
if [ -f "$file" ]
then
# Do nothing
echo "Keep playing."
sleep 10
else
echo "Stream stopped, trying to restart."
pkill vlc
STATUS_INNER=1
fi
done
# STATUS=1
else
echo "$file not found."
sleep 5
fi
done
Currently trying to run using /etc/rc.local as below
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exec 1>/tmp/rc.local.log 2>&1 # send stdout and stderr from rc.local to a log file
set -x # tell sh to display commands before execution
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/home/pi/./vlc_autorun.sh
exit 0