Posts: 8
Joined: Fri Jul 26, 2013 10:01 pm

Start at boot and restart app on exit

Fri Aug 25, 2017 5:35 pm

I am looking to set up my Pi as a dedicated camera streaming to the network. I want it to start the camera on boot and should FFmpeg or raspivid crash, then it restart the apps.

I have used a similar script before, but it just won't work here :( it starts fine but when I kill raspivid or FFMpeg, it doesn't restart.

The script (/home/pi/picamrjp.sh) as follows:

Code: Select all

while ! raspivid -o - -t 0 -fps 25 -b 6000000 | ffmpeg -re -f h264 -i - -vcodec copy -g 50 -f avi udp://
  sleep 1
  echo "Restarting program..."
I intend to call it from rc.local eventually but can't get it to work in a terminal first.
Help appreciated :-)

User avatar
Posts: 6791
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Start at boot and restart app on exit

Fri Aug 25, 2017 6:26 pm

Using "while !" means that you still are checking the return value of the command. So if the command return 0 ( which I think is "true" in bash ) your script will end because "!0" = "not true" = "false".

Using "while (true)" ( or equivalent in bash ) and moving the command into the do/done block it should never exit the loop.

Return to “Raspberry Pi OS”