Add test for video encoding

This commit is contained in:
Nick Mowen 2023-01-03 13:21:20 -07:00
parent e5038b958b
commit 49eb19b793
3 changed files with 19 additions and 15 deletions

View File

@ -515,8 +515,6 @@ class JsmpegStreamConfig(FrigateBaseModel):
class RestreamCodecEnum(str, Enum): class RestreamCodecEnum(str, Enum):
"""Represents different options for encoding the restream."""
copy = "copy" copy = "copy"
h264 = "h264" h264 = "h264"
h265 = "h265" h265 = "h265"
@ -524,8 +522,8 @@ class RestreamCodecEnum(str, Enum):
class RestreamConfig(FrigateBaseModel): class RestreamConfig(FrigateBaseModel):
enabled: bool = Field(default=True, title="Restreaming enabled.") enabled: bool = Field(default=True, title="Restreaming enabled.")
video_codec: RestreamCodecEnum = Field( video_encoding: RestreamCodecEnum = Field(
defualt=RestreamCodecEnum.copy, title="Method for encoding the restream." default=RestreamCodecEnum.copy, title="Method for encoding the restream."
) )
force_audio: bool = Field( force_audio: bool = Field(
default=True, title="Force audio compatibility with the browser." default=True, title="Force audio compatibility with the browser."

View File

@ -56,14 +56,12 @@ class RestreamApi:
else: else:
# go2rtc only supports rtsp for direct relay, otherwise ffmpeg is used # go2rtc only supports rtsp for direct relay, otherwise ffmpeg is used
self.relays[cam_name] = get_manual_go2rtc_stream( self.relays[cam_name] = get_manual_go2rtc_stream(
escape_special_characters( escape_special_characters(input.path),
input.path, camera.restream.video_encoding,
camera.restream.video_codec,
parse_preset_hardware_acceleration_go2rtc_engine( parse_preset_hardware_acceleration_go2rtc_engine(
self.config.ffmpeg.hwaccel_args self.config.ffmpeg.hwaccel_args
), ),
) )
)
if self.config.restream.birdseye: if self.config.restream.birdseye:
self.relays[ self.relays[

View File

@ -44,22 +44,30 @@ class TestRestream(TestCase):
}, },
} }
@patch("frigate.restream.requests") def test_rtsp_stream(self) -> None:
def test_rtsp_stream(self, mock_requests) -> None:
"""Test that the normal rtsp stream is sent plainly.""" """Test that the normal rtsp stream is sent plainly."""
frigate_config = FrigateConfig(**self.config) frigate_config = FrigateConfig(**self.config)
restream = RestreamApi(frigate_config) restream = RestreamApi(frigate_config)
restream.add_cameras() restream.add_cameras()
assert restream.relays["back"].startswith("rtsp") assert restream.relays["back"].startswith("rtsp")
@patch("frigate.restream.requests") def test_http_stream(self) -> None:
def test_http_stream(self, mock_requests) -> None:
"""Test that the http stream is sent via ffmpeg.""" """Test that the http stream is sent via ffmpeg."""
frigate_config = FrigateConfig(**self.config) frigate_config = FrigateConfig(**self.config)
restream = RestreamApi(frigate_config) restream = RestreamApi(frigate_config)
restream.add_cameras() restream.add_cameras()
assert not restream.relays["front"].startswith("rtsp") 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__": if __name__ == "__main__":
main(verbosity=2) main(verbosity=2)