From 762afb8f43dd2c2264b344b7e958565324905d36 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Wed, 23 Jun 2021 08:09:15 -0500 Subject: [PATCH] add config for camera live stream --- docs/docs/configuration/cameras.md | 24 +++++++++++++++++------- docs/docs/configuration/index.md | 10 +++++----- frigate/config.py | 29 +++++++++++++++++++++++++++++ frigate/output.py | 6 +++--- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/docs/docs/configuration/cameras.md b/docs/docs/configuration/cameras.md index 2f3d6c8c6..225f36677 100644 --- a/docs/docs/configuration/cameras.md +++ b/docs/docs/configuration/cameras.md @@ -240,7 +240,7 @@ timestamp_style: # Optional: Line thickness of font (default: shown below) thickness: 2 # Optional: Effect of lettering (default: shown below) - # None (No effect), + # None (No effect), # "solid" (solid background in inverse color of font) # "shadow" (shadow for font) effect: None @@ -357,9 +357,19 @@ cameras: # Optional: RTMP re-stream configuration rtmp: - # Required: Enable the live stream (default: True) + # Required: Enable the RTMP stream (default: True) enabled: True + # Optional: Live stream configuration for WebUI + live: + # Optional: Set the height of the live stream. (default: detect stream height) + # This must be less than or equal to the height of the detect stream. Lower resolutions + # reduce bandwidth required for viewing the live stream. Width is computed to match known aspect ratio. + height: 720 + # Optional: Set the encode quality of the live stream (default: shown below) + # 1 is the highest quality, and 31 is the lowest. Lower quality feeds utilize less CPU resources. + quality: 8 + # Optional: Configuration for the jpg snapshots written to the clips directory for each event snapshots: # Optional: Enable writing jpg snapshot to /media/frigate/clips (default: shown below) @@ -430,16 +440,16 @@ cameras: format: "%m/%d/%Y %H:%M:%S" # Optional: Color of font color: - # All Required when color is specified (default: shown below) - red: 255 - green: 255 - blue: 255 + # All Required when color is specified (default: shown below) + red: 255 + green: 255 + blue: 255 # Optional: Scale factor for font (default: shown below) scale: 1.0 # Optional: Line thickness of font (default: shown below) thickness: 2 # Optional: Effect of lettering (default: shown below) - # None (No effect), + # None (No effect), # "solid" (solid background in inverse color of font) # "shadow" (shadow for font) effect: None diff --git a/docs/docs/configuration/index.md b/docs/docs/configuration/index.md index d7555f25e..92cea7d4b 100644 --- a/docs/docs/configuration/index.md +++ b/docs/docs/configuration/index.md @@ -167,14 +167,14 @@ A dynamic combined camera view of all tracked cameras. This is optimized for min ```yaml birdseye: - # Optional: Enable birdseye view + # Optional: Enable birdseye view (default: shown below) enabled: True - # Optional: Width of the output resolution + # Optional: Width of the output resolution (default: shown below) width: 1280 - # Optional: Height of the output resolution + # Optional: Height of the output resolution (default: shown below) height: 720 - # Optional: Encoding quality of the mpeg1 feed. 1 is the highest quality, and 31 is the lowest. - # Lower quality feeds utilize less CPU resources. + # Optional: Encoding quality of the mpeg1 feed (default: shown below) + # 1 is the highest quality, and 31 is the lowest. Lower quality feeds utilize less CPU resources. quality: 8 # Optional: Mode of the view. Available options are: objects, motion, and continuous # objects - cameras are included if they have had a tracked object within the last 30 seconds diff --git a/frigate/config.py b/frigate/config.py index eb792fc1f..0f86243e9 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -649,6 +649,10 @@ CAMERAS_SCHEMA = vol.Schema( vol.Optional("rtmp", default={}): { vol.Required("enabled", default=True): bool, }, + vol.Optional("live", default={}): { + "height": int, + vol.Optional("quality", default=8): vol.Range(min=1, max=31), + }, vol.Optional("snapshots", default={}): { vol.Optional("enabled", default=False): bool, vol.Optional("clean_copy", default=True): bool, @@ -827,6 +831,27 @@ class CameraRtmpConfig: return dataclasses.asdict(self) +@dataclasses.dataclass +class CameraLiveConfig: + height: int + width: int + quality: int + + @classmethod + def build(cls, config, camera_height, camera_width) -> CameraRtmpConfig: + if "height" in config and config["height"] <= camera_height: + height = config["height"] + width = int(height * (camera_width / camera_height)) + else: + height = camera_height + width = camera_width + + return CameraLiveConfig(height, width, config["quality"]) + + def to_dict(self) -> Dict[str, Any]: + return dataclasses.asdict(self) + + @dataclasses.dataclass(frozen=True) class CameraConfig: name: str @@ -839,6 +864,7 @@ class CameraConfig: clips: CameraClipsConfig record: RecordConfig rtmp: CameraRtmpConfig + live: CameraLiveConfig snapshots: CameraSnapshotsConfig mqtt: CameraMqttConfig objects: ObjectConfig @@ -886,6 +912,9 @@ class CameraConfig: clips=CameraClipsConfig.build(config["clips"], global_config), record=RecordConfig.build(config["record"], global_config["record"]), rtmp=CameraRtmpConfig.build(config["rtmp"]), + live=CameraLiveConfig.build( + config["live"], config["height"], config["width"] + ), snapshots=CameraSnapshotsConfig.build(config["snapshots"], global_config), mqtt=CameraMqttConfig.build(config["mqtt"]), objects=ObjectConfig.build( diff --git a/frigate/output.py b/frigate/output.py index 384f3f07c..ce6ba272f 100644 --- a/frigate/output.py +++ b/frigate/output.py @@ -346,9 +346,9 @@ def output_frames(config: FrigateConfig, video_output_queue): converters[camera] = FFMpegConverter( cam_config.frame_shape[1], cam_config.frame_shape[0], - cam_config.frame_shape[1], - cam_config.frame_shape[0], - 8, + cam_config.live.width, + cam_config.live.height, + cam_config.live.quality, ) broadcasters[camera] = BroadcastThread( camera, converters[camera], websocket_server