Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Jan 14, 2022
1 parent 8536391 commit b9c4a6c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 111 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

# Next
# v1.0.6 - 2022-01-14

## Other Changes
- Videoanalysis: Reduced dwell time from 120s to 90s
- Videoanalysis: Minor improvements
- Refactored log output for better understanding of the flow of events

## Bugfixes
- Fixed an issue where prebuffering/videoanalysis didnt work on cameras with mapping video/audio
- Minor bugfixes

# v1.0.5 - 2022-01-13

## Other Changes
- Reduced default videoanalysis sensitivity to 25
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camera.ui",
"version": "1.0.5",
"version": "1.0.6",
"description": "User Interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/camera.ui)",
"scripts": {
Expand Down
24 changes: 7 additions & 17 deletions src/controller/camera/services/prebuffer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,12 @@ class PrebufferService {
} else {
audioArguments.push('-bsf:a', 'aac_adtstoasc', '-acodec', 'copy');
}

if (videoConfig.mapaudio) {
audioArguments.unshift('-map', videoConfig.mapaudio);
}
} else {
audioArguments.push('-an');
}

let vcodec = 'copy';

//todo change
const probeTimedout = this.#mediaService.codecs.timedout;
const videoCodecProbe = this.#mediaService.codecs.video[0];
const forcePrebuffering = this.#camera.forcePrebuffering;
Expand All @@ -265,20 +260,12 @@ class PrebufferService {

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

if (videoConfig.mapvideo) {
videoArguments.unshift('-map', videoConfig.mapvideo);
}

/*if (videoConfig.videoFilter) {
videoArguments.push('-filter:v', videoConfig.videoFilter);
}*/

this.parsers = {
mp4: cameraUtils.createFragmentedMp4Parser(),
mpegts: cameraUtils.createMpegTsParser(),
};

const session = await this.#startRebroadcastSession(ffmpegInput, videoArguments, audioArguments, {
const session = await this.#startRebroadcastSession(ffmpegInput, videoConfig, videoArguments, audioArguments, {
parsers: this.parsers,
});

Expand Down Expand Up @@ -470,7 +457,7 @@ class PrebufferService {
};
}

async #startRebroadcastSession(ffmpegInput, videoArguments, audioArguments, options) {
async #startRebroadcastSession(ffmpegInput, videoConfig, videoArguments, audioArguments, options) {
const events = new EventEmitter();

let isActive = true;
Expand Down Expand Up @@ -540,16 +527,19 @@ class PrebufferService {
}
}

let audioMap = `${videoConfig.mapaudio ? videoConfig.mapaudio : '0:a'}?`;
let videoMap = `${videoConfig.mapvideo ? videoConfig.mapvideo : '0:v'}?`;

const arguments_ = [
...ffmpegInput,
...videoArguments,
...audioArguments,
'-f',
'tee',
'-map',
'0:v?',
videoMap,
'-map',
'0:a?',
audioMap,
`${mp4Arguments}|${mpegtsArguments}`,
];

