Rework birdseye restream

This commit is contained in:
Nick Mowen 2023-01-15 17:04:38 -07:00
parent 72ffb9d5f6
commit 226b7e9efd
2 changed files with 3 additions and 56 deletions

View File

@ -344,6 +344,7 @@ class BirdseyeModeEnum(str, Enum):
class BirdseyeConfig(FrigateBaseModel): class BirdseyeConfig(FrigateBaseModel):
enabled: bool = Field(default=True, title="Enable birdseye view.") enabled: bool = Field(default=True, title="Enable birdseye view.")
restream: bool = Field(default=False, title="Restream birdseye via RTSP.")
width: int = Field(default=1280, title="Birdseye width.") width: int = Field(default=1280, title="Birdseye width.")
height: int = Field(default=720, title="Birdseye height.") height: int = Field(default=720, title="Birdseye height.")
quality: int = Field( quality: int = Field(

View File

@ -4,42 +4,15 @@
import logging import logging
import requests import requests
from typing import Optional from frigate.config import FrigateConfig
from frigate.config import FrigateConfig, RestreamAudioCodecEnum, RestreamVideoCodecEnum
from frigate.const import BIRDSEYE_PIPE from frigate.const import BIRDSEYE_PIPE
from frigate.ffmpeg_presets import ( from frigate.ffmpeg_presets import (
parse_preset_hardware_acceleration_encode, parse_preset_hardware_acceleration_encode,
parse_preset_hardware_acceleration_go2rtc_engine,
) )
from frigate.util import escape_special_characters
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_manual_go2rtc_stream(
camera_url: str,
aCodecs: list[RestreamAudioCodecEnum],
vCodec: RestreamVideoCodecEnum,
engine: Optional[str],
) -> str:
"""Get a manual stream for go2rtc."""
stream = f"ffmpeg:{camera_url}"
for aCodec in aCodecs:
stream += f"#audio={aCodec}"
if vCodec == RestreamVideoCodecEnum.copy:
stream += "#video=copy"
else:
stream += f"#video={vCodec}"
if engine:
stream += f"#hardware={engine}"
return stream
class RestreamApi: class RestreamApi:
"""Control go2rtc relay API.""" """Control go2rtc relay API."""
@ -50,34 +23,7 @@ class RestreamApi:
"""Add cameras to go2rtc.""" """Add cameras to go2rtc."""
self.relays: dict[str, str] = {} self.relays: dict[str, str] = {}
for cam_name, camera in self.config.cameras.items(): if self.config.birdseye.restream:
if not camera.restream.enabled:
continue
for input in camera.ffmpeg.inputs:
if "restream" in input.roles:
if (
input.path.startswith("rtsp")
and camera.restream.video_encoding
== RestreamVideoCodecEnum.copy
and camera.restream.audio_encoding
== [RestreamAudioCodecEnum.copy]
):
self.relays[
cam_name
] = f"{escape_special_characters(input.path)}#backchannel=0"
else:
# go2rtc only supports rtsp for direct relay, otherwise ffmpeg is used
self.relays[cam_name] = get_manual_go2rtc_stream(
escape_special_characters(input.path),
camera.restream.audio_encoding,
camera.restream.video_encoding,
parse_preset_hardware_acceleration_go2rtc_engine(
self.config.ffmpeg.hwaccel_args
),
)
if self.config.restream.birdseye:
self.relays[ self.relays[
"birdseye" "birdseye"
] = f"exec:{parse_preset_hardware_acceleration_encode(self.config.ffmpeg.hwaccel_args, f'-f rawvideo -pix_fmt yuv420p -video_size {self.config.birdseye.width}x{self.config.birdseye.height} -r 10 -i {BIRDSEYE_PIPE}', '-rtsp_transport tcp -f rtsp {output}')}" ] = f"exec:{parse_preset_hardware_acceleration_encode(self.config.ffmpeg.hwaccel_args, f'-f rawvideo -pix_fmt yuv420p -video_size {self.config.birdseye.width}x{self.config.birdseye.height} -r 10 -i {BIRDSEYE_PIPE}', '-rtsp_transport tcp -f rtsp {output}')}"