Page 1 of 1

start camera stream from web page

Posted: Sun Jun 09, 2013 11:24 am
by talkeasy
Hi all

I would like to start a pi camera stream via a webpage and then view the stream via VLC but seem to have run into a permissions issue, I think.

So far I have reused this code to start the stream:

Code: Select all

raspivid -o - -t 999991 -hf -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264
It works fine from the SSH command line as user pi, and from a inside shell script started from the command line, and from a php script which calls the shell script, again from the command line as user pi.

The problem arises when I try to run the php script from /var/www. Other scripts work fine from the directory, but after some digging around it seems that VLC will not run as root due a to restriction put in place by the developers for security issues, and also it seems, as www-data.

Can anyone figure out how I could resolve this conundrum, please?


Re: start camera stream from web page

Posted: Mon Jun 10, 2013 2:41 am
by MmmPi
Have you tried su to run it as a normal user? ... t-password

Re: start camera stream from web page

Posted: Mon Jun 10, 2013 2:38 pm
by znanev
Hi talkeasy,

I had similar issues. The application raspivid needs access to the video group (the default user - pi, is already a member of this group, so that's why it works when running the command from the terminal). So this worked nicely for me:

Code: Select all

usermod -a -G video www-data
This command says: "Add the user www-data to the secondary group video".

This should be all you need to do, if your web server runs under the www-data accont.

Re: start camera stream from web page

Posted: Mon Jun 10, 2013 9:09 pm
by talkeasy
Thanks for the replies. I now have a working solution, although the php and shell scripts need tidying up to exit properly.

I updated /etc/sudoers with:

Code: Select all

www-data ALL=(pi) NOPASSWD: /home/pi/bin/
and then called

Code: Select all

sudo -u pi /home/pi/bin/
from another www-data shell script.

Haven't got the php script to exit nicely yet, but VLC now starting nicely.

UPDATE: To have the php in the webpage exit properly I have modified the code to the following:

Code: Select all

shell_exec('nohup ./ > /dev/null & echo $!;');