Expand Down
7 changes: 5 additions & 2 deletions src/controller/camera/services/stream.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class StreamService {

if (cameraSetting?.audio && this.#mediaService.codecs.audio.length > 0) {
audioArguments.push('-acodec', 'mp2', '-ac', '1', '-b:a', '128k');
} else {
audioArguments.push('-an');
}

if (videoConfig.mapaudio && !prebuffer) {
Expand Down Expand Up @@ -114,6 +116,7 @@ class StreamService {

async start() {
if (!this.streamSession) {
// eslint-disable-next-line no-unused-vars
let { ffmpegInput, prebuffer, audioArguments, videoArguments, additionalFlags } =
await this.configureStreamOptions();

Expand Down Expand Up @@ -163,9 +166,9 @@ class StreamService {

this.streamSession = null;

if (!prebuffer) {
/*if (!prebuffer) {
this.#sessionService.closeSession();
}
}*/
});
}
}
Expand Down
53 changes: 24 additions & 29 deletions src/controller/camera/services/videoanalysis.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const { log } = LoggerService;

const isUINT = (value) => Number.isInteger(value) && value >= 0;

const FFMPEG_MODE = 'rgba'; // gray, rgba, rgb24
const FFMPEG_MODE = 'rgb24'; // gray, rgba, rgb24
const FFMPEG_RESOLUTION = '640:360';
const FFMPEG_FPS = '2';
const DIFFERENCE = 9;
//const GRAYSCALE = 'luminosity';
const DWELL_TIME = 2 * 60 * 1000;
const DWELL_TIME = 90 * 1000;

class VideoAnalysisService {
#camera;
Expand Down Expand Up @@ -137,26 +137,18 @@ class VideoAnalysisService {
clearTimeout(this.watchdog);
}

if (this.motionEventTimeout) {
clearTimeout(this.motionEventTimeout);
this.motionEventTimeout = null;

if (this.motionEventTimeout || this.forceCloseTimeout) {
this.#triggerMotion(false);
}

if (this.forceCloseTimeout) {
clearTimeout(this.forceCloseTimeout);
this.forceCloseTimeout = null;
}

if (this.restartTimer) {
clearTimeout(this.restartTimer);
this.restartTimer = null;
}

this.videoanalysisSession.cp?.kill('SIGKILL');
this.videoanalysisSession.pamDiff?.resetCache();
this.videoanalysisSession = undefined;
this.videoanalysisSession = null;
}
}

Expand Down Expand Up @@ -191,7 +183,7 @@ class VideoAnalysisService {
const videoArguments = ['-an', '-vcodec', 'pam'];

if (!prebufferInput && videoConfig.mapvideo) {
videoArguments.push('-map', videoConfig.mapvideo);
videoArguments.unshift('-map', videoConfig.mapvideo);
}

const ffmpegArguments = [
Expand Down Expand Up @@ -223,7 +215,6 @@ class VideoAnalysisService {

const p2p = new P2P();
const pamDiff = new PamDiff({
//difference: settings?.videoanalysis?.difference || 9,
//grayscale: GRAYSCALE,
difference: DIFFERENCE,
percent: 100 - (settings?.videoanalysis?.sensitivity || 25),
Expand Down Expand Up @@ -257,25 +248,22 @@ class VideoAnalysisService {
// eslint-disable-next-line no-unused-vars
pamDiff.on('diff', async (data) => {
if (!this.motionEventTimeout) {
if (this.forceCloseTimeout) {
clearTimeout(this.forceCloseTimeout);
this.forceCloseTimeout = null;
}

log.debug(`Motion detected via Videoanalysis: ${JSON.stringify(data.trigger[0])}`, this.cameraName);
this.#triggerMotion(true);

// forceClose after 3min
this.forceCloseTimeout = setTimeout(() => {
// forceClose after 3min
this.#triggerMotion(false);
}, 3 * 60 * 1000);
}

clearTimeout(this.motionEventTimeout);
if (this.motionEventTimeout) {
clearTimeout(this.motionEventTimeout);
this.motionEventTimeout = null;
}

this.motionEventTimeout = setTimeout(async () => {
this.#triggerMotion(false);
this.motionEventTimeout = null;
}, DWELL_TIME);
});

Expand Down Expand Up @@ -326,12 +314,18 @@ class VideoAnalysisService {
}

async #triggerMotion(state) {
const result = await MotionController.handleMotion('motion', this.cameraName, state, 'videoanalysis', {});
log.debug(`Received a new VIDEOANALYSIS message ${JSON.stringify(result)} (${this.cameraName})`);
await MotionController.handleMotion('motion', this.cameraName, state, 'videoanalysis');

if (!state) {
if (this.forceCloseTimeout) {
clearTimeout(this.forceCloseTimeout);
this.forceCloseTimeout = null;
}

if (!state && this.forceCloseTimeout) {
clearTimeout(this.forceCloseTimeout);
this.forceCloseTimeout = null;
if (this.motionEventTimeout) {
clearTimeout(this.motionEventTimeout);
this.motionEventTimeout = null;
}
}
}

Expand All @@ -358,7 +352,8 @@ class VideoAnalysisService {
}

#createRegions(regions = [], sensitivity) {
const percent = 100 - (sensitivity >= 0 && sensitivity <= 100 ? sensitivity : 25);
const sens = sensitivity >= 0 && sensitivity <= 100 ? sensitivity : 25;
const percent = 100 - sens;

const zones = regions
?.map((region, index) => {
Expand Down Expand Up @@ -386,7 +381,7 @@ class VideoAnalysisService {
})
.filter((zone) => zone?.polygon?.length > 2);

log.debug(`Videoanalysis: Currently active zones: ${JSON.stringify(zones)}`, this.cameraName);
log.debug(`Videoanalysis: Sensitivity: ${sens} - Active zones: ${JSON.stringify(zones)}`, this.cameraName);

return zones;
}
Expand Down
8 changes: 4 additions & 4 deletions src/controller/event/event.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { Telegram } = require('../../common/telegram');

const { LoggerService } = require('../../services/logger/logger.service');

const { CameraController } = require('../camera/camera.controller');
//const { CameraController } = require('../camera/camera.controller');

const CamerasModel = require('../../api/components/cameras/cameras.model');
const NotificationsModel = require('../../api/components/notifications/notifications.model');
Expand Down Expand Up @@ -43,7 +43,7 @@ class EventController {
// eslint-disable-next-line no-unused-vars
static async handle(trigger, cameraName, active, fileBuffer, type) {
if (active) {
const controller = CameraController.cameras.get(cameraName);
//const controller = CameraController.cameras.get(cameraName);

try {
let Camera, CameraSettings;
Expand Down Expand Up @@ -265,9 +265,9 @@ class EventController {

EventController.#movementHandler[cameraName] = false;

if (controller) {
/*if (controller) {
controller.session.closeSession();
}
}*/
} else {
log.debug(`Skip event, motion state: ${active}`, cameraName);
}
Expand Down
Loading

0 comments on commit b9c4a6c

Please sign in to comment.