Add tests for scale, fix bugs

This commit is contained in:
Nick Mowen 2022-12-28 11:39:56 -07:00
parent f996103f94
commit 5dd0726fca
3 changed files with 34 additions and 10 deletions

View File

@ -627,14 +627,15 @@ class CameraConfig(FrigateBaseModel):
ffmpeg_output_args = [] ffmpeg_output_args = []
if "detect" in ffmpeg_input.roles: if "detect" in ffmpeg_input.roles:
detect_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.detect) detect_args = get_ffmpeg_arg_list(self.ffmpeg.output_args.detect)
scale_args = parse_preset_hardware_acceleration_scale(ffmpeg_input.hwaccel_args, self.detect.fps, self.detect.width, self.detect.height) scale_detect_args = parse_preset_hardware_acceleration_scale(
ffmpeg_input.hwaccel_args or self.ffmpeg.hwaccel_args,
ffmpeg_output_args = ( detect_args,
scale_args self.detect.fps,
+ detect_args self.detect.width,
+ ffmpeg_output_args self.detect.height,
+ ["pipe:"]
) )
ffmpeg_output_args = scale_detect_args + ffmpeg_output_args + ["pipe:"]
if "rtmp" in ffmpeg_input.roles and self.rtmp.enabled: if "rtmp" in ffmpeg_input.roles and self.rtmp.enabled:
rtmp_args = get_ffmpeg_arg_list( rtmp_args = get_ffmpeg_arg_list(
parse_preset_output_rtmp(self.ffmpeg.output_args.rtmp) parse_preset_output_rtmp(self.ffmpeg.output_args.rtmp)

View File

@ -140,19 +140,21 @@ def parse_preset_hardware_acceleration_decode(arg: Any) -> list[str]:
def parse_preset_hardware_acceleration_scale( def parse_preset_hardware_acceleration_scale(
arg: Any, arg: Any,
detect_args: list[str],
fps: int, fps: int,
width: int, width: int,
height: int, height: int,
) -> list[str]: ) -> list[str]:
"""Return the correct scaling preset or default preset if none is set.""" """Return the correct scaling preset or default preset if none is set."""
if not isinstance(arg, str): if not isinstance(arg, str):
scale = PRESETS_HW_ACCEL_SCALE["default"] scale = PRESETS_HW_ACCEL_SCALE["default"].copy()
scale[1] = str(fps) scale[1] = str(fps)
scale[3] = f"{width}x{height}" scale[3] = f"{width}x{height}"
scale.extend(detect_args)
return scale return scale
scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"]) scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"])
scale[1] = scale[1].format(fps, height, width) scale[1] = scale[1].format(fps, width, height)
return scale return scale
@ -282,7 +284,9 @@ def parse_preset_input(arg: Any, detect_fps: int) -> list[str]:
return None return None
if arg == "preset-jpeg-generic": if arg == "preset-jpeg-generic":
return PRESETS_INPUT[arg].format(f"{detect_fps}") input = PRESETS_INPUT[arg].copy()
input[1] = str(detect_fps)
return input
return PRESETS_INPUT.get(arg, None) return PRESETS_INPUT.get(arg, None)

View File

@ -66,6 +66,25 @@ class TestFfmpegPresets(unittest.TestCase):
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
) )
def test_ffmpeg_hwaccel_scale_preset(self):
self.default_ffmpeg["cameras"]["back"]["ffmpeg"][
"hwaccel_args"
] = "preset-nvidia-h264"
self.default_ffmpeg["cameras"]["back"]["detect"] = {
"height": 1920,
"width": 2560,
"fps": 10,
}
frigate_config = FrigateConfig(**self.default_ffmpeg)
frigate_config.cameras["back"].create_ffmpeg_cmds()
assert "preset-nvidia-h264" not in (
" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])
)
assert (
"fps=10,scale_cuda=w=2560:h=1920:format=nv12,hwdownload,format=nv12,format=yuv420p"
in (" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]))
)
def test_default_ffmpeg_input_arg_preset(self): def test_default_ffmpeg_input_arg_preset(self):
frigate_config = FrigateConfig(**self.default_ffmpeg) frigate_config = FrigateConfig(**self.default_ffmpeg)