@camera.ui/camera-ui-pamdiff 0.0.1
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.
- package/CHANGELOG.md +8 -0
- package/CONTRIBUTING.md +1 -0
- package/LICENSE.md +22 -0
- package/README.md +1 -0
- package/dist/camera.d.ts +15 -0
- package/dist/camera.js +122 -0
- package/dist/camera.js.map +1 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +37 -0
- package/dist/constants.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +8 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/videoanalysis.d.ts +25 -0
- package/dist/videoanalysis.js +223 -0
- package/dist/videoanalysis.js.map +1 -0
- package/example-config.json +1 -0
- package/package.json +56 -0
- package/types/pam-diff.d.ts +86 -0
- package/types/pipe2pam.d.ts +34 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
All notable changes to this project will be documented in this file.
|
|
2
|
+
|
|
3
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
4
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
|
|
6
|
+
## [X.X.X] - ???
|
|
7
|
+
|
|
8
|
+
- Initial Release
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Contributing
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2024 seydx <dev@seydx.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @camera.ui/camera-ui-pamdiff
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CameraStorage } from '@camera.ui/types';
|
|
2
|
+
import type { CameraDevice } from '@camera.ui/types';
|
|
3
|
+
import type { PamDiff } from '.';
|
|
4
|
+
export declare class CameraVideoanalysis {
|
|
5
|
+
cameraStorage: CameraStorage;
|
|
6
|
+
private platform;
|
|
7
|
+
private logger;
|
|
8
|
+
private cameraDevice;
|
|
9
|
+
private videoanalysisObj?;
|
|
10
|
+
constructor(platform: PamDiff, cameraDevice: CameraDevice);
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
kill(): Promise<void>;
|
|
13
|
+
setupStream(newSource: string): Promise<void>;
|
|
14
|
+
reconfigureSources(): Promise<void>;
|
|
15
|
+
}
|
package/dist/camera.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CameraVideoanalysis = void 0;
|
|
4
|
+
const videoanalysis_1 = require("./videoanalysis");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
class CameraVideoanalysis {
|
|
7
|
+
cameraStorage;
|
|
8
|
+
platform;
|
|
9
|
+
logger;
|
|
10
|
+
cameraDevice;
|
|
11
|
+
videoanalysisObj;
|
|
12
|
+
constructor(platform, cameraDevice) {
|
|
13
|
+
this.platform = platform;
|
|
14
|
+
this.logger = platform.logger;
|
|
15
|
+
this.cameraDevice = cameraDevice;
|
|
16
|
+
}
|
|
17
|
+
async start() {
|
|
18
|
+
this.cameraStorage = await this.platform.storage.createCameraStorage(this, this.cameraDevice.id, {
|
|
19
|
+
analyzedStream: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
key: 'analyzedStream',
|
|
22
|
+
title: 'Analyzed stream',
|
|
23
|
+
description: 'Select which stream should be analyzed',
|
|
24
|
+
group: 'Manage',
|
|
25
|
+
enum: this.cameraDevice.sources.filter((source) => source.roles.includes('detect')).map((source) => source.name),
|
|
26
|
+
store: true,
|
|
27
|
+
onSet: (newSource) => {
|
|
28
|
+
this.setupStream(newSource);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
this.cameraDevice.onPropertyChange('sources').subscribe(async () => {
|
|
33
|
+
let analyzedStream = await this.cameraStorage.getValue('analyzedStream');
|
|
34
|
+
const orphanedStream = Boolean(analyzedStream && !this.cameraDevice.sources.some((s) => s.name === analyzedStream));
|
|
35
|
+
if (orphanedStream) {
|
|
36
|
+
await this.videoanalysisObj?.stream.kill();
|
|
37
|
+
await this.cameraStorage.removeSchema(analyzedStream);
|
|
38
|
+
this.videoanalysisObj = undefined;
|
|
39
|
+
analyzedStream = undefined;
|
|
40
|
+
}
|
|
41
|
+
await this.videoanalysisObj?.stream.restart();
|
|
42
|
+
await this.cameraStorage.setValue('analyzedStream', analyzedStream);
|
|
43
|
+
await this.cameraStorage.changeSchema('analyzedStream', {
|
|
44
|
+
enum: this.cameraDevice.sources.filter((source) => source.roles.includes('detect')).map((source) => source.name),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const analyzedStream = await this.cameraStorage.getValue('analyzedStream');
|
|
48
|
+
if (analyzedStream) {
|
|
49
|
+
this.setupStream(analyzedStream);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async kill() {
|
|
53
|
+
await this.videoanalysisObj?.stream.kill();
|
|
54
|
+
this.videoanalysisObj = undefined;
|
|
55
|
+
}
|
|
56
|
+
async setupStream(newSource) {
|
|
57
|
+
if (this.videoanalysisObj && this.videoanalysisObj?.name !== newSource) {
|
|
58
|
+
await this.videoanalysisObj.stream.kill();
|
|
59
|
+
await this.cameraStorage.removeSchema(this.videoanalysisObj.name);
|
|
60
|
+
}
|
|
61
|
+
const cameraSource = this.cameraDevice.sources.find((s) => s.name === newSource);
|
|
62
|
+
if (cameraSource) {
|
|
63
|
+
const analyzedStream = new videoanalysis_1.VideoanalysisService(this.cameraDevice, this.cameraStorage, cameraSource, this.logger);
|
|
64
|
+
await analyzedStream.start();
|
|
65
|
+
this.videoanalysisObj = { name: newSource, stream: analyzedStream };
|
|
66
|
+
}
|
|
67
|
+
await this.reconfigureSources();
|
|
68
|
+
}
|
|
69
|
+
async reconfigureSources() {
|
|
70
|
+
const analyzedStreamsConfig = await this.cameraStorage.getValue('analyzedStream');
|
|
71
|
+
const analyzedStreamsSchema = this.cameraStorage.getSchema('analyzedStream');
|
|
72
|
+
if (analyzedStreamsSchema) {
|
|
73
|
+
for (const source of analyzedStreamsSchema.enum) {
|
|
74
|
+
await this.cameraStorage.removeSchema(source);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const source = this.cameraDevice.sources.find((s) => s.name === analyzedStreamsConfig);
|
|
78
|
+
if (source) {
|
|
79
|
+
const group = `Stream: ${source.name}`;
|
|
80
|
+
const schema = {};
|
|
81
|
+
schema[source.name] = {
|
|
82
|
+
type: 'object',
|
|
83
|
+
key: source.name,
|
|
84
|
+
title: 'Settings',
|
|
85
|
+
description: 'Settings',
|
|
86
|
+
opened: true,
|
|
87
|
+
group,
|
|
88
|
+
properties: {
|
|
89
|
+
difference: {
|
|
90
|
+
type: 'number',
|
|
91
|
+
key: 'difference',
|
|
92
|
+
title: 'Motion Difference',
|
|
93
|
+
description: 'The color difference required to trigger motion on a pixel',
|
|
94
|
+
defaultValue: constants_1.DEFAULT_DIFFERENCE,
|
|
95
|
+
minimum: 1,
|
|
96
|
+
maximum: 255,
|
|
97
|
+
store: true,
|
|
98
|
+
onSet: (newValue) => {
|
|
99
|
+
this.videoanalysisObj?.stream.reconfigure({ difference: newValue });
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
percentage: {
|
|
103
|
+
type: 'number',
|
|
104
|
+
key: 'percentage',
|
|
105
|
+
title: 'Motion Percent',
|
|
106
|
+
description: 'The percentage of pixels required to trigger motion',
|
|
107
|
+
defaultValue: constants_1.DEFAULT_PERCENTAGE,
|
|
108
|
+
minimum: 0,
|
|
109
|
+
maximum: 100,
|
|
110
|
+
store: true,
|
|
111
|
+
onSet: (newValue) => {
|
|
112
|
+
this.videoanalysisObj?.stream.reconfigure({ percentage: newValue });
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
await this.cameraStorage.addSchema(schema);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.CameraVideoanalysis = CameraVideoanalysis;
|
|
122
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":";;;AAEA,mDAAuD;AACvD,2CAAqE;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;aACF,CAAC;YAEF,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AArID,kDAqIC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CameraZone } from '@camera.ui/types';
|
|
2
|
+
export declare const DEFAULT_PERCENTAGE = 2;
|
|
3
|
+
export declare const DEFAULT_DIFFERENCE = 9;
|
|
4
|
+
export declare const FFMPEG_MODE = "rgb24";
|
|
5
|
+
export declare const FFMPEG_RESOLUTION = "640:360";
|
|
6
|
+
export declare const FFMPEG_FPS = "2";
|
|
7
|
+
export declare const DEFAULT_ZONE: CameraZone[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ZONE = exports.FFMPEG_FPS = exports.FFMPEG_RESOLUTION = exports.FFMPEG_MODE = exports.DEFAULT_DIFFERENCE = exports.DEFAULT_PERCENTAGE = void 0;
|
|
4
|
+
exports.DEFAULT_PERCENTAGE = 2;
|
|
5
|
+
exports.DEFAULT_DIFFERENCE = 9;
|
|
6
|
+
exports.FFMPEG_MODE = 'rgb24'; // gray, rgba, rgb24
|
|
7
|
+
exports.FFMPEG_RESOLUTION = '640:360';
|
|
8
|
+
exports.FFMPEG_FPS = '2';
|
|
9
|
+
exports.DEFAULT_ZONE = [
|
|
10
|
+
{
|
|
11
|
+
name: 'default',
|
|
12
|
+
regions: [
|
|
13
|
+
{
|
|
14
|
+
_id: '0',
|
|
15
|
+
coords: [
|
|
16
|
+
{
|
|
17
|
+
_id: '1',
|
|
18
|
+
points: [0, 100],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
_id: '2',
|
|
22
|
+
points: [0, 0],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
_id: '3',
|
|
26
|
+
points: [100, 0],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
_id: '4',
|
|
30
|
+
points: [100, 100],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,kBAAkB,GAAG,CAAC,CAAC;AAEvB,QAAA,kBAAkB,GAAG,CAAC,CAAC;AAEvB,QAAA,WAAW,GAAG,OAAO,CAAC,CAAC,oBAAoB;AAE3C,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE9B,QAAA,UAAU,GAAG,GAAG,CAAC;AAEjB,QAAA,YAAY,GAAiB;IACxC;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE;YACP;gBACE,GAAG,EAAE,GAAG;gBACR,MAAM,EAAE;oBACN;wBACE,GAAG,EAAE,GAAG;wBACR,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC;qBACjB;oBACD;wBACE,GAAG,EAAE,GAAG;wBACR,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;qBACf;oBACD;wBACE,GAAG,EAAE,GAAG;wBACR,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;qBACjB;oBACD;wBACE,GAAG,EAAE,GAAG;wBACR,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;qBACnB;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAmB;IAC5C,UAAU,EAAE,8BAA8B;IAC1C,SAAS,EAAE,iBAAiB;CAC7B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BasePlugin } from '@camera.ui/types';
|
|
2
|
+
import type { API, PluginLogger, PluginConfigService, Storage, CameraDevice } from '@camera.ui/types';
|
|
3
|
+
declare const _default: (api: API) => void;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare class PamDiff extends BasePlugin {
|
|
6
|
+
private analyzedCameras;
|
|
7
|
+
constructor(pluginId: string, log: PluginLogger, configService: PluginConfigService, storage: Storage, api: API);
|
|
8
|
+
private start;
|
|
9
|
+
private stop;
|
|
10
|
+
configureCameras(cameras: CameraDevice[]): Promise<void>;
|
|
11
|
+
configureCamera(cameraDevice: CameraDevice): Promise<void>;
|
|
12
|
+
removeCamera(cameraId: string): Promise<void>;
|
|
13
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PamDiff = void 0;
|
|
4
|
+
const types_1 = require("@camera.ui/types");
|
|
5
|
+
const contract_1 = require("./contract");
|
|
6
|
+
const camera_1 = require("./camera");
|
|
7
|
+
exports.default = (api) => api.registerPlugin(PamDiff, contract_1.pluginContract);
|
|
8
|
+
class PamDiff extends types_1.BasePlugin {
|
|
9
|
+
analyzedCameras = new Map();
|
|
10
|
+
constructor(pluginId, log, configService, storage, api) {
|
|
11
|
+
super(pluginId, log, configService, storage, api);
|
|
12
|
+
this.api.on('finishLaunching', this.start.bind(this));
|
|
13
|
+
this.api.on('shutdown', this.stop.bind(this));
|
|
14
|
+
}
|
|
15
|
+
async start() {
|
|
16
|
+
this.api.deviceManager.listen('cameraSelected', async (cameraDevice) => {
|
|
17
|
+
await this.configureCamera(cameraDevice);
|
|
18
|
+
});
|
|
19
|
+
this.api.deviceManager.listen('cameraDeselected', async (cameraId) => {
|
|
20
|
+
await this.removeCamera(cameraId);
|
|
21
|
+
});
|
|
22
|
+
this.api.deviceManager.listen('cameraRemoved', async (cameraId) => {
|
|
23
|
+
await this.removeCamera(cameraId);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async stop() {
|
|
27
|
+
for (const [cameraId, analyzedCamera] of this.analyzedCameras) {
|
|
28
|
+
await analyzedCamera.kill();
|
|
29
|
+
this.analyzedCameras.delete(cameraId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async configureCameras(cameras) {
|
|
33
|
+
for (const camera of cameras) {
|
|
34
|
+
await this.configureCamera(camera);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async configureCamera(cameraDevice) {
|
|
38
|
+
this.logger.log('Configuring Camera:', cameraDevice.name);
|
|
39
|
+
const cameraPrebuffer = new camera_1.CameraVideoanalysis(this, cameraDevice);
|
|
40
|
+
await cameraPrebuffer.start();
|
|
41
|
+
this.cameras.set(cameraDevice.id, cameraDevice);
|
|
42
|
+
this.analyzedCameras.set(cameraDevice.id, cameraPrebuffer);
|
|
43
|
+
}
|
|
44
|
+
async removeCamera(cameraId) {
|
|
45
|
+
const cameraDevice = this.cameras.get(cameraId);
|
|
46
|
+
if (cameraDevice) {
|
|
47
|
+
this.logger.log('Removing Camera:', cameraDevice.name);
|
|
48
|
+
await this.analyzedCameras.get(cameraId)?.kill();
|
|
49
|
+
this.analyzedCameras.delete(cameraId);
|
|
50
|
+
this.cameras.delete(cameraId);
|
|
51
|
+
this.storage.removeCameraStorage(cameraId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.PamDiff = PamDiff;
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAE9C,yCAA4C;AAC5C,qCAA+C;AAI/C,kBAAe,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,yBAAc,CAAC,CAAC;AAEzE,MAAa,OAAQ,SAAQ,kBAAU;IAC7B,eA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pam-diff.d.ts" />
|
|
2
|
+
/// <reference path="../types/pipe2pam.d.ts" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { ChildProcess } from 'child_process';
|
|
5
|
+
import type P2P from 'pipe2pam';
|
|
6
|
+
import type PamDiff from 'pam-diff';
|
|
7
|
+
export interface VideoanalysisSession {
|
|
8
|
+
isActive(): boolean;
|
|
9
|
+
kill: (reason?: string) => void;
|
|
10
|
+
cp: ChildProcess;
|
|
11
|
+
pamDiff: PamDiff;
|
|
12
|
+
p2p: P2P;
|
|
13
|
+
}
|
|
14
|
+
export interface PamDiffRegion {
|
|
15
|
+
name: string;
|
|
16
|
+
difference?: number;
|
|
17
|
+
percent?: number;
|
|
18
|
+
polygon?: PamDiffCoords[];
|
|
19
|
+
}
|
|
20
|
+
export interface PamDiffCoords {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAwBA,kDAAkD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PluginLogger, CameraDevice, CameraInput, CameraStorage } from '@camera.ui/types';
|
|
2
|
+
export declare class VideoanalysisService {
|
|
3
|
+
private cameraDevice;
|
|
4
|
+
private cameraStorage;
|
|
5
|
+
private logger;
|
|
6
|
+
private source;
|
|
7
|
+
private killed;
|
|
8
|
+
private stopped;
|
|
9
|
+
private ffmpegPath;
|
|
10
|
+
private videoanalysisSession?;
|
|
11
|
+
private watchdog?;
|
|
12
|
+
constructor(cameraDevice: CameraDevice, cameraStorage: CameraStorage, source: CameraInput, logger: PluginLogger);
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
stop(kill?: boolean): Promise<void>;
|
|
15
|
+
kill(): Promise<void>;
|
|
16
|
+
restart(): Promise<void>;
|
|
17
|
+
reconfigure({ difference, percentage }: {
|
|
18
|
+
difference?: number;
|
|
19
|
+
percentage?: number;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
private startVideoanalysis;
|
|
22
|
+
private reset;
|
|
23
|
+
private getCameraRegions;
|
|
24
|
+
private getLogPrefix;
|
|
25
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VideoanalysisService = void 0;
|
|
7
|
+
const pipe2pam_1 = __importDefault(require("pipe2pam"));
|
|
8
|
+
const pam_diff_1 = __importDefault(require("pam-diff"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
12
|
+
class VideoanalysisService {
|
|
13
|
+
cameraDevice;
|
|
14
|
+
cameraStorage;
|
|
15
|
+
logger;
|
|
16
|
+
source;
|
|
17
|
+
killed = false;
|
|
18
|
+
stopped = false;
|
|
19
|
+
ffmpegPath;
|
|
20
|
+
videoanalysisSession;
|
|
21
|
+
watchdog;
|
|
22
|
+
constructor(cameraDevice, cameraStorage, source, logger) {
|
|
23
|
+
this.cameraDevice = cameraDevice;
|
|
24
|
+
this.cameraStorage = cameraStorage;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
this.ffmpegPath = process.env.CAMERA_UI_FFMPEG_BINARY;
|
|
27
|
+
this.source = source;
|
|
28
|
+
this.cameraDevice.onPropertyChange('motionZones').subscribe(async () => {
|
|
29
|
+
this.logger.log(this.getLogPrefix(), 'Updating videoanalysis regions', this.cameraDevice.motionZones);
|
|
30
|
+
this.videoanalysisSession?.pamDiff.setRegions(this.getCameraRegions());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async start() {
|
|
34
|
+
try {
|
|
35
|
+
this.stopped = false;
|
|
36
|
+
this.logger.log(this.getLogPrefix(), 'Starting videoanalysis');
|
|
37
|
+
this.videoanalysisSession = await this.startVideoanalysis();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
this.reset();
|
|
41
|
+
this.logger.error(this.getLogPrefix(), 'An error occured during starting videoanalysis!', error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async stop(kill) {
|
|
45
|
+
this.stopped = kill || false;
|
|
46
|
+
this.logger.log(this.getLogPrefix(), 'Stopping videoanalysis session');
|
|
47
|
+
this.reset();
|
|
48
|
+
}
|
|
49
|
+
async kill() {
|
|
50
|
+
this.killed = true;
|
|
51
|
+
await this.stop(true);
|
|
52
|
+
}
|
|
53
|
+
async restart() {
|
|
54
|
+
this.logger.log(this.getLogPrefix(), 'Restarting videoanalysis session in 5s...');
|
|
55
|
+
this.stop(true);
|
|
56
|
+
await sleep(5000);
|
|
57
|
+
if (!this.killed) {
|
|
58
|
+
await this.start();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.logger.log(this.getLogPrefix(), 'Videoanalysis restart aborted, plugin is killed!');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async reconfigure({ difference, percentage }) {
|
|
65
|
+
this.logger.log(this.getLogPrefix(), 'Reconfiguring videoanalysis...');
|
|
66
|
+
if (this.videoanalysisSession) {
|
|
67
|
+
percentage = percentage || this.videoanalysisSession.pamDiff.percent;
|
|
68
|
+
difference = difference || this.videoanalysisSession.pamDiff.difference;
|
|
69
|
+
this.logger.log(this.getLogPrefix(), `New configuration: ${percentage}% / ${difference}`);
|
|
70
|
+
this.videoanalysisSession.pamDiff.setPercent(percentage);
|
|
71
|
+
this.videoanalysisSession.pamDiff.setDifference(difference);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async startVideoanalysis() {
|
|
75
|
+
if (this.videoanalysisSession) {
|
|
76
|
+
return this.videoanalysisSession;
|
|
77
|
+
}
|
|
78
|
+
let errors = [];
|
|
79
|
+
let motionTimeout;
|
|
80
|
+
let ffmpegTimeout;
|
|
81
|
+
let isActive = true;
|
|
82
|
+
const ffmpegArguments = [
|
|
83
|
+
'-hide_banner',
|
|
84
|
+
'-v',
|
|
85
|
+
'error',
|
|
86
|
+
//'-hwaccel',
|
|
87
|
+
//'auto',
|
|
88
|
+
'-fflags',
|
|
89
|
+
'nobuffer',
|
|
90
|
+
'-flags',
|
|
91
|
+
'low_delay',
|
|
92
|
+
'-timeout',
|
|
93
|
+
'5000000',
|
|
94
|
+
'-user_agent',
|
|
95
|
+
'camera.ui/pamdiff',
|
|
96
|
+
'-fflags',
|
|
97
|
+
'+genpts',
|
|
98
|
+
'-rtsp_transport',
|
|
99
|
+
'tcp',
|
|
100
|
+
'-i',
|
|
101
|
+
this.source.urls.rtsp.single,
|
|
102
|
+
'-an',
|
|
103
|
+
'-vcodec',
|
|
104
|
+
'pam',
|
|
105
|
+
'-pix_fmt',
|
|
106
|
+
constants_1.FFMPEG_MODE,
|
|
107
|
+
'-f',
|
|
108
|
+
'image2pipe',
|
|
109
|
+
'-vf',
|
|
110
|
+
`fps=${constants_1.FFMPEG_FPS},scale=${constants_1.FFMPEG_RESOLUTION}`,
|
|
111
|
+
'pipe:1',
|
|
112
|
+
];
|
|
113
|
+
const difference = await this.cameraStorage.getValue(`${this.source.name}.difference`);
|
|
114
|
+
const percent = await this.cameraStorage.getValue(`${this.source.name}.percentage`);
|
|
115
|
+
const regions = this.getCameraRegions();
|
|
116
|
+
this.logger.debug(this.getLogPrefix(), `Videoanalysis command: ${this.ffmpegPath} ${ffmpegArguments.join(' ')}`);
|
|
117
|
+
this.logger.debug(this.getLogPrefix(), 'Videoanalysis configuration: ', JSON.stringify({ difference, percent, regions }));
|
|
118
|
+
const p2p = new pipe2pam_1.default();
|
|
119
|
+
const pamDiff = new pam_diff_1.default({
|
|
120
|
+
difference,
|
|
121
|
+
percent,
|
|
122
|
+
regions,
|
|
123
|
+
response: 'blobs',
|
|
124
|
+
});
|
|
125
|
+
const kill = () => {
|
|
126
|
+
errors = [];
|
|
127
|
+
isActive = false;
|
|
128
|
+
cp?.kill('SIGKILL');
|
|
129
|
+
clearTimeout(ffmpegTimeout);
|
|
130
|
+
};
|
|
131
|
+
const restartWatchdog = () => {
|
|
132
|
+
clearTimeout(this.watchdog);
|
|
133
|
+
this.watchdog = setTimeout(() => {
|
|
134
|
+
this.logger.error(this.getLogPrefix(), 'Videoanalysis session timed out!');
|
|
135
|
+
kill();
|
|
136
|
+
}, 30000);
|
|
137
|
+
};
|
|
138
|
+
const resetTimeout = () => {
|
|
139
|
+
clearTimeout(motionTimeout);
|
|
140
|
+
motionTimeout = setTimeout(() => {
|
|
141
|
+
this.cameraDevice.updateState('motion', { state: false }).catch();
|
|
142
|
+
}, 30000);
|
|
143
|
+
};
|
|
144
|
+
pamDiff.on('diff', (data) => {
|
|
145
|
+
const motionEvent = data.trigger.map((zone) => {
|
|
146
|
+
return {
|
|
147
|
+
name: zone.name,
|
|
148
|
+
percentage: zone.percent,
|
|
149
|
+
blobs: zone.blobs,
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
this.logger.log(this.getLogPrefix(), 'Motion detected!', JSON.stringify(motionEvent, null, 2));
|
|
153
|
+
this.cameraDevice.updateState('motion', { state: true }).catch();
|
|
154
|
+
resetTimeout();
|
|
155
|
+
});
|
|
156
|
+
pamDiff.on('data', () => {
|
|
157
|
+
restartWatchdog();
|
|
158
|
+
isActive = true;
|
|
159
|
+
});
|
|
160
|
+
const cp = (0, child_process_1.spawn)(this.ffmpegPath, ffmpegArguments, {
|
|
161
|
+
env: process.env,
|
|
162
|
+
});
|
|
163
|
+
cp.stdout?.pipe(p2p).pipe(pamDiff);
|
|
164
|
+
cp.stderr?.on('data', (data) => {
|
|
165
|
+
data
|
|
166
|
+
.toString()
|
|
167
|
+
.split('\n')
|
|
168
|
+
.forEach((line) => {
|
|
169
|
+
if (line && line !== '')
|
|
170
|
+
errors.push(line);
|
|
171
|
+
});
|
|
172
|
+
errors = errors.slice(-3);
|
|
173
|
+
});
|
|
174
|
+
cp.on('exit', (code, signal) => {
|
|
175
|
+
if (code === 1) {
|
|
176
|
+
errors.unshift(`FFMPEG videoanalysis process exited with error! (${signal})`);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
cp.on('close', () => {
|
|
180
|
+
if (errors.includes('FFMPEG videoanalysis process exited with error!')) {
|
|
181
|
+
errors.forEach((error) => this.logger.error(this.getLogPrefix(), error));
|
|
182
|
+
}
|
|
183
|
+
this.logger.warn(this.getLogPrefix(), 'FFMPEG videoanalysis process closed');
|
|
184
|
+
kill();
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
if (!this.stopped && !this.killed) {
|
|
187
|
+
this.restart();
|
|
188
|
+
}
|
|
189
|
+
}, 1500);
|
|
190
|
+
});
|
|
191
|
+
restartWatchdog();
|
|
192
|
+
return {
|
|
193
|
+
isActive() {
|
|
194
|
+
return isActive;
|
|
195
|
+
},
|
|
196
|
+
kill,
|
|
197
|
+
cp,
|
|
198
|
+
pamDiff,
|
|
199
|
+
p2p,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
reset() {
|
|
203
|
+
this.logger.debug(this.getLogPrefix(), 'Resetting videoanalysis');
|
|
204
|
+
this.videoanalysisSession?.kill();
|
|
205
|
+
this.videoanalysisSession = undefined;
|
|
206
|
+
clearTimeout(this.watchdog);
|
|
207
|
+
this.watchdog = undefined;
|
|
208
|
+
}
|
|
209
|
+
getCameraRegions() {
|
|
210
|
+
const cameraZones = this.cameraDevice.motionZones.length ? this.cameraDevice.motionZones : constants_1.DEFAULT_ZONE;
|
|
211
|
+
return cameraZones.map((zone) => {
|
|
212
|
+
return {
|
|
213
|
+
name: zone.name,
|
|
214
|
+
polygon: zone.regions.flatMap((region) => region.coords.map((coord) => ({ x: coord.points[0], y: coord.points[1] }))),
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
getLogPrefix() {
|
|
219
|
+
return `${this.cameraDevice.name} (${this.source.name}):`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.VideoanalysisService = VideoanalysisService;
|
|
223
|
+
//# sourceMappingURL=videoanalysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"videoanalysis.js","sourceRoot":"","sources":["../src/videoanalysis.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAC3B,wDAA+B;AAC/B,iDAAyD;AAEzD,2CAAuF;AAKvF,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE/F,MAAa,oBAAoB;IACvB,YAAY,CAAe;IAC3B,aAAa,CAAgB;IAC7B,MAAM,CAAe;IACrB,MAAM,CAAc;IAEpB,MAAM,GAAG,KAAK,CAAC;IACf,OAAO,GAAG,KAAK,CAAC;IAChB,UAAU,CAAS;IAEnB,oBAAoB,CAAwB;IAC5C,QAAQ,CAAkB;IAElC,YAAY,YAA0B,EAAE,aAA4B,EAAE,MAAmB,EAAE,MAAoB;QAC7G,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAwB,CAAC;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;YACrE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,gCAAgC,EAAE,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC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AC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY;QAClB,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;IAC5D,CAAC;CACF;AA7PD,oDA6PC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"displayName": "Pam Diff",
|
|
3
|
+
"name": "@camera.ui/camera-ui-pamdiff",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "camera.ui pam diff plugin",
|
|
6
|
+
"author": "seydx (https://github.com/seydx/camera.ui)",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rimraf dist && tsc",
|
|
10
|
+
"format": "prettier --write 'src/' --ignore-unknown --no-error-on-unmatched-pattern",
|
|
11
|
+
"lint": "eslint --fix --ext .js,.ts .",
|
|
12
|
+
"update": "updates --update ./",
|
|
13
|
+
"install-updates": "npm i --save",
|
|
14
|
+
"prepublishOnly": "npm run lint && npm run format && npm run build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@camera.ui/types": "^0.0.22",
|
|
18
|
+
"pam-diff": "^1.2.1",
|
|
19
|
+
"pipe2pam": "^0.7.1"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@rushstack/eslint-patch": "^1.7.2",
|
|
23
|
+
"@types/node": "^20.11.14",
|
|
24
|
+
"@types/ws": "^8.5.10",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
|
26
|
+
"@typescript-eslint/parser": "^6.20.0",
|
|
27
|
+
"concurrently": "^8.2.2",
|
|
28
|
+
"eslint": "^8.56.0",
|
|
29
|
+
"eslint-config-prettier": "^9.1.0",
|
|
30
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
31
|
+
"prettier": "^3.2.4",
|
|
32
|
+
"rimraf": "^5.0.5",
|
|
33
|
+
"typescript": "^5.3.3",
|
|
34
|
+
"updates": "^15.1.1"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/seydx/camera.ui/issues"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"camera.ui": ">=3.0.0-alpha.0",
|
|
41
|
+
"node": ">=18.12.0"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/seydx/camera.ui#readme",
|
|
44
|
+
"keywords": [
|
|
45
|
+
"camera-ui-plugin",
|
|
46
|
+
"cameras",
|
|
47
|
+
"pamdiff",
|
|
48
|
+
"motion",
|
|
49
|
+
"detection"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/seydx/camera.ui.git"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
declare module 'pam-diff' {
|
|
2
|
+
import { Transform } from 'stream';
|
|
3
|
+
|
|
4
|
+
interface PamDiffOptions {
|
|
5
|
+
difference?: number;
|
|
6
|
+
percent?: number;
|
|
7
|
+
response?: 'percent' | 'bounds' | 'blobs';
|
|
8
|
+
regions?: PamDiffRegion[];
|
|
9
|
+
mask?: boolean;
|
|
10
|
+
draw?: boolean;
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface PamDiffCoords {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface PamDiffRegion {
|
|
20
|
+
name: string;
|
|
21
|
+
difference?: number;
|
|
22
|
+
percent?: number;
|
|
23
|
+
polygon?: PamDiffCoords[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Trigger {
|
|
27
|
+
name: string;
|
|
28
|
+
percent: number;
|
|
29
|
+
minX?: number;
|
|
30
|
+
maxX?: number;
|
|
31
|
+
minY?: number;
|
|
32
|
+
maxY?: number;
|
|
33
|
+
blobs?: Blob[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Blob {
|
|
37
|
+
label: number;
|
|
38
|
+
percent: number;
|
|
39
|
+
minX: number;
|
|
40
|
+
maxX: number;
|
|
41
|
+
minY: number;
|
|
42
|
+
maxY: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface DiffResult {
|
|
46
|
+
trigger: Trigger[];
|
|
47
|
+
pam: Buffer;
|
|
48
|
+
headers: Buffer;
|
|
49
|
+
pixels: Buffer;
|
|
50
|
+
debug?: {
|
|
51
|
+
name: string;
|
|
52
|
+
count: number;
|
|
53
|
+
duration: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class PamDiff extends Transform {
|
|
58
|
+
constructor(options?: PamDiffOptions, callback?: Function);
|
|
59
|
+
|
|
60
|
+
config: PamDiffOptions;
|
|
61
|
+
difference: number;
|
|
62
|
+
percent: number;
|
|
63
|
+
response: string;
|
|
64
|
+
regions: PamDiffRegion[];
|
|
65
|
+
mask: boolean;
|
|
66
|
+
draw: boolean;
|
|
67
|
+
debug: boolean;
|
|
68
|
+
callback?: Function;
|
|
69
|
+
|
|
70
|
+
setDifference(num: number): PamDiff;
|
|
71
|
+
setPercent(num: number): PamDiff;
|
|
72
|
+
setResponse(str: string): PamDiff;
|
|
73
|
+
setRegions(arr: PamDiffRegion[]): PamDiff;
|
|
74
|
+
setMask(bool: boolean): PamDiff;
|
|
75
|
+
setDraw(bool: boolean): PamDiff;
|
|
76
|
+
setDebug(bool: boolean): PamDiff;
|
|
77
|
+
setCallback(func: Function): PamDiff;
|
|
78
|
+
resetCache(): PamDiff;
|
|
79
|
+
reset(): PamDiff;
|
|
80
|
+
|
|
81
|
+
on(event: 'diff', callback: (data: DiffResult) => void): PamDiff;
|
|
82
|
+
on(event: 'data', callback: (data: any) => void): PamDiff;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export = PamDiff;
|
|
86
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
declare module 'pipe2pam' {
|
|
2
|
+
import { Transform } from 'stream';
|
|
3
|
+
|
|
4
|
+
interface Pipe2PamOptions {
|
|
5
|
+
pool?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Pipe2PamHeaders {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
depth: number;
|
|
12
|
+
maxval: number;
|
|
13
|
+
tupltype: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Pipe2PamData {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
depth: number;
|
|
20
|
+
maxval: number;
|
|
21
|
+
tupltype: string;
|
|
22
|
+
headers: Buffer;
|
|
23
|
+
pixels: Buffer;
|
|
24
|
+
pam: Buffer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class Pipe2Pam extends Transform {
|
|
28
|
+
constructor(options?: Pipe2PamOptions);
|
|
29
|
+
|
|
30
|
+
reset(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export = Pipe2Pam;
|
|
34
|
+
}
|