Cookie

TheJoe.it Into the (open) source

1Jul/102

Stream images from the webcam every minute with GNU / Linux

Caution!

This article was written in the 2010, there may have been some developments in the subject matter.
If in doubt please leave a comment in the bottom of the article.
Thanks.

webcam_streaming

Recently I was asked how he could do to organize a stream webcam that may control the Weather Conditions of a given area. The images of the stream must then be placed on a dedicated page of a site. Unfortunately, (or fortunately) I had to run into a big problem that at first seemed insurmountable: la webcam is locally attached, the server that hosts the site è remote.

This small detail was going to make me give up, when I remembered the existence of "Curlftpfs" (where there we have already discussed) to mount the remote FTP seen by the system as if it were a local. A real godsend.

The rest was easy. The software used is "Curlftpfs", "Crontab", "Streamer". For simplicity, I organized the stream so that the image was overwritten by the new one every minute. In this way save resources the server, though not be able to keep a historical record movements in front of the webcam. I repeat that it is a webcam placed for meteorological purposes, surely this procedure is not useful for the remote control.

Below I list the most important passages.

The three programs exist in repositories of major distributions, each uses its package manager to install.

Streamer

First you need to test the 'effectiveness of "Streamer". Run the command:

streamer-o / home / user / images / image.jpeg

and we check that the directory "/home/user/images/" both the file was created "image.jpeg". If all goes well the program has created its first photo.

Curlftpfs

At this point we mount the remote FTP with "Curlftpfs":

curlftpfs -o user="user:pwd" ftp.miosito.it / mnt / miosito.it /

If everything runs smoothly going in the directory "/mnt / miosito.it /" we should see the files on the server (there is obviously a slight delay in response, remember that we are always operating in remote).

At this point suggest, to order more than anything else, of create a directory local and a remote call "webcam".

Crontab

Here comes into play "Crontab". It must do load "take a picture" and move in the directory "/mnt / miosito.it /" every minute. Open the file "/etc / crontab":

[user@localhost:~]$ sudo nano / etc / crontab

and add the following lines after the last command you have entered in the file:

* *   * * *   joe     streamer -o /home/user/Immagini/webcam/w_image.jpeg
* *   * * *   joe     cp /home/user/Immagini/webcam/w_image.jpeg /mnt/miosito.it/webcam/

The asterisks at the beginning of the line are very important, in practice they say in "Cron" to start the program specified every minute.

We pretty much finished. We can do testing the operation of the procedure (just wait a minute) making sure that the image is actually loaded, and include it in the page.

Council also set a refresh automatico every minute on the landing page of photos. In this way the beholder stream will not have to recharge every time the page. To refresh in php include the following lines just after the tag "<html>":

<?php
header("Refresh: 60;");
?>

And this is a screenshot of the result, a little 'spartan but functional:

About

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

Comments (2) Trackbacks (0)
  1. Everything depends on the level of access you have to the remote server, libraries and programs installed.

    Meanwhile, try to tell me how you configure your network. Images are “taken” via webcam from your local PC if I understand it, will then be saved to a local directory and then transferred to the remote server (what you see by typing “http://*.*.*.*:445/snapshot.cgi”.

    I understand it, or the ip you type is your local (or the global one that refers to your pc)?

    Last thing: I assume that on the computer that “snaps” the photo has been installed in any linux distribution.

  2. Hello I have two simple webcam and I should do the same thing only I can do it just the web side can you tell me how I can get the same result??

    Let me explain

    the cam i can see from http://*.*.*.*:445/snapshot.cgi that returns the’ I should add this picture to date now and logo.
    And’ can do the web side in the sense that the cam is installed and accessible via an IP the site is hosted on a remote server that is fished in the details of http://*.*.*.*:445/snapshot.cgi

    Thank you very much

    Hello


Leave a comment

No trackbacks yet.