mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Add tests for scale, fix bugs
This commit is contained in:
parent
f996103f94
commit
5dd0726fca
@ -627,14 +627,15 @@ class CameraConfig(FrigateBaseModel):
|
||||
ffmpeg_output_args = []
|
||||
if "detect" in ffmpeg_input.roles:
|
||||
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)
|
||||
|
||||
ffmpeg_output_args = (
|
||||
scale_args
|
||||
+ detect_args
|
||||
+ ffmpeg_output_args
|
||||
+ ["pipe:"]
|
||||
scale_detect_args = parse_preset_hardware_acceleration_scale(
|
||||
ffmpeg_input.hwaccel_args or self.ffmpeg.hwaccel_args,
|
||||
detect_args,
|
||||
self.detect.fps,
|
||||
self.detect.width,
|
||||
self.detect.height,
|
||||
)
|
||||
|
||||
ffmpeg_output_args = scale_detect_args + ffmpeg_output_args + ["pipe:"]
|
||||
if "rtmp" in ffmpeg_input.roles and self.rtmp.enabled:
|
||||
rtmp_args = get_ffmpeg_arg_list(
|
||||
parse_preset_output_rtmp(self.ffmpeg.output_args.rtmp)
|
||||
|
||||
@ -140,19 +140,21 @@ def parse_preset_hardware_acceleration_decode(arg: Any) -> list[str]:
|
||||
|
||||
def parse_preset_hardware_acceleration_scale(
|
||||
arg: Any,
|
||||
detect_args: list[str],
|
||||
fps: int,
|
||||
width: int,
|
||||
height: int,
|
||||
) -> list[str]:
|
||||
"""Return the correct scaling preset or default preset if none is set."""
|
||||
if not isinstance(arg, str):
|
||||
scale = PRESETS_HW_ACCEL_SCALE["default"]
|
||||
scale = PRESETS_HW_ACCEL_SCALE["default"].copy()
|
||||
scale[1] = str(fps)
|
||||
scale[3] = f"{width}x{height}"
|
||||
scale.extend(detect_args)
|
||||
return scale
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -282,7 +284,9 @@ def parse_preset_input(arg: Any, detect_fps: int) -> list[str]:
|
||||
return None
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@ -66,6 +66,25 @@ class TestFfmpegPresets(unittest.TestCase):
|
||||
" ".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):
|
||||
frigate_config = FrigateConfig(**self.default_ffmpeg)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user