Skip to content

Commit

Permalink
v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 15, 2022
1 parent b9c4a6c commit fc05dde
Show file tree
Hide file tree
Showing 18 changed files with 1,057 additions and 826 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# Changelog
All notable changes to this project will be documented in this file.

# v1.0.7 - 2022-01-15

## Other Changes
- Videoanalysis: Reduced the dwell time from 90s to 60s
- Videoanalysis: Removed `-hwaccel` from FFMPEG parameters
- Videoanalysis: Added `pixel/color difference` slider to be able to adjust the video analysis even more precisely within ui
- Prebuffering: Added `-preset:v ultrafast` if `forcePrebuffering` is enabled
- Added the possibility to control the motion sensor (OFF state) via the camera instead of via motionTimeout (set `"motionTimeout": 0`, the camera must be able to send a `OFF` message e.g. via MQTT or Videoanalysis)
- More translation added
- Minor improvements (camera.ui)

## Bugfixes
- Fixed an isue where crashing FFmpeg did not display an error message in the log
- Fixed an issue where the dwell time could start before the motion handler was initialized
- Fixed an issue where the restart timer for prebuffering and videoanalysis were calculated wrong
- Minor Bugfixes

# v1.0.6 - 2022-01-14

## Other Changes
Expand Down
1,444 changes: 755 additions & 689 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.0.6",
"version": "1.0.7",
"description": "User Interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand All @@ -16,7 +16,7 @@
},
"main": "src/index.js",
"dependencies": {
"@aws-sdk/client-rekognition": "^3.46.0",
"@aws-sdk/client-rekognition": "^3.47.0",
"alexa-remote2": "^4.1.1",
"axios": "^0.24.0",
"bunyan": "^1.8.15",
Expand Down
6 changes: 5 additions & 1 deletion src/api/components/settings/settings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ exports.patchTarget = async (req, res) => {

for (const camera of cameraSettings) {
const controller = cameras.get(camera.name);
controller?.videoanalysis.changeZone(camera.videoanalysis.regions, camera.videoanalysis.sensitivity);
controller?.videoanalysis.changeZone(
camera.videoanalysis.regions,
camera.videoanalysis.sensitivity,
camera.videoanalysis.difference
);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/api/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const defaultCameraSettingsEntry = {
},
videoanalysis: {
sensitivity: 25,
difference: 9,
regions: [],
},
};
Expand Down Expand Up @@ -509,6 +510,10 @@ class Database {
settings.videoanalysis = {};
}

if (!(settings.videoanalysis.difference >= 0 && settings.videoanalysis.difference <= 255)) {
settings.videoanalysis.difference = defaultCameraSettingsEntry.videoanalysis.difference;
}

if (!(settings.videoanalysis.sensitivity >= 0 && settings.videoanalysis.sensitivity <= 100)) {
settings.videoanalysis.sensitivity = defaultCameraSettingsEntry.videoanalysis.sensitivity;
}
Expand Down
11 changes: 9 additions & 2 deletions src/controller/camera/camera.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const { StreamService } = require('./services/stream.service');
const { VideoAnalysisService } = require('./services/videoanalysis.service');

class CameraController {
static #controller;
static #socket;

static cameras = new Map([]);

constructor(socket) {
constructor(controller, socket) {
CameraController.#controller = controller;
CameraController.#socket = socket;

for (const camera of ConfigService.ui.cameras) {
Expand All @@ -26,7 +28,12 @@ class CameraController {
static createController(camera) {
const mediaService = new MediaService(camera);
const prebufferService = new PrebufferService(camera, mediaService, CameraController.#socket);
const videoanalysisService = new VideoAnalysisService(camera, prebufferService, CameraController.#socket);
const videoanalysisService = new VideoAnalysisService(
camera,
prebufferService,
CameraController.#controller,
CameraController.#socket
);
const sessionService = new SessionService(camera);
const streamService = new StreamService(
camera,
Expand Down
34 changes: 19 additions & 15 deletions src/controller/camera/services/prebuffer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const _ = require('lodash');
const { createServer } = require('net');
const { EventEmitter } = require('events');
const moment = require('moment');
const { spawn } = require('child_process');

const cameraUtils = require('../utils/camera.utils');
Expand Down Expand Up @@ -86,8 +87,7 @@ class PrebufferService {

this.prebufferSession = await this.#startPrebufferSession();

const midnight = this.#millisUntilMidnight();
const timer = midnight + 2 * 60 * 60 * 1000;
const timer = this.#millisUntilTime('02:00');

log.info(`Prebuffering scheduled for restart at 2AM: ${Math.round(timer / 1000 / 60)} minutes`, this.cameraName);

Expand Down Expand Up @@ -235,7 +235,7 @@ class PrebufferService {
audioArguments.push('-an');
}

let vcodec = 'copy';
const videoArguments = [];

const probeTimedout = this.#mediaService.codecs.timedout;
const videoCodecProbe = this.#mediaService.codecs.video[0];
Expand All @@ -254,12 +254,14 @@ class PrebufferService {
return this.stop(true);
} else {
log.info('Prebuffering with reencoding enabled! Please pay attention to the CPU load', this.cameraName);
vcodec = videoConfig.vcodec === 'copy' ? 'libx264' : videoConfig.vcodec;

let vcodec = videoConfig.vcodec === 'copy' ? 'libx264' : videoConfig.vcodec;
videoArguments.push('-vcodec', vcodec, '-preset:v', 'ultrafast');
}
} else {
videoArguments.push('-vcodec', 'copy');
}

const videoArguments = ['-vcodec', vcodec];

this.parsers = {
mp4: cameraUtils.createFragmentedMp4Parser(),
mpegts: cameraUtils.createMpegTsParser(),
Expand Down Expand Up @@ -557,7 +559,7 @@ class PrebufferService {
cp.stderr.on('data', (data) => errors.push(data.toString().replace(/(\r\n|\n|\r)/gm, '')));

cp.on('exit', (code, signal) => {
if (code === 1) {
if (code === 1 || (!this.killed && errors.length > 0)) {
errors.unshift(`FFmpeg prebuffer process exited with error! (${signal})`);
log.error(errors.join(' - '), this.cameraName, 'prebuffer');
} else {
Expand All @@ -566,7 +568,7 @@ class PrebufferService {
});

cp.on('close', () => {
log.debug('Prebufferring process closed', this.cameraName);
log.info('Prebufferring process closed', this.cameraName);

kill();

Expand Down Expand Up @@ -599,13 +601,15 @@ class PrebufferService {
};
}

#millisUntilMidnight() {
const midnight = new Date();
midnight.setHours(24);
midnight.setMinutes(0);
midnight.setSeconds(0);
midnight.setMilliseconds(0);
return midnight.getTime() - Date.now();
#millisUntilTime(end = '03:00') {
const startTime = moment();
const endTime = moment(end, 'HH:mm');

if ((startTime.hour() >= 12 && endTime.hour() <= 12) || endTime.isBefore(startTime)) {
endTime.add(1, 'days');
}

return endTime.diff(startTime);
}

async #pingCamera() {
Expand Down
1 change: 0 additions & 1 deletion src/controller/camera/services/session.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class SessionService {

clearSession() {
this.session.activeStreams = 0;
log.debug('Session cleared', this.cameraName);
}
}

Expand Down
Loading

0 comments on commit fc05dde

Please sign in to comment.