Short and Simple:
Client needed simple, low bandwidth solution for monitoring home while away for vacation
Setup 4 IP Cameras to feed images into Raspberry Pi connected to 1TB External HardDrive via FTP Server
Setup hourly backup script which archived all images of that hour, processed images through ffmpeg to create webms a video format used on sites such as twitter and snapchat
The newly created webms were then sent to clients email address for consumption
This story starts out with one of my family members worrying about leaving their home unattended while they planned on going on vacation for the next two months. They had hastily gone out and purchased 4 IP cameras that one of their relatives had recommended for monitoring but had not set it up completely. About 2 days before their scheduled trip he had still not set it up so he tasked me with setting it up for him.
To start out, the IP Cameras he purchased were of varying quality and feature set. Three were outdoor, one was indoor. They all supported a common feature set which included:
- Motion Sensing
- Night Mode
With the deadline looming forth, I hastily grabbed a few things from my closet, these being:
- Raspberry pi 2
- 1tB External HDD
My thought process was that I could use the motion sensing in conjunction with the ftp feature to store all the captures on the external HDD connected to the raspberry pi. Now I understand that the raspberry pi isn't necessarily the best due to the USB ports and the ethernet port running on the same usb 2.0 chipset, but with the deadline looming forth, I did some quick tests and it appeared to be serviceable with 4 IP cameras sending 4 pictures every second at most.
To start off with I setup the raspberry pi with Raspbian, attached the 1tB external hdd which was formatted with ntfs which required me to install ntfs-3g, normally I'd just format this with ext4 but the client seemed to be using windows on all his machines so if he wanted to access the harddrive later I figured just using ntfs would be fine. I did also setup samba so he could access it via network discovery but the raspberry pi is quite slow in this department due to the config of the USBs and Ethernet being on the same usb 2.0 controller as stated earlier.
With the drive now ready for files I quickly setup FTP on the raspberry pi and changed the settings on all the IP Cameras to feed their image data over to the pi. It appears that all they do is attach the IP Cameras unique name and a timestamp so I needed a way to archive them better. I merely wrote a simple bash script that ran hourly via Crontab to save the images to a separate location on the external harddrive. With this done I moved onto figuring out a way for the client to view his footage.
The clients internet connection, left much to be desired. It was a 5mbps down, .5mbps up connection with very little room to spare when it came to bandwidth. Single images clocked in at approximately .5mB each, sending every single image to the client simply wasn't an option, especially considering he was vacationing overseas with unknown internet capability. I did some quick research and hastily tossed together the idea of taking the bulk of the footage in one hour intervals and converting it to video, the webm standard had been slowly been creeping its head into the internet landscape so I decided to try my hand and see if my idea held salt. I landed on using ffmpeg and setting it up to make videos, the settings I decided on were 720p and setting the fps to 4. Results were quite good, the cameras were setup to take pictures every time something moved, but since nearly 80% of the screen is static most of the time, the resulting videos turned out to be very efficient on size.
With that hurdle solved, I simply setup the Raspberry pi to send the client an email every hour with the webms attached and everything was perfectly fine. Although I don't necessarily think my solution is perfect, but I think for the amount of time I had to complete it I did a reasonably good job.