Automatically collect/backup from Foscam SD-card storage to most NAS setups
To my knowledge, most (all?) modern Foscams have a built-in ftp-upload feature that one can use to point to an ftp server running on their home NAS... but this option has an unavoidable failing: uploaded videos have no audio!! (Why!?!!?)
If, instead, your camera is configured to save media to a removeable SD-card, these files do have audio. Physically removing the SD-card is an unacceptable pain, but it IS possible to access its contents over your home network! (well, probably. I can't speak for all camera models.)
As one example, the Foscam C1, has a quasi-secret built-in FTP server we can use. (Note this is entirely different from the ftp-upload client feature.) This feature is exposed when you "manage" your SD Card from the C1's webgui: [webgui:88] > Settings tab (on top) > Record tab (on left) > SD Card Management > "SD Card Management" button
. This button silently starts the camera's FTP server, then opens a Windows Explorer FTP-browser URL to port 50021 of your camera.
Using this, we can automate the archiving process using some basic unix/linux tools. Thus, I'm choosing to call this whole thing a (quasi-) "service", for simplicity. And this being said, this project is more of a how-to with guided examples than anything else.
- your NAS/computer to store the media and run the "service"
- the "Chocolatey" package manager, IF running the service on a Windows box
- the "Lftp" binary to manage the mirroring operation
- the "curl" binary to send the start-ftp command
- one or two scripts to config/run these binaries
- crontab (or your NAS's built in task scheduler) to regularly grab new files
I prefer to install non-server-essential junk outside the main OS, in a jail, but you don't have to. Doing so with a jail will definitely require you install some things manually so it's a better instructional starting point:
- Open a jail console (if using a jail) or SSH shell
- use
sudo
prefixing if you aren't root pkg update
to update the FreeBSD repository cataloguepkg install curl
to install curl (used to start an unstarted FTP server on the foscam)pkg install lftp
to install lftp (which will manage all mirroring)
- use
- choose/prepare your script(s)
- you can use a shell script that includes an LFTP command, or...
- use just an LFTP script
There's other ways to run Lftp on Windows, but I prefer using Chocolatey to sort of emulate the pkg/apt-get package managers since it's quick and easy. Chocolatey runs a quasi-hidden Cygwin environment in the background and installs .exe "shims" that communicate with the hidden environment.
- open an administrator command shell (aka run-as-administrator on cmd.exe)
- install Chocolatey via copy/paste/execute of the install command (https://chocolatey.org/install)
-
Currently:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
-
You should see progress text, but not errors.
-
If you see no text at all, try restarting your computer -- .net might have crashed
-
- install curl and Lftp using chocolatey (in that same administrator shell)
choco install curl
to install curl (used to start an unstarted FTP server on the foscam)choco install lftp
to install lftp (which will manage all mirroring)
- choose/prepare your script(s)
- you can use a shell script that includes an LFTP command, or...
- use just an LFTP script
- schedule a task trigger
- use crontab inside a jail, or...
- use FreeNAS's scheduler if you didn't use a jail, or...
- use FreeNAS's scheduler to send an SSH command to the jail (requires your jail also have SSH access conf'd)
- set your task action
- point it directly at (an executable) shell script: e.g.:
/PATH/TO/sync_foscams_simple.sh
, or... - point it at the Lftp binary and use the
-f
flag: e.g./PATH/TO/lftp -f /PATH/TO/sync_foscams_noshell.lftp
- point it directly at (an executable) shell script: e.g.:
- schedule a task trigger
- find the "Task Scheduler" app by searching via the Start menu
- choose "Create Basic Task" from the Actions section on the right side of the window
- give it a name and choose the date/time frequency for triggering it
- set your task action
- choose to "Start a program"
- point the "Program/script" box at the Lftp binary: e.g.
lftp.exe
orC:\PATH\TO\lftp.exe
- set the "Add arguments" box to
-f /cygdrive/C/PATH/TO/sync_foscams_noshell.lftp
- NOTE: in the arguments box, the standard windows "c:\whatever" syntax is replaced by "/cygdrive/c/whatever" with slashes reversed to make the Cygwin environment happy
The summarizer script
- gathers the files under every "YYYYMMDD/YYYYMMDD_hhmmss" directory (created for first video of the day or first recording after a reboot)
- sorts them by record-time alone, so SDalarm, MDalarm, and Scheduled files aren't grouped
- and losslessly combines them using ffmpeg. (i.e. you'd have to also install ffmpeg using "pkg install ffmpeg"/etc)
It's written in Bourne shell so isn't windows-box ready.
In its current form, the ffmpeg string strips the audio out and losslessly combines to a file with size equal to the video streams of all included clips. This could easily be changed to suit individual purposes. E.g.:
- re-encode at smaller dimensions
- re-encode using "time lapse"
- re-encode any/all of the above in addition to a lossless digest
- etc, etc
Ffmpeg has a daunting number of options, so I eventually plan to include some "uncomment to x/y/z" flags for common operations.