diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 78c0b8389..477c574b3 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -25,7 +25,7 @@ ffmpeg: ```yaml ffmpeg: - hwaccel_args: preset-intel-vaapi + hwaccel_args: preset-vaapi ``` **NOTICE**: With some of the processors, like the J4125, the default driver `iHD` doesn't seem to work correctly for hardware acceleration. You may need to change the driver to `i965` by adding the following environment variable `LIBVA_DRIVER_NAME=i965` to your docker-compose file or [in the frigate.yml for HA OS users](advanced.md#environment_vars). @@ -42,7 +42,7 @@ ffmpeg: ```yaml ffmpeg: - hwaccel_args: preset-amd-vaapi + hwaccel_args: preset-vaapi ``` ### NVIDIA GPU diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index b6ec49b21..27c7d1636 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -114,90 +114,12 @@ PRESETS_HW_ACCEL_SCALE = { } PRESETS_HW_ACCEL_ENCODE = { - "preset-vaapi": [ - "-c:v", - "h264_vaapi", - "-g", - "50", - "-bf", - "0", - "-profile:v", - "high", - "-level:v", - "4.1", - "-sei:v", - "0", - ], - "preset-intel-qsv-h264": [ - "-c:v", - "h264_qsv", - "-g", - "50", - "-bf", - "0", - "-profile:v", - "high", - "-level:v", - "4.1", - "-async_depth:v", - "1", - ], - "preset-intel-qsv-h265": [ - "-c:v", - "h264_qsv", - "-g", - "50", - "-bf", - "0", - "-profile:v", - "high", - "-level:v", - "4.1", - "-async_depth:v", - "1", - ], - "preset-nvidia-h264": [ - "-c:v", - "h264_nvenc", - "-g", - "50", - "-profile:v", - "high", - "-level:v", - "auto", - "-preset:v", - "p2", - "-tune:v", - "ll", - ], - "preset-nvidia-h265": [ - "-c:v", - "h264_nvenc", - "-g", - "50", - "-profile:v", - "high", - "-level:v", - "auto", - "-preset:v", - "p2", - "-tune:v", - "ll", - ], - "default": [ - "-c:v", - "libx264", - "-g", - "50", - "-profile:v", - "high", - "-level:v", - "4.1", - "-preset:v", - "superfast", - "-tune:v", - "zerolatency", - ], + "preset-vaapi": "ffmpeg -hide_banner -vaapi_device /dev/dri/renderD128 {} -vf 'format=yuv420p,hwupload' -c:v h264_vaapi -g 50 -bf 0 -profile:v high -level:v 4.1 -sei:v 0 {}", + "preset-intel-qsv-h264": "ffmepg -hide_banner {} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {}", + "preset-intel-qsv-h265": "ffmepg -hide_banner {} -c:v h264_qsv -g 50 -bf 0 -profile:v high -level:v 4.1 -async_depth:v 1 {}", + "preset-nvidia-h264": "ffmepg -hide_banner {} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {}", + "preset-nvidia-h265": "ffmepg -hide_banner {} -c:v h264_nvenc -g 50 -profile:v high -level:v auto -preset:v p2 -tune:v ll {}", + "default": "ffmepg -hide_banner {} -c:v libx264 -g 50 -profile:v high -level:v 4.1 -preset:v superfast -tune:v zerolatency {}", } @@ -229,12 +151,12 @@ def parse_preset_hardware_acceleration_scale( return scale -def parse_preset_hardware_acceleration_encode(arg: Any) -> list[str]: +def parse_preset_hardware_acceleration_encode(arg: Any, input: str, output: str) -> str: """Return the correct scaling preset or default preset if none is set.""" if not isinstance(arg, str): - return PRESETS_HW_ACCEL_ENCODE["default"] + return PRESETS_HW_ACCEL_ENCODE["default"] % (input, output) - return PRESETS_HW_ACCEL_ENCODE.get(arg, PRESETS_HW_ACCEL_ENCODE["default"]) + return PRESETS_HW_ACCEL_ENCODE.get(arg, PRESETS_HW_ACCEL_ENCODE["default"]) % (input, output) PRESETS_INPUT = { diff --git a/frigate/restream.py b/frigate/restream.py index 6642fbeb4..6062be122 100644 --- a/frigate/restream.py +++ b/frigate/restream.py @@ -47,7 +47,7 @@ class RestreamApi: if self.config.restream.birdseye: self.relays[ "birdseye" - ] = f"exec:ffmpeg -hide_banner -f rawvideo -pix_fmt yuv420p -video_size {self.config.birdseye.width}x{self.config.birdseye.height} -r 10 -i {BIRDSEYE_PIPE} {' '.join(parse_preset_hardware_acceleration_encode(self.config.ffmpeg.hwaccel_args))} -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}')}" for name, path in self.relays.items(): params = {"src": path, "name": name}