From 49eb19b79331af8443de2e423034e07430c2c22e Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 3 Jan 2023 13:21:20 -0700 Subject: [PATCH] Add test for video encoding --- frigate/config.py | 6 ++---- frigate/restream.py | 12 +++++------- frigate/test/test_restream.py | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index 161ab8db9..1dc59c30f 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -515,8 +515,6 @@ class JsmpegStreamConfig(FrigateBaseModel): class RestreamCodecEnum(str, Enum): - """Represents different options for encoding the restream.""" - copy = "copy" h264 = "h264" h265 = "h265" @@ -524,8 +522,8 @@ class RestreamCodecEnum(str, Enum): class RestreamConfig(FrigateBaseModel): enabled: bool = Field(default=True, title="Restreaming enabled.") - video_codec: RestreamCodecEnum = Field( - defualt=RestreamCodecEnum.copy, title="Method for encoding the restream." + video_encoding: RestreamCodecEnum = Field( + default=RestreamCodecEnum.copy, title="Method for encoding the restream." ) force_audio: bool = Field( default=True, title="Force audio compatibility with the browser." diff --git a/frigate/restream.py b/frigate/restream.py index 50f690b99..6ef6ebade 100644 --- a/frigate/restream.py +++ b/frigate/restream.py @@ -56,13 +56,11 @@ class RestreamApi: 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.video_codec, - parse_preset_hardware_acceleration_go2rtc_engine( - self.config.ffmpeg.hwaccel_args - ), - ) + escape_special_characters(input.path), + camera.restream.video_encoding, + parse_preset_hardware_acceleration_go2rtc_engine( + self.config.ffmpeg.hwaccel_args + ), ) if self.config.restream.birdseye: diff --git a/frigate/test/test_restream.py b/frigate/test/test_restream.py index 6e4096a05..8d577b8a4 100644 --- a/frigate/test/test_restream.py +++ b/frigate/test/test_restream.py @@ -44,22 +44,30 @@ class TestRestream(TestCase): }, } - @patch("frigate.restream.requests") - def test_rtsp_stream(self, mock_requests) -> None: + def test_rtsp_stream(self) -> None: """Test that the normal rtsp stream is sent plainly.""" frigate_config = FrigateConfig(**self.config) restream = RestreamApi(frigate_config) restream.add_cameras() assert restream.relays["back"].startswith("rtsp") - @patch("frigate.restream.requests") - def test_http_stream(self, mock_requests) -> None: + def test_http_stream(self) -> None: """Test that the http stream is sent via ffmpeg.""" frigate_config = FrigateConfig(**self.config) restream = RestreamApi(frigate_config) restream.add_cameras() assert not restream.relays["front"].startswith("rtsp") + def test_restream_codec_change(self) -> None: + """Test that the http stream is sent via ffmpeg.""" + self.config["cameras"]["front"]["restream"]["video_encoding"] = "h265" + self.config["ffmpeg"] = {"hwaccel_args": "preset-nvidia-h264"} + frigate_config = FrigateConfig(**self.config) + restream = RestreamApi(frigate_config) + restream.add_cameras() + assert "#hardware=cuda" in restream.relays["front"] + assert "#video=h265" in restream.relays["front"] + if __name__ == "__main__": main(verbosity=2)