6

I am trying to auto-start a script, that starts a video stream via vlc on a raspberry pi with raspi camera. This is the code that starts 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

I have tried to add the script to init.d which does work as the LED on the camera blinks, but the startup seems to stop the script after a second. I also tried to add the script to rc.local and autologin and it didn't even blink. I tried to edit /etc/bash.bashrc too, with the following code:

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

But that didn't work either. Any suggestions? The script runs fine on its own.

I should also add that the stream gives an output constantly and it can't be hidden or ignored.

  • 1
    Hi! You might try adding sleep X at the beginning of script (where X is a reasonable number of seconds) and changing the line of your code into ./script & . However, I haven't tested it, it's basically only a blind shot. – yo' Mar 12 '14 at 13:56
  • I forgot to add, use init.d of course, using .bashrc seems just wrong! The idea was simply to add a long sleep in the process. – yo' Mar 12 '14 at 14:26
  • Unfortunately it did not work. The Camera does not blink or anything. – Diego Mar 13 '14 at 6:17
  • Try run from ~/.xinitrc – hendry Mar 13 '14 at 11:36
  • Try putting it in /etc/rc.local with the & after. – Fred Mar 13 '14 at 14:03
2

I have now found out two solutions.

  1. Making a script that run another script (This is the one I'm using at the moment)

I have made a script (check.sh) that searches the processes-list for "vlc", and if it get any hit it will exit the script. If there are no processes called "vlc" running, it execute a script (video.sh) which start the stream. In crontab I added the first script (check.sh) to be run when booting:

crontab -e @reboot /home/pi/check.sh 

This is what check.sh looks like:

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

And this is what video.sh looks like:

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv
stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264 OBS!
This will not work with **sudo crontab -e** as vlc only run as
regular user (pi works fine)

2. Adding only execution-line into rc.local

I have not tried this, but a collegue got this to work with vlc on raspberry. This way you only have to add one string to rc.local with a pause before the string, like this:

(sleep 5;su - pi -c "raspivid -o - -t 0 -n -w 640 -h 480 -fps 15 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264")&

There may be more ways to do this, but this is what I have found out so far.

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.