Migrate birdseye stream definition to S6

This commit is contained in:
Nick Mowen 2023-02-13 17:14:02 -07:00
parent c5dd20ae67
commit 6d025f5eaf

View File

@ -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,7 +49,10 @@ 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
@ -67,9 +77,24 @@ 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))