After being unsatisfied with other OSS Security Camera NVR setups I decided to rely on my cameras built-in motion detecting abilities; and allow them to FTP alert files to my NAS. This however unfortunately left me with no simple way to quickly review the footage.
TimeLine is a simple PHP script to traverse a given directory tree looking for video files; providing viewing links to the files, as well as links to "related" footage. It's simple, and ugly (absolutely no prettying has been done); but it works for me™.
My personal cameras (ReoLink RLC-420) generate files in the format of 01_YYYYMMDDHHmmSS.ext (an mp4 and matching JPG); and are assigned to upload their files to a one-folder-per-camera assignment.
TimeLine walks this directory tree; with the assumption that for a given video file is a matching screenshot. If your cameras don't generate screenshots at the same time as (or with a matching filename to) video files all links will appear broken (however they should still link to the appropriate video file allowing viewing).
Video viewing is accomplished with built-in HTML5 video tags; so a modern(ish) browser is required for playback.
#EXPECTATIONS AND DEFAULT CONFIGURATION
$RootDir = "./camera/";
This is the base location of where you want scanning to occur. It is assumed that INSIDE this location the directory tree looks similar to this:
-./camera/
|--CAM_FRONT_DOOR
|----01_20161217113927.jpg
|----01_20161217113927.mp4
|----01_20161217105054.jpg
|----01_20161217105054.mp4
|----01_20161217100705.jpg
|----01_20161217100705.mp4
|--CAM_BACK_DOOR
|----01_20161217113927.jpg
|----01_20161217113927.mp4
|----01_20161217100705.jpg
|----01_20161217100705.mp4
|--CAM_GARAGE_DOOR
|----01_20161217113927.jpg
|----01_20161217113927.mp4
|----01_20161217105054.jpg
|----01_20161217105054.mp4
|--CAM_GARAGE_INT
|----01_20161217113927.jpg
|----01_20161217113927.mp4
To put it another way; $RootDir
contains folders for each of your cameras. Inside each camera folder are the video and image files associated. Folders INSIDE the camera folders are NOT processed however ANY FOLDER IMMEDIATELY INSIDE $RootDir
is, so do not place other folders with images or video files inside this location.
$Fuzzy = "2 minutes";
This is the time-span ± of a given video to check for related footage. If you are watching a video with a filename-timestamp of 20161217090500 (09:05:00 on Dec 17th 2016); it will look for files with a filename-timestamp of 20161217090300 to 20161217090700 (09:03:00 on Dec 17th 2016 to 09:07:00 on Dec 17th 2016).
This is a reasonably "intelligent" variable; and you can limit it in seconds, minutes, days, weeks, months, years etc. See PHP's datetime formats page at http://www.php.net/manual/en/datetime.formats.relative.php
$DateFormat = "Y-m-d H:i:s";
FOR DISPLAYING TIMESTAMPS ONLY. By Default this outputs a 4 digit year, 2 digit day & month, 24-hour hour, two digit minute and second. For Example 2016-12-17 18:36:05
See http://www.php.net/manual/en/datetime.formats.date.php and http://www.php.net/manual/en/datetime.formats.time.php for alternatives. Timestamp is pulled from the FILENAME of a given file. At the moment the script is HARD CODED to expect YYYYMMDDHHmmSS (4 digit year, 2 digit month/day, two digit 24hour, two digit minute/seconds). I intend to allow for easily changing this in the future but can be changed by modifying the line date_create_from_format('YmdHis',$file);
(roughly line 56 as of this writing). Follows standard PHP date/time rules (see previous links).
$IMGFormat = "jpg";
$VIDFormat = "mp4";
Filename extensions of the files generated by your cameras. You can honestly put anything you want here but whether or not it displays and / or plays is dependent on filetype and browser / HTML standards.
$FileCruft = "01_";
My particular cameras include a prefix to the filename, which just gets in the way of any formatting. If your cameras don't then set it blank (""); currently does not support a SUFFIX (EG if your files are named DATE_TIME_SUFFIX.ext). It's on the TODO list.
#SYSTEM REQUIREMENTS
The script was written on and works without modification (eg "out of the box") on a VirtualMachine running TurnKey-Linux (specifically debian-8-turnkey-nginx-php-fastcgi_14.1-1). I imagine it will work on any recent release of PHP as it's very simple and doesn't use anything exotic or modern that I am aware of.
#Warnings and disclaimer.
DO NOT RUN THIS ON ANY PUBLICALLY ACCESSABLE WEB-SERVER.
No warranty of usability, reliability, fit, finish or security; either explicit or implied is made. It may or may not work for you. It may impregnate your youngest son and steal your dog. All I know is he's called The Stig it works for me™.
This is a very QuickNDirty™ PHP script that reads everything on the fly. No data is cached so if you have a massive amount of files or are running this on a very low powered machine it could create a large amount of disk thrashing. The camera files must be read/write accessable to the webserver user.
Deleting files is relatively unchecked. It will not allow bulk deletions of files newer than 5 minutes and ignores 0-byte files. In both circumstances I assume that the file is either freshly uploaded, or still in the process of being uploaded by the camera.
Furthermore there is next to no security implimented, with liberal usage of $_GET variables. A nefarious individual could leverage this to delete un-intended files although it's unlikely due to the way the deletion code is written. The bulk delete command however could be ran by anyone
#SCREENSHOTS Main Index Page