Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option enabled for each camera in config #4162

Merged
merged 9 commits into from
Nov 2, 2022
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 @@ -20,6 +22,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 @@ -44,4 +47,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 @@ -380,6 +380,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.
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is incorrect for these (# is correct but doesn't need space after)

Copy link
Contributor Author

@banthungprong banthungprong Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this. Formatting is the same like other comment blocks with the Optional.
# in the same columns like the next line "enabled : True
and after # the same blanks like a few lines above

# Events/Recordings are still viewable.
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.
# 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.

this is what I mean, the start of the comment is indented too much

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still needs to be addressed

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 @@ -250,6 +250,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():
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -271,6 +275,10 @@ def start_camera_processors(self) -> None:

def start_camera_capture_processes(self) -> None:
for name, config in self.config.cameras.items():
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -530,6 +530,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 @@ -799,7 +800,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 @@ -915,10 +916,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 text-green-500">Camera is disabled in config, no stream or snapshot available!</div>
NickM-27 marked this conversation as resolved.
Show resolved Hide resolved
}
{
(!hasLoaded && enabled) ? (
<div className="absolute inset-0 flex justify-center" style={`height: ${scaledHeight}px`}>
<ActivityIndicator />
</div>
) : null
}
</div >
);
}