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
Merged

Add option enabled for each camera in config #4162

merged 9 commits into from
Nov 2, 2022

Conversation

banthungprong
Copy link
Contributor

Based on requirement and discussion in #4109:

  • for each camera an option "enabled: True/False" can be used
  • if option isn't used in config file the camera is enable as default (so no changes in the old config are necessary

Corrected 2 typos in config.py (propagate, generate)

Adding the if block resulted in 91 deletions and 96 additions after changing the indentation. The only real changes were:

  • in config.py in class CameraConfig
    enabled: Optional[bool] = Field(default=True, title="Enable camera.")

  • in config.py in class FrigateConfig in runtime_config:
    replace
    for name, camera in config.cameras.items():
    with
    for name, camera in config.cameras.copy().items():
    ... generate camera_config ...
    if camera_config.enabled:
    ... configurations ...
    else: config.cameras.pop(name)
    befor line
    return config

@banthungprong banthungprong changed the title add option enabled for each camera in config Add option enabled for each camera in config Oct 25, 2022
frigate/config.py Outdated Show resolved Hide resolved
frigate/config.py Outdated Show resolved Hide resolved
@NickM-27
Copy link
Sponsor Collaborator

Also need to update configuration docs to reflect this new option

@banthungprong
Copy link
Contributor Author

Docs Update will follow if the reviews here are ok. I don't want to update the doc before the solution seems to be ok.
I can add the documenation update as a commit to this branch later or not?
If it is better to change something in code AND in doc at the same time I will do from now on.

@NickM-27
Copy link
Sponsor Collaborator

Yes, docs and code updates should always be part of the same PR

@@ -530,6 +530,7 @@ class CameraUiConfig(FrigateBaseModel):

class CameraConfig(FrigateBaseModel):
name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$")
enabled: Optional[bool] = Field(default=True, title="Enable camera.")
Copy link
Sponsor Collaborator

@NickM-27 NickM-27 Oct 25, 2022

Choose a reason for hiding this comment

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

Suggested change
enabled: Optional[bool] = Field(default=True, title="Enable camera.")
enabled: bool = Field(default=True, title="Enable camera.")

You are using the Optional qualifier which means the field is nullable, but it shouldn't be. This will always have a default value of True or a user set value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Simply misunderstood the Optional.

@banthungprong
Copy link
Contributor Author

Code changes as requested and updated documentation for the new option

Copy link
Sponsor Collaborator

@NickM-27 NickM-27 left a comment

Choose a reason for hiding this comment

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

Looks good, just one small thing

docs/docs/configuration/index.md Outdated Show resolved Hide resolved
merged_config = deep_merge(camera.dict(exclude_unset=True), global_config)
camera_config: CameraConfig = CameraConfig.parse_obj(
{"name": name, **merged_config}
)

if not camera_config.enabled:
config.cameras.pop(name)
Copy link
Owner

Choose a reason for hiding this comment

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

I haven't tested this, but won't this essentially just prevent the camera's config from being loaded at all? I thought the goal was to make it possible to have retain settings for a disabled camera that are different than the default values.

Copy link
Sponsor Collaborator

@NickM-27 NickM-27 Oct 26, 2022

Choose a reason for hiding this comment

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

Yeah you're right, I wasn't sure if that was supposed to be in this initial pass.

@banthungprong In that case we'd want to leave the config itself alone and not run the ffmpeg commands if the camera is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we talk about 3 different requirements:

  1. static: Option in config, only used one time when starting the container (the original requirement for this PR). Camera settings aren't loaded in config.py.
  2. dynamic: Camera can be disabled or enabled while running frigate, so the config is changed in the UI. State of the camera will be saved "somewhere else" but not in the config. Settings are always available.
  3. "A bit of both": Option in config, when starting frigate the settings are loaded but the views (recording/events/live/rtmp etc) do not show a disabled camera. But additionaly features in the UI to enable/disable every camera. Setting are always available.

Is it enough to "not run the ffmpeg commands" or is more logic necessary in the different views when a camera isn't shown (example: Events View, dropdown Filter)? I will start digging and trying here today.

Close this pull request and make a new one based on requirement 2 or 3?
Or update this one and switch to the dynamic solution?

If starting to change parameters dynamically (enabled/disabled is only a first possibility) shouldn't there be a view for configurations showing each camera with a list of parameters that might be changed in the UI (resolution, framerate, 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.

