awcams 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awcams-0.1.0/LICENSE +202 -0
- awcams-0.1.0/PKG-INFO +140 -0
- awcams-0.1.0/README.md +115 -0
- awcams-0.1.0/awcams/__init__.py +13 -0
- awcams-0.1.0/awcams/_doctor.py +198 -0
- awcams-0.1.0/awcams/api.py +231 -0
- awcams-0.1.0/awcams/cli.py +378 -0
- awcams-0.1.0/awcams/config.py +169 -0
- awcams-0.1.0/awcams/daemon.py +337 -0
- awcams-0.1.0/awcams/detect.py +65 -0
- awcams-0.1.0/awcams/ha.py +238 -0
- awcams-0.1.0/awcams/media.py +235 -0
- awcams-0.1.0/awcams/retention.py +67 -0
- awcams-0.1.0/awcams/store.py +202 -0
- awcams-0.1.0/awcams/summarize.py +116 -0
- awcams-0.1.0/awcams.egg-info/PKG-INFO +140 -0
- awcams-0.1.0/awcams.egg-info/SOURCES.txt +25 -0
- awcams-0.1.0/awcams.egg-info/dependency_links.txt +1 -0
- awcams-0.1.0/awcams.egg-info/entry_points.txt +2 -0
- awcams-0.1.0/awcams.egg-info/requires.txt +6 -0
- awcams-0.1.0/awcams.egg-info/top_level.txt +1 -0
- awcams-0.1.0/pyproject.toml +36 -0
- awcams-0.1.0/setup.cfg +4 -0
- awcams-0.1.0/tests/test_daemon.py +264 -0
- awcams-0.1.0/tests/test_ha.py +78 -0
- awcams-0.1.0/tests/test_media.py +106 -0
- awcams-0.1.0/tests/test_store_api.py +290 -0
awcams-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
awcams-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awcams
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Private camera recording and one-line event summaries, on storage you own
|
|
5
|
+
Author: AitherOS
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Keywords: camera,nvr,home-assistant,ffmpeg,privacy
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Multimedia :: Video :: Capture
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Provides-Extra: vision
|
|
21
|
+
Requires-Dist: awvision>=0.3.2; extra == "vision"
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# awcams
|
|
27
|
+
|
|
28
|
+
Private camera recording and one-line event summaries, on storage you own.
|
|
29
|
+
|
|
30
|
+
awcams finds your cameras (from Home Assistant, or RTSP URLs you list), records each one
|
|
31
|
+
to your own disk in 10-minute segments, notices when something happens, describes each
|
|
32
|
+
event in one line through a local vision model, and keeps the event list in SQLite
|
|
33
|
+
behind a small read-only HTTP API.
|
|
34
|
+
|
|
35
|
+
The contract: **Point it at one RTSP camera, enable it, and read back a one-line
|
|
36
|
+
description of each event.**
|
|
37
|
+
|
|
38
|
+
## Defaults that matter
|
|
39
|
+
|
|
40
|
+
- **Every camera is off.** A newly discovered camera is neither recorded nor watched.
|
|
41
|
+
`awcams enable <camera> --by <guardian>` turns it on; the change is logged with who
|
|
42
|
+
made it (`awcams cameras --log`). `disable` stops the recorder within one poll.
|
|
43
|
+
- **No cloud, enforced.** Footage stays under the path you configure. A frame is sent
|
|
44
|
+
only to the vision endpoint you name in `AWCAMS_VISION_URL`, and only if it is on this
|
|
45
|
+
host or the home network (loopback, RFC 1918, 100.64/10) and is not a fleet router or
|
|
46
|
+
gateway port (those can fall back to a cloud model). Unset or anything else, the
|
|
47
|
+
event records `summary_error` and the frame never leaves the process.
|
|
48
|
+
- **Private on disk.** The CLI runs under umask 077 and every directory it makes is
|
|
49
|
+
0700; event frames live in `<root>/.frames`, are deleted after their look, and the
|
|
50
|
+
directory is emptied at start and removed at stop.
|
|
51
|
+
- **No face recognition.** Nothing here identifies people, and the summary prompt tells
|
|
52
|
+
the model not to.
|
|
53
|
+
- **Retention: 7 days and 200 GB**, whichever bites first; the oldest segments go first,
|
|
54
|
+
and the segment being written is never deleted. Events whose footage was pruned keep
|
|
55
|
+
their summary and say `clip_pruned` until the event rows expire too
|
|
56
|
+
(`event_retention_days`, default: the footage retention).
|
|
57
|
+
- **Codec copy.** Segments are the camera's own H.264/H.265 stream, never re-encoded.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install -e . # recording, events, API
|
|
63
|
+
pip install -e ".[vision]" # + one-line summaries through a local vision model
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`ffmpeg` must be on `PATH`. Without the vision extra, events are still recorded and
|
|
67
|
+
each one carries `summary_error` saying the vision lane is not installed.
|
|
68
|
+
|
|
69
|
+
## Use
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export AWCAMS_HA_URL=http://127.0.0.1:8123
|
|
73
|
+
export AWCAMS_HA_TOKEN=... # a Home Assistant long-lived token
|
|
74
|
+
export AWCAMS_API_TOKEN=... # required by `serve` / `run --serve`
|
|
75
|
+
export AWCAMS_VISION_URL=http://127.0.0.1:8000 # a LOCAL vision model server
|
|
76
|
+
awcams discover # cameras, their motion sensors, their source
|
|
77
|
+
awcams enable camera.front_door --by parent # record + events (or --record / --events)
|
|
78
|
+
awcams run --serve # record, detect, summarise, prune; API on :8794
|
|
79
|
+
awcams events --hours 24
|
|
80
|
+
awcams prune --dry-run
|
|
81
|
+
awcams --self-test # offline proof: exit 0 only when it passed
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
A settings file (`~/.aither/awcams/config.json`, or `--config`) holds everything else.
|
|
85
|
+
An unknown key is an error, not a shrug. Prefer Home Assistant's stream over a
|
|
86
|
+
`sources` entry: an RTSP URL with `user:pass@` is visible on ffmpeg's command line to
|
|
87
|
+
anyone on the host who can run `ps` (`awcams enable` warns when it sees one). If a camera
|
|
88
|
+
needs credentials, give awcams a camera-side read-only user.
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"root": "/srv/cams",
|
|
93
|
+
"retention_days": 7,
|
|
94
|
+
"max_gb": 200,
|
|
95
|
+
"sources": {"camera.garage": "rtsp://192.168.1.40:554/stream1"},
|
|
96
|
+
"motion_entities": {"camera.yard": ["binary_sensor.yard_occupancy"]}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## How it works
|
|
101
|
+
|
|
102
|
+
| step | how |
|
|
103
|
+
|---|---|
|
|
104
|
+
| discover | `GET /api/states` -> `camera.*`; a `binary_sensor` with device class motion/occupancy/presence named `<camera>` or `<camera>_...` pairs with it, and only with the longest such camera (override in `motion_entities`) |
|
|
105
|
+
| source | a configured RTSP URL wins; otherwise Home Assistant's `camera/stream` websocket command returns an HLS URL with a short-lived stream token, so the long-lived token never appears on an ffmpeg command line |
|
|
106
|
+
| record | `ffmpeg -c copy -f segment -segment_time 600 -strftime 1`, one process per enabled camera, restarted with backoff if it dies or if its segments stop growing for `stall_s` (180 s); its stderr is drained so a chatty stream cannot wedge it |
|
|
107
|
+
| detect | the camera's motion sensor if it has one; otherwise a Home Assistant snapshot every 5 s reduced to 32x32 grayscale and compared with the previous one |
|
|
108
|
+
| summarise | one frame per event, one look, one line; the frame is deleted afterwards (the recording is the footage) |
|
|
109
|
+
| store | SQLite: `cameras` (consent flags), `consent_log`, `events` (time, camera, trigger, summary, clip path + offset) |
|
|
110
|
+
|
|
111
|
+
## Read API
|
|
112
|
+
|
|
113
|
+
`GET /health`, `/cameras`, `/events?camera=&since=&limit=`, `/events/<id>`,
|
|
114
|
+
`/events/<id>/clip`. Read-only: nothing over HTTP can turn a camera on. It will not
|
|
115
|
+
start without `AWCAMS_API_TOKEN`, on any address, loopback included, and every route
|
|
116
|
+
but a bare `/health` (which then says only `{"ok": true}`) needs
|
|
117
|
+
`Authorization: Bearer <token>`. Requests whose `Host` is not the bind address,
|
|
118
|
+
localhost or one in `AWCAMS_API_ALLOWED_HOSTS` get 421 (DNS rebinding).
|
|
119
|
+
|
|
120
|
+
The clip route answers single byte ranges (206), so a player can seek to the event's
|
|
121
|
+
`clip_offset_s`. Browsers do not play Matroska: `/events/<id>/clip?remux=mp4` streams
|
|
122
|
+
the same footage as fragmented MP4 (codec copy, nothing written to disk), starting at
|
|
123
|
+
the event's offset or at `&start=<seconds>`.
|
|
124
|
+
|
|
125
|
+
`awcams run` stops cleanly on SIGTERM/SIGHUP (open events are closed and summarised,
|
|
126
|
+
segments closed). After a SIGKILL, the next run marks what was left open or
|
|
127
|
+
unsummarised with a `summary_error` and empties the frame directory.
|
|
128
|
+
|
|
129
|
+
## Switches
|
|
130
|
+
|
|
131
|
+
`AWCAMS=0` refuses to record or watch on this host. Settings via environment:
|
|
132
|
+
`AWCAMS_HA_URL`, `AWCAMS_HA_TOKEN` (its own token only; a shared
|
|
133
|
+
`HOME_ASSISTANT_TOKEN` is not read), `AWCAMS_ROOT`, `AWCAMS_DB`,
|
|
134
|
+
`AWCAMS_RETENTION_DAYS`, `AWCAMS_EVENT_RETENTION_DAYS`, `AWCAMS_MAX_GB`,
|
|
135
|
+
`AWCAMS_API_HOST`, `AWCAMS_API_PORT`, `AWCAMS_API_TOKEN`, `AWCAMS_API_ALLOWED_HOSTS`,
|
|
136
|
+
`AWCAMS_VISION_URL`, `AWCAMS_VISION_MODEL`.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
Apache-2.0.
|
awcams-0.1.0/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# awcams
|
|
2
|
+
|
|
3
|
+
Private camera recording and one-line event summaries, on storage you own.
|
|
4
|
+
|
|
5
|
+
awcams finds your cameras (from Home Assistant, or RTSP URLs you list), records each one
|
|
6
|
+
to your own disk in 10-minute segments, notices when something happens, describes each
|
|
7
|
+
event in one line through a local vision model, and keeps the event list in SQLite
|
|
8
|
+
behind a small read-only HTTP API.
|
|
9
|
+
|
|
10
|
+
The contract: **Point it at one RTSP camera, enable it, and read back a one-line
|
|
11
|
+
description of each event.**
|
|
12
|
+
|
|
13
|
+
## Defaults that matter
|
|
14
|
+
|
|
15
|
+
- **Every camera is off.** A newly discovered camera is neither recorded nor watched.
|
|
16
|
+
`awcams enable <camera> --by <guardian>` turns it on; the change is logged with who
|
|
17
|
+
made it (`awcams cameras --log`). `disable` stops the recorder within one poll.
|
|
18
|
+
- **No cloud, enforced.** Footage stays under the path you configure. A frame is sent
|
|
19
|
+
only to the vision endpoint you name in `AWCAMS_VISION_URL`, and only if it is on this
|
|
20
|
+
host or the home network (loopback, RFC 1918, 100.64/10) and is not a fleet router or
|
|
21
|
+
gateway port (those can fall back to a cloud model). Unset or anything else, the
|
|
22
|
+
event records `summary_error` and the frame never leaves the process.
|
|
23
|
+
- **Private on disk.** The CLI runs under umask 077 and every directory it makes is
|
|
24
|
+
0700; event frames live in `<root>/.frames`, are deleted after their look, and the
|
|
25
|
+
directory is emptied at start and removed at stop.
|
|
26
|
+
- **No face recognition.** Nothing here identifies people, and the summary prompt tells
|
|
27
|
+
the model not to.
|
|
28
|
+
- **Retention: 7 days and 200 GB**, whichever bites first; the oldest segments go first,
|
|
29
|
+
and the segment being written is never deleted. Events whose footage was pruned keep
|
|
30
|
+
their summary and say `clip_pruned` until the event rows expire too
|
|
31
|
+
(`event_retention_days`, default: the footage retention).
|
|
32
|
+
- **Codec copy.** Segments are the camera's own H.264/H.265 stream, never re-encoded.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e . # recording, events, API
|
|
38
|
+
pip install -e ".[vision]" # + one-line summaries through a local vision model
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`ffmpeg` must be on `PATH`. Without the vision extra, events are still recorded and
|
|
42
|
+
each one carries `summary_error` saying the vision lane is not installed.
|
|
43
|
+
|
|
44
|
+
## Use
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
export AWCAMS_HA_URL=http://127.0.0.1:8123
|
|
48
|
+
export AWCAMS_HA_TOKEN=... # a Home Assistant long-lived token
|
|
49
|
+
export AWCAMS_API_TOKEN=... # required by `serve` / `run --serve`
|
|
50
|
+
export AWCAMS_VISION_URL=http://127.0.0.1:8000 # a LOCAL vision model server
|
|
51
|
+
awcams discover # cameras, their motion sensors, their source
|
|
52
|
+
awcams enable camera.front_door --by parent # record + events (or --record / --events)
|
|
53
|
+
awcams run --serve # record, detect, summarise, prune; API on :8794
|
|
54
|
+
awcams events --hours 24
|
|
55
|
+
awcams prune --dry-run
|
|
56
|
+
awcams --self-test # offline proof: exit 0 only when it passed
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A settings file (`~/.aither/awcams/config.json`, or `--config`) holds everything else.
|
|
60
|
+
An unknown key is an error, not a shrug. Prefer Home Assistant's stream over a
|
|
61
|
+
`sources` entry: an RTSP URL with `user:pass@` is visible on ffmpeg's command line to
|
|
62
|
+
anyone on the host who can run `ps` (`awcams enable` warns when it sees one). If a camera
|
|
63
|
+
needs credentials, give awcams a camera-side read-only user.
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"root": "/srv/cams",
|
|
68
|
+
"retention_days": 7,
|
|
69
|
+
"max_gb": 200,
|
|
70
|
+
"sources": {"camera.garage": "rtsp://192.168.1.40:554/stream1"},
|
|
71
|
+
"motion_entities": {"camera.yard": ["binary_sensor.yard_occupancy"]}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## How it works
|
|
76
|
+
|
|
77
|
+
| step | how |
|
|
78
|
+
|---|---|
|
|
79
|
+
| discover | `GET /api/states` -> `camera.*`; a `binary_sensor` with device class motion/occupancy/presence named `<camera>` or `<camera>_...` pairs with it, and only with the longest such camera (override in `motion_entities`) |
|
|
80
|
+
| source | a configured RTSP URL wins; otherwise Home Assistant's `camera/stream` websocket command returns an HLS URL with a short-lived stream token, so the long-lived token never appears on an ffmpeg command line |
|
|
81
|
+
| record | `ffmpeg -c copy -f segment -segment_time 600 -strftime 1`, one process per enabled camera, restarted with backoff if it dies or if its segments stop growing for `stall_s` (180 s); its stderr is drained so a chatty stream cannot wedge it |
|
|
82
|
+
| detect | the camera's motion sensor if it has one; otherwise a Home Assistant snapshot every 5 s reduced to 32x32 grayscale and compared with the previous one |
|
|
83
|
+
| summarise | one frame per event, one look, one line; the frame is deleted afterwards (the recording is the footage) |
|
|
84
|
+
| store | SQLite: `cameras` (consent flags), `consent_log`, `events` (time, camera, trigger, summary, clip path + offset) |
|
|
85
|
+
|
|
86
|
+
## Read API
|
|
87
|
+
|
|
88
|
+
`GET /health`, `/cameras`, `/events?camera=&since=&limit=`, `/events/<id>`,
|
|
89
|
+
`/events/<id>/clip`. Read-only: nothing over HTTP can turn a camera on. It will not
|
|
90
|
+
start without `AWCAMS_API_TOKEN`, on any address, loopback included, and every route
|
|
91
|
+
but a bare `/health` (which then says only `{"ok": true}`) needs
|
|
92
|
+
`Authorization: Bearer <token>`. Requests whose `Host` is not the bind address,
|
|
93
|
+
localhost or one in `AWCAMS_API_ALLOWED_HOSTS` get 421 (DNS rebinding).
|
|
94
|
+
|
|
95
|
+
The clip route answers single byte ranges (206), so a player can seek to the event's
|
|
96
|
+
`clip_offset_s`. Browsers do not play Matroska: `/events/<id>/clip?remux=mp4` streams
|
|
97
|
+
the same footage as fragmented MP4 (codec copy, nothing written to disk), starting at
|
|
98
|
+
the event's offset or at `&start=<seconds>`.
|
|
99
|
+
|
|
100
|
+
`awcams run` stops cleanly on SIGTERM/SIGHUP (open events are closed and summarised,
|
|
101
|
+
segments closed). After a SIGKILL, the next run marks what was left open or
|
|
102
|
+
unsummarised with a `summary_error` and empties the frame directory.
|
|
103
|
+
|
|
104
|
+
## Switches
|
|
105
|
+
|
|
106
|
+
`AWCAMS=0` refuses to record or watch on this host. Settings via environment:
|
|
107
|
+
`AWCAMS_HA_URL`, `AWCAMS_HA_TOKEN` (its own token only; a shared
|
|
108
|
+
`HOME_ASSISTANT_TOKEN` is not read), `AWCAMS_ROOT`, `AWCAMS_DB`,
|
|
109
|
+
`AWCAMS_RETENTION_DAYS`, `AWCAMS_EVENT_RETENTION_DAYS`, `AWCAMS_MAX_GB`,
|
|
110
|
+
`AWCAMS_API_HOST`, `AWCAMS_API_PORT`, `AWCAMS_API_TOKEN`, `AWCAMS_API_ALLOWED_HOSTS`,
|
|
111
|
+
`AWCAMS_VISION_URL`, `AWCAMS_VISION_MODEL`.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
Apache-2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""awcams: private camera recording and one-line event summaries, on storage you own.
|
|
2
|
+
|
|
3
|
+
Discover cameras from Home Assistant (or name them yourself), record each one in
|
|
4
|
+
codec-copy ffmpeg segments under a path you choose with a retention cap, notice
|
|
5
|
+
events cheaply (a motion sensor if the camera has one, a 32x32 frame diff if not),
|
|
6
|
+
describe each event in one line through a local vision model, and keep the event
|
|
7
|
+
list in SQLite behind a small read-only HTTP API.
|
|
8
|
+
|
|
9
|
+
Off by default, per camera: nothing is recorded and nothing is looked at until a
|
|
10
|
+
named guardian turns it on (``awcams enable``). No cloud, no face recognition.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Stack-aware `doctor` for awcams.
|
|
2
|
+
|
|
3
|
+
GENERATED BY gen_aw_doctor.py -- DO NOT EDIT.
|
|
4
|
+
Regenerate it with the generator named above; a hand-edit here is reverted by
|
|
5
|
+
the next run and fails the parity gate.
|
|
6
|
+
|
|
7
|
+
Why a doctor exists at all: the aw* bricks are designed to COMPOSE, so the
|
|
8
|
+
interesting failures live BETWEEN them. "awcams is installed" is not the useful
|
|
9
|
+
fact -- "awcams is installed and the thing it pairs with is not" is. This reports
|
|
10
|
+
the whole stack, not just itself.
|
|
11
|
+
|
|
12
|
+
stdlib only, on purpose: a diagnostic that cannot run because a dependency is
|
|
13
|
+
missing is worthless precisely when you need it.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
#: Frozen from the Aither World registry at generation time. A shipped
|
|
23
|
+
#: package cannot read the registry, and a doctor that guessed at the family
|
|
24
|
+
#: would go stale in silence. Regenerate to update.
|
|
25
|
+
SELF = 'awcams'
|
|
26
|
+
FAMILY = [
|
|
27
|
+
'awask', 'awavatar', 'awbac', 'awbrain', 'awbrowse', 'awclassify', 'awdecide', 'awdeck',
|
|
28
|
+
'awdelphi', 'awdit', 'awembed', 'awevolve', 'awfind', 'awflow', 'awfocus', 'awgit', 'awgraph',
|
|
29
|
+
'awgym', 'awiam', 'awkno', 'awm', 'awmail', 'awmine', 'awnboard', 'awnest', 'awnet', 'awplay',
|
|
30
|
+
'awpool', 'awpredict', 'awprism', 'awprove', 'awreason', 'awrecover', 'awrecurse', 'awrelay',
|
|
31
|
+
'awrena', 'awrepl', 'awreport', 'awresearch', 'awrise', 'awrouter', 'awrtifact', 'awrun',
|
|
32
|
+
'awscope', 'awscreen', 'awseal', 'awsettings', 'awshare', 'awsprite', 'awstorage', 'awsuite',
|
|
33
|
+
'awswarm', 'awtax', 'awtoll', 'awtunnel', 'awvision', 'awvoice', 'awwall', 'gawbbonet',
|
|
34
|
+
]
|
|
35
|
+
PAIRS_WITH = ['awvision']
|
|
36
|
+
|
|
37
|
+
#: This brick's OWN config, read out of its source at generation time.
|
|
38
|
+
#: ENV_REQUIRED is `os.environ["X"]` -- absent, that is a KeyError the moment
|
|
39
|
+
#: the line runs. ENV_OPTIONAL is `os.getenv("X")`, which returns None and lets
|
|
40
|
+
#: the caller cope. Only this brick's namespace is listed: reporting the
|
|
41
|
+
#: platform-wide vars it also touches would be noise, and a doctor that floods
|
|
42
|
+
#: gets ignored.
|
|
43
|
+
ENV_REQUIRED = []
|
|
44
|
+
ENV_OPTIONAL = ['AWCAMS_API_TOKEN', 'AWCAMS_CONFIG', 'AWCAMS_HA_TOKEN']
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _installed(mod: str) -> "str | None":
|
|
48
|
+
"""Version if importable, else None. Never raises -- a broken sibling must
|
|
49
|
+
not take the diagnostic down with it."""
|
|
50
|
+
try:
|
|
51
|
+
if importlib.util.find_spec(mod) is None:
|
|
52
|
+
return None
|
|
53
|
+
except (ImportError, ValueError):
|
|
54
|
+
return None
|
|
55
|
+
try:
|
|
56
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
57
|
+
try:
|
|
58
|
+
return version(mod)
|
|
59
|
+
except PackageNotFoundError:
|
|
60
|
+
return "installed"
|
|
61
|
+
except Exception:
|
|
62
|
+
return "installed"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def report(out=None) -> int:
|
|
66
|
+
"""Print the stack picture. 0 = this brick and its pairs are present."""
|
|
67
|
+
out = out or sys.stdout
|
|
68
|
+
print(f"{SELF} doctor", file=out)
|
|
69
|
+
|
|
70
|
+
mine = _installed(SELF)
|
|
71
|
+
print(f" self {SELF} {mine or 'NOT IMPORTABLE'}", file=out)
|
|
72
|
+
shim = shutil.which(SELF)
|
|
73
|
+
print(f" command {shim or 'not on PATH'}", file=out)
|
|
74
|
+
|
|
75
|
+
# The stack. Siblings this brick pairs with are called out separately,
|
|
76
|
+
# because a missing pair is a REASON, while a missing unrelated brick is
|
|
77
|
+
# just a fact about your machine.
|
|
78
|
+
missing_pairs, present = [], []
|
|
79
|
+
for name in FAMILY:
|
|
80
|
+
v = _installed(name)
|
|
81
|
+
if v:
|
|
82
|
+
present.append(name)
|
|
83
|
+
elif name in PAIRS_WITH:
|
|
84
|
+
missing_pairs.append(name)
|
|
85
|
+
print(f" stack {len(present)}/{len(FAMILY)} aw* packages installed",
|
|
86
|
+
file=out)
|
|
87
|
+
if present:
|
|
88
|
+
print(f" {' '.join(sorted(present))}", file=out)
|
|
89
|
+
|
|
90
|
+
missing_req = [v for v in ENV_REQUIRED if not os.environ.get(v)]
|
|
91
|
+
if ENV_REQUIRED or ENV_OPTIONAL:
|
|
92
|
+
have = sum(1 for v in ENV_REQUIRED + ENV_OPTIONAL if os.environ.get(v))
|
|
93
|
+
total = len(ENV_REQUIRED) + len(ENV_OPTIONAL)
|
|
94
|
+
print(f" config {have}/{total} of this brick's own vars set", file=out)
|
|
95
|
+
if missing_req:
|
|
96
|
+
# Not a preference. os.environ[...] raises the moment it runs.
|
|
97
|
+
print(f" MISSING REQUIRED: {' '.join(missing_req)}", file=out)
|
|
98
|
+
|
|
99
|
+
local = _local_checks()
|
|
100
|
+
for line in local:
|
|
101
|
+
print(f" {line}", file=out)
|
|
102
|
+
problems, unjudged = _local_verdict()
|
|
103
|
+
|
|
104
|
+
if mine is None:
|
|
105
|
+
print(f"\nverdict: {SELF} itself is not importable. Reinstall it before "
|
|
106
|
+
f"anything else here means much.", file=out)
|
|
107
|
+
return 1
|
|
108
|
+
if missing_req:
|
|
109
|
+
print(f"\nverdict: {SELF} is missing required config "
|
|
110
|
+
f"({', '.join(missing_req)}). Those are read with os.environ[...], "
|
|
111
|
+
f"so the code path that needs them raises rather than degrades.",
|
|
112
|
+
file=out)
|
|
113
|
+
return 1
|
|
114
|
+
# A measured NO outranks a missing optional pair: awrise printed
|
|
115
|
+
# "nothing wakes run-due" and still exited 0 because the missing-pairs
|
|
116
|
+
# branch returned first (measured 2026-09-20).
|
|
117
|
+
if problems:
|
|
118
|
+
for p in problems:
|
|
119
|
+
print(f"\nverdict: {p}", file=out)
|
|
120
|
+
return 1
|
|
121
|
+
if unjudged:
|
|
122
|
+
for u in unjudged:
|
|
123
|
+
print(f"\nverdict: UNJUDGED -- could not judge: {u}", file=out)
|
|
124
|
+
return 2
|
|
125
|
+
if missing_pairs:
|
|
126
|
+
print(f"\nverdict: {SELF} works, but pairs with "
|
|
127
|
+
f"{', '.join(sorted(missing_pairs))} which "
|
|
128
|
+
f"{'is' if len(missing_pairs) == 1 else 'are'} not installed. "
|
|
129
|
+
f"That is a capability you are missing, not an error.", file=out)
|
|
130
|
+
return 0
|
|
131
|
+
print(f"\nverdict: {SELF} and everything it pairs with are present.", file=out)
|
|
132
|
+
return 0
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _local_verdict() -> tuple:
|
|
136
|
+
"""The brick's OWN verdict, folded into the exit code.
|
|
137
|
+
|
|
138
|
+
Without this the local lines are DECORATION. Measured 2026-09-20: awrise
|
|
139
|
+
printed "hostclock NOT INSTALLED -- nothing wakes run-due" and "last tick
|
|
140
|
+
never", then exited 0 -- teaching an operator that a doctor exit code
|
|
141
|
+
carries no information. A brick opts in with `_doctor_local_verdict()`
|
|
142
|
+
returning (problems, unjudged); a brick without one is unaffected.
|
|
143
|
+
"""
|
|
144
|
+
try:
|
|
145
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
146
|
+
problems, unjudged = mod._doctor_local_verdict()
|
|
147
|
+
except Exception: # noqa: BLE001
|
|
148
|
+
return [], []
|
|
149
|
+
return list(problems or []), list(unjudged or [])
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _local_checks() -> "list[str]":
|
|
153
|
+
"""Per-brick checks, if this package defines them.
|
|
154
|
+
|
|
155
|
+
Kept as a HOOK rather than generated guesses: the generator knows the family
|
|
156
|
+
from the registry, but it does not know what awcams needs at runtime, and a
|
|
157
|
+
doctor that invented config requirements would be confidently wrong. A
|
|
158
|
+
package supplies `_doctor_local()` returning display lines; absent, the
|
|
159
|
+
stack picture above still stands on its own.
|
|
160
|
+
"""
|
|
161
|
+
try:
|
|
162
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
163
|
+
except Exception:
|
|
164
|
+
return []
|
|
165
|
+
try:
|
|
166
|
+
return list(mod._doctor_local())
|
|
167
|
+
except Exception as exc: # noqa: BLE001
|
|
168
|
+
return [f"local checks raised {type(exc).__name__}: {exc}"]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def main(argv: "list[str] | None" = None) -> int:
|
|
172
|
+
# --self-test delegates to a SIBLING module when one exists.
|
|
173
|
+
#
|
|
174
|
+
# This file is generated and a fresh run replaces it, so a self-test
|
|
175
|
+
# written HERE is deleted by the next regeneration. awdelphi learned that
|
|
176
|
+
# the expensive way: 125 lines exercising four real failure paths --
|
|
177
|
+
# convergence, roster anonymization, resume, gateway-down -- lived in this
|
|
178
|
+
# file and were destroyed by a routine regeneration, silently, leaving a
|
|
179
|
+
# --self-test flag that reported PASS while asserting nothing.
|
|
180
|
+
#
|
|
181
|
+
# So the seam is a separate module the generator never writes. A package
|
|
182
|
+
# with real machinery to prove puts it in _selftest.py; everything else
|
|
183
|
+
# keeps the honest answer below rather than a self-test that only ever
|
|
184
|
+
# passes.
|
|
185
|
+
argv = list(argv if argv is not None else __import__("sys").argv[1:])
|
|
186
|
+
if "--self-test" in argv:
|
|
187
|
+
try:
|
|
188
|
+
from . import _selftest as _st
|
|
189
|
+
except Exception:
|
|
190
|
+
print("no _selftest module: this doctor reports the stack, and has",
|
|
191
|
+
"no machinery of its own to prove")
|
|
192
|
+
return 0
|
|
193
|
+
return int(_st.run())
|
|
194
|
+
return report()
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if __name__ == "__main__":
|
|
198
|
+
raise SystemExit(main())
|