Skip to main content
added 870 characters in body
Source Link
#!/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
#!/bin/bash

# Remove previous test stream grab
rm /home/pi/snapshot.png

STATUS=0
while [  $STATUS == 0 ]; do

    # Test stream by taking image grab
    ffmpeg -i rtsp://192.168.0.67:8080/h264_ulaw.sdp -frames 1 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: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:8080/h264_ulaw.sdp -frames 1 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
    else
        echo "$file not found."
        sleep 5
    fi
done
#!/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://$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://$myip:8080/h264_ulaw.sdp --fullscreen &
        
        STATUS_INNER=0
        while [  $STATUS_INNER == 0 ]; do
            rm /home/pi/snapshot.png
            ffmpeg -i rtsp://$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
Source Link

Getting vlc to start network stream on boot (if stream is up) and monitor stream status in case it goes down

I've written a script that first checks whether a local network stream is up, then if this is the case it will start vlc. It will then keep monitoring the stream, if it goes down it will close vlc and wait for the stream to return before restarting vlc (see below).

If I run the script manually this works.

I'd like this script to run automatically on startup (using Raspbian). The issue I seem to be having is that regardless of how I get the script to run on startup I see that it's briefly connecting to the network stream but it isn't opening vlc (at least not visibly on the desktop).

Any suggestions gratefully appreciated.

#!/bin/bash

# Remove previous test stream grab
rm /home/pi/snapshot.png

STATUS=0
while [  $STATUS == 0 ]; do

    # Test stream by taking image grab
    ffmpeg -i rtsp://192.168.0.67:8080/h264_ulaw.sdp -frames 1 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: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:8080/h264_ulaw.sdp -frames 1 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
    else
        echo "$file not found."
        sleep 5
    fi
done