1

I am trying to start a stream on my Raspberry Pi Camera when I boot the Raspberry Pi. I have tried the following options:

  1. Using crontab

    @reboot /home/pi/video.sh &

  2. Using init.d Copied the script video.sh into init.d

  3. Added following code to /etc/rc.local

    if [ $(tty) == /dev/tty1 ]; then

    /home/pi/video.sh &

    fi

I can also add that the script contain this:

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264

This string starts a continuous flow of data and start to stream from VLC. To watch the stream I start VLC, or as I do, start the HTML page I have created and enter the raspberry IP-address.

My guess is that when booting the Pi it runs the script, but after that stop or get terminated by another startup script, since the camera just blinks for a second then turn off.

Is there a way to make this script keep running even after startup?

  • Does your script work normal in commandline mode? As user root and as user pi? – ExploWare Mar 18 '14 at 17:52
  • It does work in commandline. Only as Pi thought, somethind about VLC can't be run as root. – Diego Mar 19 '14 at 7:55
1

I have now solved it.

My solution was to make a script the check if there are any processes named vlc, and if there are none it run the script that starts the stream. Then I added the followin to cron with crontab -e:

@reboot /home/pi/check.sh

The script itself contain the following code:

#!/bin/bash
pidof='pidof vlc'
if [[ -z $pidof ]]
then
        exit
else
        /home/pi/video.sh
fi
exit

video.sh contain the following string to start the stream:

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264 &

What I think may cause the problem I had was that when the Pi run scripts at startup, it just runs it, and when finnished it stop. That would explain why the camera blinked for about 1 second and then stopped.

  • Glad to hear you resolved this! If you could mark this self-answer (this one) as answer, that would be great. We are trying to get the site Q:A ratio up and doing this would help us a lot. Thanks! – RPiAwesomeness Mar 23 '14 at 17:26
  • Marked as answered. I had to wait 24 hours to do so after answering and forgot about this this weekend. – Diego Mar 24 '14 at 6:06
  • Of course. No probleema, and again, glad to here that it got resolved! – RPiAwesomeness Mar 24 '14 at 6:08
0

Anything in /etc/rc.local should keep running after boot indefinitely. If it is crashing, you can make it restart automatically by putting it in a while loop:

#!/bin/sh
while true
do
    raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264
done
  • Same result as with everything else. The Camera LED blink for a second, then nothing. – Diego Mar 18 '14 at 14:24
  • I'd suggest then trying to break down the command. The fact that it flashes suggests the program is crashing. If you run only the raspivid portion (before the |), does it still happen? – Fred Mar 19 '14 at 13:02
0

Most bootscripts run as root.
VLC doesn't allow that.
You should run vlc as normal user, maybe like so:

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 |su pi -c "cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264"

or in /etc/crontab:

@rebootpi/home/pi/video.sh &

or in the /etc/rc.local:

if [ $(tty) == /dev/tty1 ]; then su pi -c "/home/pi/video.sh"& fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.