Making video recorder for IP-cameras on base Raspberry Pi 2 with an USB HDD (SSD) drive that all together had placed in retro Atari XC12's case.
- Raspberry Pi 2,
- USB HDD (SSD) drive;
- DC-DC to 5V 3-5A step down converter;
- USB HUB (optional);
- Atari XC12 case.
Any single-board computer with USB and LAN port can be used here, as Raspberry, Odroid, even some routers.
YDS-5A DC-DC converter step down from 12-36 to 5V 5A was used in this case.
An USB HUB is optional only if used USB HDD (SSD) requires more than 1A power.
The RJ45 patch cord and the pair-wire cable with DC power jack were used.
All electronic components of Atari XC12 and main part of it tape track were deleted.
The original "Save" LED of the Atari XC12 was used as LAN indicator of Raspberry Pi.
All components were connected as this wiring diagram ...
... and them were placed in the Atari XC12 case.
The RJ45 patch cord and the pair-wire cable with DC power jack were let out from the Atari's case.
Being connected to the home network router and powered, this new recorder was accessed via PuTTY by IP, port 22 (SSH access must be switched on in Raspberry by command raspi-config and then Interfacing Options). Then in terminal under root user was entered next commands:
apt-get install ffmpeg
apt-get install samba
Here was noted name of USB (SSD) storage attached to Raspberry. This was sda1 (can be sdb1 or other). Then next commands were entered:
mount /dev/sda1 /mnt
- /dev/sda1 is name of HDD (SSD) was noted above;
- outer_cam_01 is name of folder for video archive (can be more then one folder).
Next lines were entered at the end of opened file:
path = /mnt
force user = root
read only = No
guest ok = Yes
hide dot files=yes
create mask = 0777
directory mask = 0777
Ctrl+O, Enter, Ctrl+X
Then next commands were entered:
@reboot sleep 60; mount /dev/sda1 /mnt; sleep 20; chmod -R 0777 /mnt
# the following line gives the command every 2 minutes to record 118 seconds of the stream from the camera to a file with the current date and time in name
*/2 * * * * ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.3:554/11 -r 25 -t 118 -vcodec copy /mnt/outer_cam_01/`date +\%Y\%m\%d\%H\%M\%S`.avi > /dev/null
# the following line gives the command every 6 minutes to delete the oldest files in the folder when the folder size exceeds 130000 MB
*/6 * * * * while [ $(du -sm /mnt/outer_cam_01| cut -f1) -gt 130000 ]; do rm -f /mnt/outer_cam_01/"$(ls -1c /mnt/outer_cam_01/ | tail -n1)";done > /dev/null
@daily sudo killall ffmpeg
# and at least one empty line should be at the end of the file!
Ctrl+O, Enter, Ctrl+X
where rtsp://192.168.1.3:554/11 is address of RTSP stream of IP camera (can be other according camera's user guide).
No later than 2 minute, the video archive accessible from any computer in home network.