OK, here's a quick tut on how to get live video streaming onto your brewpi page (following on from
this post on getting images from your webcam onto the page):
Disclaimers:
- I've tested this in chrome, it works there
- I've tested this on Safari on iOS devices, it does NOT work there
- I've tested this using VLC on iOS devices, it works there
Setting Up VLC:
(Get VLC if you don't have it-> sudo apt-get install vlc)
Make sure your user has permissions to access the webcam:
Give a group called 'video' ownership of the webcam:
Code:
sudo chown root.video /dev/video*
Then, add 'brewpi' to the group:
Code:
sudo adduser brewpi video
Then, give brewpi access:
Code:
sudo chmod g+rw /dev/video0
That should work great. (
Source)
Create a file in your home folder called "webcam.sh"
In it, put the following:
Code:
#!/bin/bash
cvlc v4l2:///dev/video0 :v4l2-standard= :input-slave=oss://denull :live-caching=300 :sout='#duplicate{dst="transcode{vcodec=theo,vb=1024,channels=1,ab=128,samplerate=44100,width=320}:http{dst=:8084/stream.ogg}"}'
Note: If your video still doesn't work because of permission errors accessing /dev/video0, then you can add the following line to your shell script, above the cvlc line (replacing the <password> bit with your brewpi password):
Code:
echo <brewpi password here> | sudo -S chmod 666 /dev/video0
Obviously, echo-ing the password into the sudo is bad and should be avoided if you can.
Save that file.
You can test it by running it (./webcam.sh) over SSH and seeing if VLC on any other computer can get to the stream (File->Open Network Stream->http://<brewpi address>:8084/stream.ogg
Making the script run on startup:
Now you want this script to run every time the computer starts up, so we'll add a task to the crontab:
Add a line at the bottom like so:
Code:
@reboot /home/brewpi/webcam.sh > /home/brewpi/vlclog.log 2>&1 &
This tells cron to run the script on reboot, and to pipe the output to that log file, just in case.
Adding the video to your page:
Now that that's working (hopefully), you can edit your index.php file to include the video:
So, where we previously had the canvas (down at the bottom of the page), we'll now just have this simple code:
(again, replacing the url portion with the correct address)
Code:
<video id='webcamVid' width='600px' controls>
[INDENT]<source src='http://<brewpi url>:8084/stream.ogg' type='video/ogg'>[/INDENT]
</video>
Reload the page in Chrome, and you should see the live stream from your webcam.
Good luck, let me know how it goes!
View attachment 213584