Simpe AWS lambda function to create a timelapse movie by creating periodic snapshots using a NetGear Arlo Pro Camera and ffmpeg (on a local machine)
When looking for a way to create a timelapse using a Arlo camera I bumped into Jeffrey d Walter's Arlo python library that has all the functionality required. Running the code on AWS lambda provides a cheap (first year should be within the AWS free tier) and hassle-free way to host such a repeating task.
The script works like this:
- AWS triggers a snapshot every 10 minutes (configurable in AWS)
- Lambda function triggers a snapshot through the Arlo cloud endpoint
- Lambda function retrieves and stores the snapshot in a private S3 bucket
- On your desktop: grab all images and construct a timelapse uing ffmpeg
Below are the steps I took (roughly) to get everything up and running on OSX (other platforms should also work, but the commands will be a bit different)
This script is open-sourced under the MIT license; please use and distribute as you wish. There are no warranties; use at your own risk. Contributions are welcome
Install python - or you can install it using homebrew (OSX)
Install pipenv
pip3 install --user pipenv
depending on your install the command could be 'pip' instead of 'pip3'. I had to run the commands below to set up the enviroment properly
export LC_LOCAL=en_US.UTF-8
export LANG=en_US.UTF-8
git clone https://github.com/Notalifeform/arlo-timelapse-lambda
In your project directory run
pipenv install
The aws library boto3 uses the aws CLI configuration to access S3, we'll also use it later to retrieve the snapshots.
brew install awscli
First sign up for an AWS account
Make sure the aws cli and python can write to aws S3
- create bucket
- create user
- assign S3 full rights to user
- setup was cli access key locally
see https://boto3.readthedocs.io/en/latest/guide/quickstart.html
set up your environment
export [email protected]
export ARLO_PASSWORD=password
export S3_BUCKET_NAME=my.bucket.name
then run
make run
it should output something like
pipenv run python ./arlosnapshot.py
Looking up sequence number
Creating ARLO snapshot 1
retrieving and storing snapshot_2018-02-10_23-03-18_000000143.jpg
Script complete at 2018-02-10 23:03:24.209948
in your project directory run
make clean && make build
This is a good start to create a first version of your function
https://docs.aws.amazon.com/lambda/latest/dg/with-scheduledevents-example.html
When you upload delivery.zip
make sure to set the handler to arlosnapshot.lambda_handler
The trigger you can set to something like */10 6-18 ? * MON-FRI *
(in this case: weekday create a snapshot every 10 minutes from 6AM to 6PM - GMT)
brew install libvpx
brew install ffmpeg --with-libvpx
Run from your snapshot dir (asuming it is next to your project dir)
../snapshot-lambda/tools/create-slideshow.sh
this should
- download all your snapshots
- symlink them so ffmpeg can find them
- create a movie using ffmpeg
the ffmpeg command line will probably need some tuning to fit your situation/preferences
Big thanks to jeffdwalter for providing the pyhton library and quickly fixing a threading issue that I ran into using this library on AWS Lambda.
- arlo pyhton library - https://github.com/jeffreydwalter/arlo
- make files for AWS Lambda - https://github.com/browniebroke/hello-lambda
- ffmpeg commands for creating slideshows - http://hamelot.io/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/