Skip to content

Commit

Permalink
add max_recording_time
Browse files Browse the repository at this point in the history
  • Loading branch information
roflcoopter committed Mar 12, 2024
1 parent 3987238 commit c9fcea2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@
"optional": true,
"default": 10
},
{
"type": "integer",
"valueMin": 0,
"name": "max_recording_time",
"description": "Maximum number of seconds to record.",
"optional": true,
"default": 300
},
{
"type": "integer",
"valueMin": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@
"optional": true,
"default": 10
},
{
"type": "integer",
"valueMin": 0,
"name": "max_recording_time",
"description": "Maximum number of seconds to record.",
"optional": true,
"default": 300
},
{
"type": "integer",
"valueMin": 1,
Expand Down
21 changes: 18 additions & 3 deletions viseron/components/nvr/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,17 @@ def start_recorder(self, shared_frame) -> None:
self._frame_scanners[MOTION_DETECTOR].scan = True
self._logger.info("Starting motion detector")

def stop_recorder(self) -> None:
def stop_recorder(self, force=False) -> None:
"""Stop recorder."""

def _stop():
self._idle_frames = 0
self._camera.stop_recorder()

if force:
_stop()
return

if self._idle_frames % self._camera.output_fps == 0:
self._logger.info(
"Stopping recording in: {}".format(
Expand All @@ -596,8 +605,7 @@ def stop_recorder(self) -> None:
):
self._frame_scanners[MOTION_DETECTOR].scan = False
self._logger.info("Pausing motion detector")
self._idle_frames = 0
self._camera.stop_recorder()
_stop()

def process_frame(self, shared_frame: SharedFrame) -> None:
"""Process frame."""
Expand All @@ -611,6 +619,13 @@ def process_recorder(self, shared_frame: SharedFrame) -> None:
if self._start_recorder:
self._start_recorder = False
self.start_recorder(shared_frame)
# Stop recording if max_recording_time is exceeded
elif (
self._camera.is_recording
and self._camera.recorder.max_recording_time_exceeded
):
self._logger.info("Max recording time exceeded, stopping recorder")
self.stop_recorder(force=True)
elif self._camera.is_recording and self.event_over():
self._idle_frames += 1
self.stop_recorder()
Expand Down
8 changes: 8 additions & 0 deletions viseron/domains/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
CONFIG_FOLDER,
CONFIG_IDLE_TIMEOUT,
CONFIG_LOOKBACK,
CONFIG_MAX_RECORDING_TIME,
CONFIG_MJPEG_DRAW_MOTION,
CONFIG_MJPEG_DRAW_MOTION_MASK,
CONFIG_MJPEG_DRAW_OBJECT_MASK,
Expand All @@ -80,6 +81,7 @@
DEFAULT_FILENAME_PATTERN,
DEFAULT_IDLE_TIMEOUT,
DEFAULT_LOOKBACK,
DEFAULT_MAX_RECORDING_TIME,
DEFAULT_MJPEG_DRAW_MOTION,
DEFAULT_MJPEG_DRAW_MOTION_MASK,
DEFAULT_MJPEG_DRAW_OBJECT_MASK,
Expand Down Expand Up @@ -112,6 +114,7 @@
DESC_FOLDER,
DESC_IDLE_TIMEOUT,
DESC_LOOKBACK,
DESC_MAX_RECORDING_TIME,
DESC_MJPEG_DRAW_MOTION,
DESC_MJPEG_DRAW_MOTION_MASK,
DESC_MJPEG_DRAW_OBJECT_MASK,
Expand Down Expand Up @@ -239,6 +242,11 @@
default=DEFAULT_IDLE_TIMEOUT,
description=DESC_IDLE_TIMEOUT,
): vol.All(int, vol.Range(min=0)),
vol.Optional(
CONFIG_MAX_RECORDING_TIME,
default=DEFAULT_MAX_RECORDING_TIME,
description=DESC_MAX_RECORDING_TIME,
): vol.All(int, vol.Range(min=0)),
Deprecated(
CONFIG_RETAIN,
description=DESC_RETAIN,
Expand Down
3 changes: 3 additions & 0 deletions viseron/domains/camera/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
# RECORDER_SCHEMA constants
CONFIG_LOOKBACK = "lookback"
CONFIG_IDLE_TIMEOUT = "idle_timeout"
CONFIG_MAX_RECORDING_TIME = "max_recording_time"
CONFIG_RETAIN = "retain"
CONFIG_FOLDER = "folder"
CONFIG_FILENAME_PATTERN = "filename_pattern"
Expand All @@ -86,6 +87,7 @@

DEFAULT_LOOKBACK = 5
DEFAULT_IDLE_TIMEOUT = 10
DEFAULT_MAX_RECORDING_TIME: Final = 300
DEFAULT_FILENAME_PATTERN = "%H:%M:%S"
DEFAULT_THUMBNAIL: Final = None
DEFAULT_CREATE_EVENT_CLIP = False
Expand All @@ -94,6 +96,7 @@

DESC_LOOKBACK = "Number of seconds to record before a detected object."
DESC_IDLE_TIMEOUT = "Number of seconds to record after all events are over."
DESC_MAX_RECORDING_TIME = "Maximum number of seconds to record."
DESC_RETAIN = "Number of days to save recordings before deletion."
DEPRECATED_RETAIN = (
"Use the "
Expand Down
15 changes: 15 additions & 0 deletions viseron/domains/camera/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CONFIG_FILENAME_PATTERN,
CONFIG_IDLE_TIMEOUT,
CONFIG_LOOKBACK,
CONFIG_MAX_RECORDING_TIME,
CONFIG_RECORDER,
CONFIG_SAVE_TO_DISK,
CONFIG_THUMBNAIL,
Expand Down Expand Up @@ -391,6 +392,20 @@ def lookback(self) -> int:
"""Return lookback."""
return self._config[CONFIG_RECORDER][CONFIG_LOOKBACK]

@property
def max_recording_time(self) -> int:
"""Return max_recording_time."""
return self._config[CONFIG_RECORDER][CONFIG_MAX_RECORDING_TIME]

@property
def max_recording_time_exceeded(self) -> bool:
"""Return True if the maximum recording time has been exceeded."""
if self._active_recording is None:
return False
return (
utcnow() - self._active_recording.start_time
).total_seconds() > self.max_recording_time


class FailedCameraRecorder(RecorderBase):
"""Failed camera recorder.
Expand Down

0 comments on commit c9fcea2

Please sign in to comment.