Skip to content

Commit

Permalink
Allow cameras to be disabled in config (#4162)
Browse files Browse the repository at this point in the history
* add option enabled for each camera in config

* Simplified If-block and removed wrong Optional

* Update Docs enabling/disabling camera in config

* correct format for option

* Disabling Camera for processes, no config changes

* Describe effects of disabled cam in documentation

* change if-logic, obsolete copy, info disabled cam

* changed color to white, added top padding in disabled camera info

* changed indentation
  • Loading branch information
banthungprong committed Nov 2, 2022
1 parent 2a36a1b commit 8163afc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
5 changes: 4 additions & 1 deletion docs/docs/configuration/cameras.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ title: Cameras

Several inputs can be configured for each camera and the role of each input can be mixed and matched based on your needs. This allows you to use a lower resolution stream for object detection, but create recordings from a higher resolution stream, or vice versa.

A camera is enabled by default but can be temporarily disabled by using `enabled: False`. Existing events and recordings can still be accessed. Live streams, recording and detecting are not working. Camera specific configurations will be used.

Each role can only be assigned to one input per camera. The options for roles are as follows:

| Role | Description |
Expand All @@ -21,6 +23,7 @@ mqtt:
host: mqtt.server.com
cameras:
back:
enabled: True
ffmpeg:
inputs:
- path: rtsp://viewer:{FRIGATE_RTSP_PASSWORD}@10.0.10.10:554/cam/realmonitor?channel=1&subtype=2
Expand All @@ -45,4 +48,4 @@ cameras:
side: ...
```

For camera model specific settings check the [camera specific](/configuration/camera_specific) infos.
For camera model specific settings check the [camera specific](/configuration/camera_specific) infos.
4 changes: 4 additions & 0 deletions docs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ timestamp_style:
cameras:
# Required: name of the camera
back:
# Optional: Enable/Disable the camera (default: shown below).
# If disabled: config is used but no live stream and no capture etc.
# Events/Recordings are still viewable.
enabled: True
# Required: ffmpeg settings for the camera
ffmpeg:
# Required: A list of input streams for the camera. See documentation for more information.
Expand Down
8 changes: 8 additions & 0 deletions frigate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def start_video_output_processor(self) -> None:
def start_camera_processors(self) -> None:
model_shape = (self.config.model.height, self.config.model.width)
for name, config in self.config.cameras.items():
if not self.config.cameras[name].enabled:
logger.info(f"Camera processor not started for disabled camera {name}")
continue

camera_process = mp.Process(
target=track_camera,
name=f"camera_processor:{name}",
Expand All @@ -276,6 +280,10 @@ def start_camera_processors(self) -> None:

def start_camera_capture_processes(self) -> None:
for name, config in self.config.cameras.items():
if not self.config.cameras[name].enabled:
logger.info(f"Capture process not started for disabled camera {name}")
continue

capture_process = mp.Process(
target=capture_camera,
name=f"camera_capture:{name}",
Expand Down
6 changes: 3 additions & 3 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ class CameraUiConfig(FrigateBaseModel):

class CameraConfig(FrigateBaseModel):
name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$")
enabled: bool = Field(default=True, title="Enable camera.")
ffmpeg: CameraFfmpegConfig = Field(title="FFmpeg configuration for the camera.")
best_image_timeout: int = Field(
default=60,
Expand Down Expand Up @@ -819,7 +820,7 @@ def runtime_config(self) -> FrigateConfig:
if config.mqtt.password:
config.mqtt.password = config.mqtt.password.format(**FRIGATE_ENV_VARS)

# Global config to propegate down to camera level
# Global config to propagate down to camera level
global_config = config.dict(
include={
"birdseye": ...,
Expand Down Expand Up @@ -940,10 +941,9 @@ def runtime_config(self) -> FrigateConfig:
logger.warning(
f"{name}: Recording retention is configured for {camera_config.record.retain.mode} and event retention is configured for {camera_config.record.events.retain.mode}. The more restrictive retention policy will be applied."
)
# generage the ffmpeg commands
# generate the ffmpeg commands
camera_config.create_ffmpeg_cmds()
config.cameras[name] = camera_config

return config

@validator("cameras")
Expand Down
21 changes: 14 additions & 7 deletions web/src/components/CameraImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch
const [{ width: availableWidth }] = useResizeObserver(containerRef);

const { name } = config ? config.cameras[camera] : '';
const enabled = config ? config.cameras[camera].enabled : 'True';
const { width, height } = config ? config.cameras[camera].detect : { width: 1, height: 1 };
const aspectRatio = width / height;

Expand Down Expand Up @@ -45,12 +46,18 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch

return (
<div className="relative w-full" ref={containerRef}>
<canvas data-testid="cameraimage-canvas" height={scaledHeight} ref={canvasRef} width={scaledWidth} />
{!hasLoaded ? (
<div className="absolute inset-0 flex justify-center" style={`height: ${scaledHeight}px`}>
<ActivityIndicator />
</div>
) : null}
</div>
{
(enabled) ?
<canvas data-testid="cameraimage-canvas" height={scaledHeight} ref={canvasRef} width={scaledWidth} />
: <div class="text-center pt-6">Camera is disabled in config, no stream or snapshot available!</div>
}
{
(!hasLoaded && enabled) ? (
<div className="absolute inset-0 flex justify-center" style={`height: ${scaledHeight}px`}>
<ActivityIndicator />
</div>
) : null
}
</div >
);
}

0 comments on commit 8163afc

Please sign in to comment.