From 6d025f5eaf041f4021c4dde65b3b2509b01ab5f0 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Mon, 13 Feb 2023 17:14:02 -0700 Subject: [PATCH] Migrate birdseye stream definition to S6 --- .../rootfs/usr/local/go2rtc/create_config.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py index 580963431..8bf4f0eee 100644 --- a/docker/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/rootfs/usr/local/go2rtc/create_config.py @@ -5,8 +5,13 @@ import os import sys import yaml +import sys + +sys.path.insert(0, "/opt/frigate/frigate/ffmpeg_presets.py") + BTBN_PATH = "/usr/lib/btbn-ffmpeg" +BIRDSEYE_PIPE = "/tmp/cache/birdseye" FRIGATE_ENV_VARS = {k: v for k, v in os.environ.items() if k.startswith("FRIGATE_")} config_file = os.environ.get("CONFIG_FILE", "/config/config.yml") @@ -34,7 +39,9 @@ elif go2rtc_config["log"].get("format") is None: if not go2rtc_config.get("webrtc", {}).get("candidates", []): default_candidates = [] # use internal candidate if it was discovered when running through the add-on - internal_candidate = os.environ.get("FRIGATE_GO2RTC_WEBRTC_CANDIDATE_INTERNAL", None) + internal_candidate = os.environ.get( + "FRIGATE_GO2RTC_WEBRTC_CANDIDATE_INTERNAL", None + ) if internal_candidate is not None: default_candidates.append(internal_candidate) # should set default stun server so webrtc can work @@ -42,8 +49,11 @@ if not go2rtc_config.get("webrtc", {}).get("candidates", []): go2rtc_config["webrtc"] = {"candidates": default_candidates} else: - print("[INFO] Not injecting WebRTC candidates into go2rtc config as it has been set manually", file=sys.stderr) - + print( + "[INFO] Not injecting WebRTC candidates into go2rtc config as it has been set manually", + file=sys.stderr, + ) + # sets default RTSP response to be equivalent to ?video=h264,h265&audio=aac # this means user does not need to specify audio codec when using restream # as source for frigate and the integration supports HLS playback @@ -62,14 +72,29 @@ if not os.path.exists(BTBN_PATH): go2rtc_config["ffmpeg"][ "rtsp" ] = "-fflags nobuffer -flags low_delay -stimeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}" - + for name in go2rtc_config.get("streams", {}): stream = go2rtc_config["streams"][name] if isinstance(stream, str): - go2rtc_config["streams"][name] = go2rtc_config["streams"][name].format(**FRIGATE_ENV_VARS) + go2rtc_config["streams"][name] = go2rtc_config["streams"][name].format( + **FRIGATE_ENV_VARS + ) elif isinstance(stream, list): for i, stream in enumerate(stream): go2rtc_config["streams"][name][i] = stream.format(**FRIGATE_ENV_VARS) +# add birdseye restream stream if enabled +if config.get("birdseye", {}).get("restream", False): + birdseye = config.get("birdseye") + + input = f"-f rawvideo -pix_fmt yuv420p -video_size {birdseye.get('width', 1280)}x{birdseye.get('height', 720)} -r 10 -i {BIRDSEYE_PIPE}" + ffmpeg_cmd = f"exec:{parse_preset_hardware_acceleration_encode(config.get('ffmpeg', {}).get('hwaccel_args'), input, '-rtsp_transport tcp -f rtsp {output}')}" + + if go2rtc_config.get("streams"): + go2rtc_config["streams"]["birdseye"] = ffmpeg_cmd + else: + go2rtc_config["streams"] = {"birdseye": ffmpeg_cmd} + + print(json.dumps(go2rtc_config))