The dynamic solution should come later, that's not what's being suggested.

This solution should still be static. The thing that's being discussed is we don't want the cameras config completely removed as we still want the retention settings to be applied. If a camera is disabled it just shouldn't be running, it should still show in the dropdowns and other places because you may still want to view those events

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

Close this pull request and make a new one based on requirement 2 or 3?
Or update this one and switch to the dynamic solution?

I don't think there's a reason to close, but again we don't need the dynamic solution implemented. Just static solution that maintains camera settings in the config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I started looking already in app.py. And "some other places". I will try it and I hope it won't get too annoying if my commits aren't perfect...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not starting the process when the camera is disabled is working already.
Birdseye, Events, Debug all ok.
In Cameras: I hate the green image when no camera snapshot/stream is available...

Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

In Cameras: I hate the green image when no camera snapshot/stream is available...

That is on the list to improve in the 0.12.0 release, so I'd say leave it with the green screens for now as that is a separate PR which will address the green screen. Maybe having one message for cameras with errors and a different message for disabled cameras.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not start camera processors and capture processes when a camera is disabled. Working. Will commit in the morning. Too tired now.

Naming looks strange:
start_camera_processors vs start_capture_processes
whereas inside camera_process and capture_process looks ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is on the list to improve in the 0.12.0 release, so I'd say leave it with the green screens for now as that is a separate PR which will address the green screen. Maybe having one message for cameras with errors and a different message for disabled cameras.

I couldn't resist:
Screenshot from 2022-10-27 10-39-01

Copy link
Sponsor Collaborator

@NickM-27 NickM-27 left a comment

Choose a reason for hiding this comment

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

Just some small stuff

frigate/app.py Show resolved Hide resolved
@@ -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

@@ -62,6 +62,7 @@ detectors:

cameras:
camera_1: # <------ Name the camera
enabled: True # <----- Enable/disable camera
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it makes sense to put it here, this section is the minimal config and this isn't necessary

frigate/app.py Show resolved Hide resolved
@@ -816,7 +817,7 @@ def runtime_config(self) -> FrigateConfig:
exclude_unset=True,
)

for name, camera in config.cameras.items():
for name, camera in config.cameras.copy().items():
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

Don't need the copy here anymore

@netlify
Copy link

netlify bot commented Oct 30, 2022

Deploy Preview for frigate-docs ready!

Name Link
🔨 Latest commit 2fa0316
🔍 Latest deploy log https://app.netlify.com/sites/frigate-docs/deploys/635eade705859300083748b8
😎 Deploy Preview https://deploy-preview-4162--frigate-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@banthungprong
Copy link
Contributor Author

banthungprong commented Oct 30, 2022

Commit comment length was limited (I just changed that in VS Code). So here a summary of the changes:

  • changed the if-logic as reqested (2x) in app.py
  • removed obsolete copy() in config.py
  • removed enabled option in minimal camera configuration in getting_started.md
  • added info in Cameras View when a camera is disabled and avoid green image in CameraImage.jsx

I didn't change the "wrong indentation" because I simply do not understand what might be wrong.

Comment on lines 383 to 385
# 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.
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

web/src/components/CameraImage.jsx Outdated Show resolved Hide resolved
Comment on lines 383 to 385
# 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.
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

@banthungprong
Copy link
Contributor Author

banthungprong commented Oct 30, 2022

A few lines above the indentation was used in the same way. It's not really consistent in the complete file.
But thanks for the replies and reviews. It's really helpful and nice to work like this.

@NickM-27
Copy link
Sponsor Collaborator

A few lines above the indentation was used in the same way. It's not really consistent in the complete file.
But thanks for the replies and reviews. It's really helpful and nice to work like this.

The ones that are indented start with WARNING: or NOTE: and are one statement. General descriptions around how the settings work should not be indented.

@blakeblackshear blakeblackshear merged commit 8163afc into blakeblackshear:dev Nov 2, 2022
herostrat pushed a commit to herostrat/frigate that referenced this pull request Nov 24, 2022
* 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
@Zaschii
Copy link

Zaschii commented Apr 3, 2023

Is there also the possibility to disable a cam per mqtt?
Because i have a webcam which is not always online - so how can i automate this (changing the config file per script is not really a smooth solution in my mind). Thx & BR

@TheSleepySlee
Copy link

This works perfectly, thanks for this new option!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants