⬆️ ⬇️

Timelapse with elements of video surveillance

Hello, habra users.



Having read Habré about timelapse with Raspberry Pi ( one , two ) and after three cars in the parking lot punched the wheels for one night, and a week before one car was opened, I decided that I needed to organize low-budget video surveillance.



There is no budget for a super-cool HD IP camera with a wi-fi, and, frankly, a desire, since I like to dig into configs, poke wires and anything else.

')

In general, anyone interested, please under the cat.



Iron part



• The center of the processing universe - Raspberry Pi ($ 43 for a fee with an SD card 8Gb + 16 UAH for delivery by New Post from the regional branch of DHL).



• Video capture card - EasyCap on STK1160 chipset ($ 12 from China).



• Communication with the world - Wi-fi dongle COMFAST ($ 6 from China).



• Backup Power - NONAME PowerBank ($ 6 from China).



• Analog camera like on a CCD from Sony (has been available for many years).



• Cheap NONAME webcam for example ($ 7 from China).



• Charger for PowerBank for 1A, power supply for analog camera on 9V, a pair of microUSB wires (everything was good in stock).



Software part



operating system


Install Debian Wheezy on Raspberry Pi ( taken here ). I did not bother with the Unix dd and Windows Win32DiskImager utility and downloaded Noobs Lite, with which I installed the desired Raspbian Wheezy.



When you first start, we are welcomed by raspi-config, where you can change the locale, user password pi, overclock the processor (I advise you to do it only after installing radiators). Next comes the reboot and here we are in Linux.



Immediately I advise you to do:



sudo apt-get update sudo apt-get upgrade 




Network connection


Install drivers on the wi-fi module:



 sudo apt-get install firmware-ralink 




Next, we register in our wi-fi network



 sudo nano /etc/network/interfaces 




 allow-hotplug wlan0 auto wlan0 iface wlan0 inet dhcp wpa-ssid “__” wpa-psk “___” 




We save. Execute the command:



 sudo /etc/init.d/networking restart 




and disconnect from the wired connection.



Capture program


I’ve been looking for something suitable for a long time, I went through different options, including those on Habré, but the choice fell on FSwebcam. Install it:



 sudo apt-get install fswebcam cd /home/pi touch fswebcam.conf sudo nano /home/pi/fswebcam.conf 




And in the config we write:



 device /dev/video0 pid 9990 input 0 loop 10 skip 20 resolution 720x576 top-banner title "Stoyanka@RPi" timestamp "%d-%m-%Y %H:%M:%S (%Z)" palette YUYV jpeg 100 save /home/pi/webcam/capture."%Y%m%d%H%M%S".jpg save /usr/share/nginx/www/wc/capture.jpg 




We save.



By config I hope everything is simple:

• device / dev / video0 - our video device

• loop 10 - capture pictures every 10 seconds

• skip 20 - skip 20 frames before capturing an image



Run FSwebcam:



 sudo fswebcam –c /home/pi/fswebcam.conf –b 




And see how the picture is updated.

In the wilds of nginx I will not climb, and there are many simple examples on the Internet. All the good is displayed on a web page with one picture, which is saved in the FSwebcam config in /usr/share/nginx/www/wc/capture.jpg.





Sample webcam images in the morning





Sample pictures from the analog camera in the morning



According to the photo, we can assume that the photo from the webcam is better, “more colorful”, but at night everything changes. Moreover, the webcam has the maximum quality that can be pulled out, and on the analog one, the default settings, which can still be pulled.





Sample webcam images at night





Sample pictures from analog camera at night



And the analog viewing angle is larger. Go ahead.



Since the power of the Raspberry Pi will not be enough to compile the video, I decided that it would be better to do it on an old Toshiba Satellite A100 laptop.



Connecting to a laptop via sshfs (it seemed to me that it would be easier).

It is installed simply:



 sudo apt-get install sshfs 


and finally:

 sudo echo 'ROOT_PASSWORD' | sshfs root@192.168.1.1:/usr/storage/primary/webcam /home/pi/webcam -o password_stdin 




I did not suffer every time to enter the password and scored this command in the crontab when rebooting. Now all the pictures with the time stamp in the file name are stored on the laptop, where, according to krone, at 8 am the command is run:



 mv -a /usr/storage/primary/webcam/. /home/note/webcam 




Next, we rename all the photos one by one to aconv eat them:



 ls *.jpg| awk 'BEGIN{ a=0 }{ printf "mv %s cap_%04d.jpg\n", $0, a++ }' | bash 


Glue the video:

 avconv -i cap_%04d.jpg -c:v libx264 -r 24 -crf 21 test.mkv 




Clear the folder from the photo. After that, we upload the video manually or automatically to YouTube and apply music so that it is not boring to watch.



Sorry for the video from the old webcam, as the analog one just plugged in yesterday and didn’t manage to tweak everything and glue the video together.





System view



Notes



Prices for goods from China are from Aliexpress at the time of purchase.

Raspberry Pi is powered by PowerBank, which is connected to the charging, which allows the system to work autonomously with a power loss of up to 4 hours. True power to the analog camera is reserved through the UPS.



List of links



Script download video on Youtube

Installing drivers on wi-fi Ralink

Connecting to a wi-fi network

Mounting a remote folder

About FSwebcam

Why you need to buy EasyCap on the STK1160 chipset



That's all I wanted to say. I would be glad if someone would be useful and interesting.

Source: https://habr.com/ru/post/200934/



All Articles