xt4london
Posts: 1
Joined: Tue Aug 13, 2013 11:29 am

use rapistill with an ordinary webcam

Tue Aug 13, 2013 11:33 am

Do you know if it is possible to use rapistill with an ordinary webcam connected to the pi via usb?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 17882
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to make a webcam

Tue Aug 13, 2013 12:01 pm

xt4london wrote:Do you know if it is possible to use rapistill with an ordinary webcam connected to the pi via usb?
No, that software is specifically for the Raspi camera module.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Re: How to make a webcam

Tue Aug 13, 2013 2:53 pm

Have tried it as per instructions and I get this error msg.:

The image “http://192.168.0.2/webcam.php” cannot be displayed, because it contains errors.


so just to be sure I have checked the /tmp/ folder if images are being generated with:

sudo nano /etc/lighttpd/lighttpd.conf
###########################
## http://redmine.lighttpd.net/projects/1/ ... ngactivate
## Enable Directory listings :))) for all DIR with no INDEX file present
dir-listing.activate = "enable"
###########################

sudo ln -s /tmp/ /var/www/tmp
sudo ls -ld /var/www/tmp

now when viewing the folder in http://192.168.0.2/tmp
I get 2 files:
buffer.jpg 2013-Aug-13 15:45:56 40.0K image/jpeg
webcam.jpg 2013-Aug-13 15:49:15 236.1K image/jpeg

which are the pictures of the camera being updated every 5 seconds
but no luck in web browser in either of html or php :(
Last edited by marcelp1 on Wed Aug 14, 2013 10:42 am, edited 1 time in total.

marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Re: How to make a webcam

Wed Aug 14, 2013 8:39 am

ednl wrote:Also, does http://192.168.0.2/phpinfo.php work, does it give the PHP configuration info? I'm afraid I made a mistake in the original instructions on how to create that file, which I corrected this morning. This should work:

Code: Select all

echo '<?php phpinfo(); ?>' | sudo tee /var/www/phpinfo.php
And if it works, does the page have a "gd" section?

Edit: I added an important caveat to the page, warning not to have any spaces or blank lines outside the <?php and ?> markers in the script. They MUST be the absolute first and last thing in that file.
PHPinfo.php works fine with the latest instructions and gd section is there as well:

Code: Select all

gd
GD Support 	enabled
GD Version 	2.0
FreeType Support 	enabled
FreeType Linkage 	with freetype
FreeType Version 	2.4.9
GIF Read Support 	enabled
GIF Create Support 	enabled
JPEG Support 	enabled
libJPEG Version 	unknown
PNG Support 	enabled
libPNG Version 	1.2.49
WBMP Support 	enabled

Directive	Local Value	Master Value
gd.jpeg_ignore_warning	0	0


I have downloaded copy of the files from your server

wget http://www.dronkert.net/rpi/webcam-html-1.0.0.txt
wget http://www.dronkert.net/rpi/webcam-php-1.0.1.txt
sudo cp webcam-html-1.0.0.txt /var/www/index.html
sudo cp webcam-php-1.0.1.txt /var/www/webcam.php

and it is now working.

Now, I have not studied the files (index.html / webcam.php), but I have made a mistake and for some strange reason I thought that I can view the camera in html or php file, so I have originally named both files webcam.html and webcam.php ;(
Lesson learned.

Can the stills be written to RAM "/run/shm" of the RPi rather than "/tmp/" folder?

marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Re: How to make a webcam

Thu Aug 15, 2013 10:10 am

Is there any way to have the:

Code: Select all

nohup raspistill -n -e jpg -w 640 -h 480 -q 80 -t 2147483647 -tl 5000 -o /run/shm/webcam.jpg &
or I have noticed that for unlimited time -t has been set to

Code: Select all

nohup raspistill -n -e jpg -w 640 -h 480 -q 80 -t 9999999 -tl 5000 -o /run/shm/webcam.jpg &

start on reboot / power on automatically?

BlackBear
Posts: 5
Joined: Sat Jun 01, 2013 10:08 am

Re: How to make a webcam

Mon Aug 19, 2013 12:21 am

Thank you for this! I've finally completed my apt door monitor project with your tutorial.

I have mine setup to reboot the webcam using cron jobs hopefully it works lol. Now i have to figure out how to schedule my raspberry pi to reset every week or every 20 days. In case my raspberry pi freezes.. I set up watchdogs as well. I was wondering though if there's a way to create a button that says save image on the webpage next to stop?

Anyway to program it to stop at a certain time and turn on at a certain time? I noticed my raspberry pi gets pretty hot leaving it on 24/7 maybe i need to some a way to cool it.
Thank you for all your hard work and without your tutorial I would of never been able to get this mini project done!

marcelp1
Posts: 129
Joined: Mon Jun 11, 2012 8:41 pm

Re: How to make a webcam

Wed Aug 28, 2013 12:54 pm

Notice that you have changed RAM disk reference from /run/shm to /dev/shm
Is it where the RAM is, in /dev/shm?

Thank you for the start-up daemon.

Is there a way of making the time/date stamp in top left corner bit bigger?

rasphoto
Posts: 14
Joined: Tue Aug 27, 2013 9:14 pm
Location: Mexico
Contact: Website

Re: How to make a webcam

Wed Sep 25, 2013 5:54 pm

Hi. Thanks much for this. I am almost finished, I think, but since I am a a very cautious begginer, I am a bit stumped on this "essential step":
the file name (-o) in the raspistill command and the file name ($cam) in the webcam.php script.

What should I change before I enter
nohup raspistill -n -e jpg -w 800 -h 600 -q 70 -t 2147483647 -tl 5000 -o /dev/shm/webcam.jpg &
and then hit enter?

Apologies but any help is appreciated.

rasphoto
Posts: 14
Joined: Tue Aug 27, 2013 9:14 pm
Location: Mexico
Contact: Website

Re: How to make a webcam

Wed Sep 25, 2013 6:39 pm

Many thanks! I am still trying to understand your reply little by little. I am working this project to be a "volcano-cam" to monitor a nearby volcano. I have a question:
Aside from this being a webcam, could I also have the raspberry send the saved images to an ftp and delete them from disk at the end of the day or every 12 hours so as to not fill up my disk?

rasphoto
Posts: 14
Joined: Tue Aug 27, 2013 9:14 pm
Location: Mexico
Contact: Website

Re: How to make a webcam

Wed Sep 25, 2013 8:26 pm

Thank you so much. Well, my webcam is up and running in my office right now so I know it works with your very well explained post. I still have a lot to learn and shell scripts and php are totally alien to me. But I'll keep trying. I have a question: How do I stop this webcam process?

rasphoto
Posts: 14
Joined: Tue Aug 27, 2013 9:14 pm
Location: Mexico
Contact: Website

Re: How to make a webcam

Wed Sep 25, 2013 9:02 pm

Great! Today was a really helpful and productive day thanks to you! Your post help me understand many issues. Thanks so much for your quick replies. I'll keep trying to make this work for my project but this was really a great step forward.

TimBacon
Posts: 5
Joined: Wed Sep 25, 2013 10:51 am

Re: How to make a webcam

Wed Oct 02, 2013 5:20 pm

This is an outstanding project and really well explained. I'd just got wifi working, then the camera and was wondering how, with my limited Linux, to take the next steps. The inclusion of these short code examples, with nice, simple possibilities for customization is ideal for me. I can't wait to get it working!

TimBacon
Posts: 5
Joined: Wed Sep 25, 2013 10:51 am

Outstanding!!!

Wed Oct 02, 2013 9:26 pm

Followed the instructions, worked first time, results outstanding! This is great fun.

User avatar
u8nc
Posts: 45
Joined: Mon Mar 05, 2012 7:55 am
Location: Rural Australia

Re: How to make a webcam

Thu Oct 10, 2013 10:50 pm

I haven't tried this, only read it through.

From what i can gather, it's only a webcam as in 'like your camera enabled laptop'.
Just like you can take your laptop into the backyard, as long as your within wifi range of your modem router you're golden.
or, a PiCam with a Pi as sufficient brains to store and take requests from your computer indoors ( or remote login form anywhere on the web ) , but the connection is already held by another machine through the modem.

Am i right in saying then if i wanted to monitor a creek crossing out in the bush, with a 3G dongle taking requests from a web page on my ISP's server many 100's of kilometres away via SSH, then this is not for me?

User avatar
u8nc
Posts: 45
Joined: Mon Mar 05, 2012 7:55 am
Location: Rural Australia

Re: How to make a webcam

Sun Oct 13, 2013 2:47 am

then this is not for me?
... nobody ??

poing
Posts: 1132
Joined: Thu Mar 08, 2012 3:32 pm

Re: How to make a webcam

Sun Oct 13, 2013 10:34 am

I don't know why it wouldn't work over 3G. But your #1 problem would be power; although the Pi consumes very little for a full fledged computer, running it 24/7 will need considerable power which is hard to maintain off-grid. Do a search, it's discussed many times. Also the cost of the 3G connection will be significant I'd say.

raspy1
Posts: 1
Joined: Mon May 27, 2013 8:53 pm

Re: .

Tue Dec 24, 2013 11:11 am

Hi,

thanks for the code, very usefull to build a homemade webcam.

To manually start taking pictures only when necessary, and not running raspistill all the time, I add command when loading the page first time, by adding a php script at the beginning of page load.
1. rename index.html to index.php
2. add this code between the </head> and the <body>

Code: Select all

<?php
$ps = exec("ps -A | grep 'raspistill'");
$run = strstr($ps, 'raspistill', False);
//echo $run;
if ($run == 'raspistill') {
   echo "Capture is already running";
}
else {
   echo "Capture and refresh every sec, launched for 5mn";
   $output = shell_exec('raspistill -n -e jpg -w 800 -h 600 -q 70 -t 300000 -tl 1000 -o /dev/shm/webcam.jpg > /dev/null 2>/dev/null &');
   echo $output;
};
?>
3.Do not run the raspistill as a service.

It runs the capture only for 5 minutes (300 000ms - you can adjust the -t parameter), and stop.
Just refresh the page in the browser to run a new set.

It seems working fine :)
Raspy1

Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 10 guests