Stream images from the webcam every minute with GNU / Linux
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.
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.
At this point we montare l’FTP remoto 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“.
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 powder’ Spartan but functional: