GithubHelp home page GithubHelp logo

notalifeform / arlo-timelapse-lambda Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 5.0 20 KB

Simpe AWS lambda function to create a timelapse using a NetGear Arlo Pro Camera and ffmpeg.

License: MIT License

Makefile 1.55% Python 97.41% Shell 1.04%

arlo-timelapse-lambda's Introduction

arlo-timelapse-lambda

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)

Introduction

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

Setup environment and dependencies

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

Clone this project

git clone https://github.com/Notalifeform/arlo-timelapse-lambda

Install required pyhton libraries

In your project directory run

pipenv install

Install aws CLI

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 

AWS setup S3

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

Test locally

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

Create distribution

in your project directory run

make clean && make build

Upload your code to AWS Lambda

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)

Downloading pictures and creating the timelapse

Install dependencies

brew install libvpx
brew install ffmpeg --with-libvpx

Create the timelapse

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

Thank you

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.

See also

arlo-timelapse-lambda's People

Contributors

notalifeform avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

arlo-timelapse-lambda's Issues

Lambda function fails during test

After I create a new lambda function and test I am getting following error. Have you seen this or know what could cause this. I am able to run locally fine.

Traceback (most recent call last):
File "/var/task/arlosnapshot.py", line 33, in lambda_handler
s3.Bucket(S3_BUCKET_NAME).download_file('sequence.txt', '/tmp/sequence.txt')
File "/var/task/boto3/s3/inject.py", line 246, in bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "/var/task/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/var/task/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/var/task/s3transfer/futures.py", line 73, in result
return self._coordinator.result()
File "/var/task/s3transfer/futures.py", line 233, in result
raise self._exception
File "/var/task/s3transfer/tasks.py", line 255, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/var/task/s3transfer/download.py", line 353, in _submit
**transfer_future.meta.call_args.extra_args
File "/var/task/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/task/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.