Pynopticon
Project description
Pynopticon
Pynopticon is a video recording utility that saves the last n
frames before an interesting event to disk. This is an efficient way to monitor and record systems where you care only about certain moments, and only have information ex post facto (like a crash on a robotic system).
Using the server you can always see a live video feed.
import time
from pynopticon import Pynopticon
p = Pynopticon(
record_frames=100,
width=640,
height=480,
cam=0
)
p.start()
time.sleep(10)
p.save(
outname="my_video.mp4",
fps=30,
)
Features
YouTube Upload
Optionally, you can upload the video to YouTube. This requires a client_secrets.json
file, see instructions here.
import time
from pynopticon import Pynopticon, get_authenticated_service
youtube = get_authenticated_service(client_secrets_file="./client_secrets.json") # initialize youtube
p = Pynopticon(record_frames=100, youtube=youtube)
p.start()
time.sleep(10)
p.save(upload=True, title="My Video", description="My Description")
Email Notification
If uploading to YouTube, you can also send an email when a video is saved.
import time
from pynopticon import Pynopticon, get_authenticated_service
import sendgrid
sg = sendgrid.SendGridAPIClient(api_key=sendgrid_api_key) # initialize sendgrid
youtube = get_authenticated_service(client_secrets_file="./client_secrets.json")
p = Pynopticon(record_frames=100, youtube=youtube, sg=sg)
p.start()
time.sleep(10)
p.save(
upload=True,
title="My Video", description="My Description",
to_email=["me@example.com", "other@example.com"],from_email="you@sendgrid.com")
HTTP API
There is also a server that exposes an http api, in case if you want to run Pynopticon on an external device.
# without YouTube upload:
python -m pynopticon
# with YouTube upload:
CLIENT_SECRETS_FILE="client_secrets.json" python -m pynopticon
api:
/
: visit in browser for live streaming.POST /start
: same asp.start()
(after stop, server auto starts pynopticon instance).POST /save
: same asp.save()
.- Set
?upload=true
to upload to YouTube. Only works ifCLIENT_SECRETS_FILE
is set. - Set
?emails=one@example.com,two@example.com
to send an email to the given emails. Only works ifSENDGRID_API_KEY
,SENDGRID_FROM
are set, andupload=true
.
- Set
POST /stop
: same asp.stop()
.
config:
RECORD_FRAMES
: number of frames to record before an event. Default:100
PORT
: port to run server on. Default:4004
HOST
: host to run server on. Default:0.0.0.0
CAM
: camera index. Default:0
WIDTH
: width of camera. Default:640
HEIGHT
: height of camera. Default:480
If you want to upload to YouTube, you should set the following environment variables:
CLIENT_SECRETS_FILE
: path toclient_secrets.json
file. Default:None
If all three of the following are set, the server will send an email when a video is uploaded to YT. If just some are set, an error will be raised.
SENDGRID_API_KEY
: sendgrid api key. Default:None
SENDGRID_FROM
: sendgrid from email. Default:None
Live Streaming
See HTTP API section above.
Installation
Requires OpenCV!
- from pip
pip install pynopticon # basic
pip install 'pynopticon[all]' # all
pip install 'pynopticon[mail]' # mail
pip install 'pynopticon[yt]' # yt
pip install 'pynopticon[server]' # server
- from source
git clone https://github.com/rickwierenga/pynopticon
Cameras
Plug in a webcam/camera to your computer. We use this one ($50) in lab, but you should be able to use any USB webcam / camera.
Tip: You can use v4l2-ctl --list-devices
on Linux to find the value you need to pass to CAM
. This is particularly useful if you're going to be running multiple instances of the Pynopticon.
Informative
Developed for the Sculpting Evolution Group at the MIT Media Lab
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Pynopticon-0.0.7.tar.gz
.
File metadata
- Download URL: Pynopticon-0.0.7.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90de29459a6abd2dde2e1814b4008f705cb425733019dd1de8dff2e9abf76029 |
|
MD5 | 6e0d65aa4a94b4d43485c52a662f24da |
|
BLAKE2b-256 | 449fbdcbc5285cc7c05244a19fd5d346b47dd29f00a2215308ff3ab781bee297 |
File details
Details for the file Pynopticon-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: Pynopticon-0.0.7-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed54c25d9113da4b1b7624957a44b124083c4d528565c0e7961f901dc45926ec |
|
MD5 | 3af6fabbd108cd70d04e708a5e42b55c |
|
BLAKE2b-256 | 76dfb4b05223c9438db2ed9ac61d3d2c7f6157be4d48d5c9313157b38de38468 |