From a705fed710d132d0bd3ba1647c5c52b84b39330c Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 11:21:46 -0600 Subject: [PATCH 01/11] Update ffmpeg to 7 and update intel hwaccel docs --- docker/main/install_deps.sh | 16 ++++++------ .../rootfs/usr/local/go2rtc/create_config.py | 16 ++++++------ docker/rockchip/Dockerfile | 1 + .../configuration/hardware_acceleration.md | 26 ++++++++++++------- frigate/config.py | 20 +++++++------- frigate/const.py | 4 ++- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/docker/main/install_deps.sh b/docker/main/install_deps.sh index 327053edda..9664c45740 100755 --- a/docker/main/install_deps.sh +++ b/docker/main/install_deps.sh @@ -40,25 +40,25 @@ apt-get -qq install --no-install-recommends --no-install-suggests -y \ # btbn-ffmpeg -> amd64 if [[ "${TARGETARCH}" == "amd64" ]]; then mkdir -p /usr/lib/ffmpeg/5.0 - mkdir -p /usr/lib/ffmpeg/6.0 + mkdir -p /usr/lib/ffmpeg/7.0 wget -qO btbn-ffmpeg.tar.xz "https://github.com/NickM-27/FFmpeg-Builds/releases/download/autobuild-2022-07-31-12-37/ffmpeg-n5.1-2-g915ef932a3-linux64-gpl-5.1.tar.xz" tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/5.0 --strip-components 1 rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/5.0/doc /usr/lib/ffmpeg/5.0/bin/ffplay - wget -qO btbn-ffmpeg.tar.xz "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2024-08-31-12-50/ffmpeg-n6.1.2-2-gb534cc666e-linux64-gpl-6.1.tar.xz" - tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/6.0 --strip-components 1 - rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/6.0/doc /usr/lib/ffmpeg/6.0/bin/ffplay + wget -qO btbn-ffmpeg.tar.xz "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2024-09-19-12-51/ffmpeg-n7.0.2-18-g3e6cec1286-linux64-gpl-7.0.tar.xz" + tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/7.0 --strip-components 1 + rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/7.0/doc /usr/lib/ffmpeg/7.0/bin/ffplay fi # ffmpeg -> arm64 if [[ "${TARGETARCH}" == "arm64" ]]; then mkdir -p /usr/lib/ffmpeg/5.0 - mkdir -p /usr/lib/ffmpeg/6.0 + mkdir -p /usr/lib/ffmpeg/7.0 wget -qO btbn-ffmpeg.tar.xz "https://github.com/NickM-27/FFmpeg-Builds/releases/download/autobuild-2022-07-31-12-37/ffmpeg-n5.1-2-g915ef932a3-linuxarm64-gpl-5.1.tar.xz" tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/5.0 --strip-components 1 rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/5.0/doc /usr/lib/ffmpeg/5.0/bin/ffplay - wget -qO btbn-ffmpeg.tar.xz "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2024-08-31-12-50/ffmpeg-n6.1.2-2-gb534cc666e-linuxarm64-gpl-6.1.tar.xz" - tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/6.0 --strip-components 1 - rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/6.0/doc /usr/lib/ffmpeg/6.0/bin/ffplay + wget -qO btbn-ffmpeg.tar.xz "hhttps://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2024-09-19-12-51/ffmpeg-n7.0.2-18-g3e6cec1286-linuxarm64-gpl-7.0.tar.xz" + tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/ffmpeg/7.0 --strip-components 1 + rm -rf btbn-ffmpeg.tar.xz /usr/lib/ffmpeg/7.0/doc /usr/lib/ffmpeg/7.0/bin/ffplay fi # arch specific packages diff --git a/docker/main/rootfs/usr/local/go2rtc/create_config.py b/docker/main/rootfs/usr/local/go2rtc/create_config.py index d33e4da9eb..a9abbe1d1c 100644 --- a/docker/main/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/main/rootfs/usr/local/go2rtc/create_config.py @@ -9,10 +9,12 @@ import yaml sys.path.insert(0, "/opt/frigate") -from frigate.const import BIRDSEYE_PIPE # noqa: E402 -from frigate.ffmpeg_presets import ( # noqa: E402 - parse_preset_hardware_acceleration_encode, +from frigate.const import ( + BIRDSEYE_PIPE, + DEFAULT_FFMPEG_VERSION, + INCLUDED_FFMPEG_VERSIONS, ) +from frigate.ffmpeg_presets import parse_preset_hardware_acceleration_encode sys.path.remove("/opt/frigate") @@ -110,13 +112,11 @@ path = config.get("ffmpeg", {}).get("path", "default") if path == "default": if shutil.which("ffmpeg") is None: - ffmpeg_path = "/usr/lib/ffmpeg/6.0/bin/ffmpeg" + ffmpeg_path = f"/usr/lib/ffmpeg/{DEFAULT_FFMPEG_VERSION}/bin/ffmpeg" else: ffmpeg_path = "ffmpeg" -elif path == "6.0": - ffmpeg_path = "/usr/lib/ffmpeg/6.0/bin/ffmpeg" -elif path == "5.0": - ffmpeg_path = "/usr/lib/ffmpeg/5.0/bin/ffmpeg" +elif path in INCLUDED_FFMPEG_VERSIONS: + ffmpeg_path = f"/usr/lib/ffmpeg/{path}/bin/ffmpeg" else: ffmpeg_path = f"{path}/bin/ffmpeg" diff --git a/docker/rockchip/Dockerfile b/docker/rockchip/Dockerfile index 9087efcd2d..e1b43c2553 100644 --- a/docker/rockchip/Dockerfile +++ b/docker/rockchip/Dockerfile @@ -24,3 +24,4 @@ RUN rm -rf /usr/lib/btbn-ffmpeg/bin/ffmpeg RUN rm -rf /usr/lib/btbn-ffmpeg/bin/ffprobe ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-5/ffmpeg /usr/lib/ffmpeg/6.0/bin/ ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-5/ffprobe /usr/lib/ffmpeg/6.0/bin/ +ENV PATH="/usr/lib/ffmpeg/6.0/bin/:${PATH}" diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 0b62a0f088..8cf2b73336 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -65,24 +65,30 @@ Or map in all the `/dev/video*` devices. ## Intel-based CPUs -### Via VAAPI +**Recommended hwaccel Preset** -VAAPI supports automatic profile selection so it will work automatically with both H.264 and H.265 streams. VAAPI is recommended for all generations of Intel-based CPUs. - -```yaml -ffmpeg: - hwaccel_args: preset-vaapi -``` +| CPU Generation | Intel Driver | Recommended Preset | Notes | +| <= gen7 | i965 | preset-vaapi | qsv is not supported | +| gen8 - gen12 | iHD | preset-vaapi | preset-intel-qsv-* can also be used | +| gen13+ | iHD / Xe | preset-intel-qsv-* | | +| Intel Arc GPU | iHD / Xe | preset-intel-qsv-* | | :::note -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.yaml` for HA OS users](advanced.md#environment_vars). +The default driver is `iHD`. 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.yaml` for HA OS users](advanced.md#environment_vars). ::: -### Via Quicksync (>=10th Generation only) +### Via VAAPI + +VAAPI supports automatic profile selection so it will work automatically with both H.264 and H.265 streams. + +```yaml +ffmpeg: + hwaccel_args: preset-vaapi +``` -If VAAPI does not work for you, you can try QSV if your processor supports it. QSV must be set specifically based on the video encoding of the stream. +### Via Quicksync #### H.264 streams diff --git a/frigate/config.py b/frigate/config.py index ad96cebef8..b1af9c51b7 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -26,7 +26,9 @@ CACHE_DIR, CACHE_SEGMENT_FORMAT, DEFAULT_DB_PATH, + DEFAULT_FFMPEG_VERSION, FREQUENCY_STATS_POINTS, + INCLUDED_FFMPEG_VERSIONS, MAX_PRE_CAPTURE, REGEX_CAMERA_NAME, YAML_EXT, @@ -896,27 +898,23 @@ class FfmpegConfig(FrigateBaseModel): def ffmpeg_path(self) -> str: if self.path == "default": if shutil.which("ffmpeg") is None: - return "/usr/lib/ffmpeg/6.0/bin/ffmpeg" + return f"/usr/lib/ffmpeg/{DEFAULT_FFMPEG_VERSION}/bin/ffmpeg" else: return "ffmpeg" - elif self.path == "6.0": - return "/usr/lib/ffmpeg/6.0/bin/ffmpeg" - elif self.path == "5.0": - return "/usr/lib/ffmpeg/5.0/bin/ffmpeg" + elif self.path in INCLUDED_FFMPEG_VERSIONS: + return f"/usr/lib/ffmpeg/{self.path}/bin/ffmpeg" else: return f"{self.path}/bin/ffmpeg" @property def ffprobe_path(self) -> str: if self.path == "default": - if int(os.getenv("LIBAVFORMAT_VERSION_MAJOR", "59")) >= 59: - return "/usr/lib/ffmpeg/6.0/bin/ffprobe" + if shutil.which("ffprobe") is None: + return f"/usr/lib/ffmpeg/{DEFAULT_FFMPEG_VERSION}/bin/ffprobe" else: return "ffprobe" - elif self.path == "6.0": - return "/usr/lib/ffmpeg/6.0/bin/ffprobe" - elif self.path == "5.0": - return "/usr/lib/ffmpeg/5.0/bin/ffprobe" + elif self.path in INCLUDED_FFMPEG_VERSIONS: + return f"/usr/lib/ffmpeg/{self.path}/bin/ffprobe" else: return f"{self.path}/bin/ffprobe" diff --git a/frigate/const.py b/frigate/const.py index c5cc41b3ec..681873c319 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -43,8 +43,10 @@ MAX_WAL_SIZE = 10 # MB -# Ffmpeg Presets +# Ffmpeg constants +DEFAULT_FFMPEG_VERSION = "7.0" +INCLUDED_FFMPEG_VERSIONS = ["7.0","5.0"] FFMPEG_HWACCEL_NVIDIA = "preset-nvidia" FFMPEG_HWACCEL_VAAPI = "preset-vaapi" FFMPEG_HWACCEL_VULKAN = "preset-vulkan" From 551a3c25c7677dac56b6858ceb52c0a6622cbf3f Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 11:25:16 -0600 Subject: [PATCH 02/11] Formatting --- frigate/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frigate/const.py b/frigate/const.py index 681873c319..a0066774b1 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -46,7 +46,7 @@ # Ffmpeg constants DEFAULT_FFMPEG_VERSION = "7.0" -INCLUDED_FFMPEG_VERSIONS = ["7.0","5.0"] +INCLUDED_FFMPEG_VERSIONS = ["7.0", "5.0"] FFMPEG_HWACCEL_NVIDIA = "preset-nvidia" FFMPEG_HWACCEL_VAAPI = "preset-vaapi" FFMPEG_HWACCEL_VULKAN = "preset-vulkan" From 7f0fc0a07ee41a7a5d1c0f0cac53b558dc3c8218 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 11:29:18 -0600 Subject: [PATCH 03/11] Redo early gen naming --- docs/docs/configuration/hardware_acceleration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 8cf2b73336..121e6ae3a2 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -68,7 +68,7 @@ Or map in all the `/dev/video*` devices. **Recommended hwaccel Preset** | CPU Generation | Intel Driver | Recommended Preset | Notes | -| <= gen7 | i965 | preset-vaapi | qsv is not supported | +| gen1 - gen7 | i965 | preset-vaapi | qsv is not supported | | gen8 - gen12 | iHD | preset-vaapi | preset-intel-qsv-* can also be used | | gen13+ | iHD / Xe | preset-intel-qsv-* | | | Intel Arc GPU | iHD / Xe | preset-intel-qsv-* | | From 0f0d6a38686e1ea0291e0f68802368ab36400a96 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 11:30:50 -0600 Subject: [PATCH 04/11] Add gamma back in --- frigate/ffmpeg_presets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index 25dd809cbb..19103cdf85 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -91,7 +91,7 @@ def get_selected_gpu(self) -> str: PRESETS_HW_ACCEL_SCALE = { "preset-rpi-64-h264": "-r {0} -vf fps={0},scale={1}:{2}", "preset-rpi-64-h265": "-r {0} -vf fps={0},scale={1}:{2}", - FFMPEG_HWACCEL_VAAPI: "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", + FFMPEG_HWACCEL_VAAPI: "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2},hwdownload,eq=gamma=1.05", "preset-intel-qsv-h264": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", "preset-intel-qsv-h265": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", FFMPEG_HWACCEL_NVIDIA: "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", From aacdefd93f39ec02360b6349c0b27a690bf14ce7 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 11:32:31 -0600 Subject: [PATCH 05/11] Fix table --- docs/docs/configuration/hardware_acceleration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 121e6ae3a2..b9f2aae0d7 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -68,6 +68,7 @@ Or map in all the `/dev/video*` devices. **Recommended hwaccel Preset** | CPU Generation | Intel Driver | Recommended Preset | Notes | +| -------------- | ------------ | ------------------ | ----------------------------------- | | gen1 - gen7 | i965 | preset-vaapi | qsv is not supported | | gen8 - gen12 | iHD | preset-vaapi | preset-intel-qsv-* can also be used | | gen13+ | iHD / Xe | preset-intel-qsv-* | | From a5fb06dc534a3608b1776d43c34c7974b07c11a5 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 12:24:07 -0600 Subject: [PATCH 06/11] Add link to intel docs --- docs/docs/configuration/hardware_acceleration.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index b9f2aae0d7..867d555d83 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -78,6 +78,8 @@ Or map in all the `/dev/video*` devices. The default driver is `iHD`. 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.yaml` for HA OS users](advanced.md#environment_vars). +See [The Intel Docs](https://www.intel.com/content/www/us/en/support/articles/000005505/processors.html to figure out what generation your CPU is.) + ::: ### Via VAAPI From 878560935c6f724928a1202dd09e7b5db9306db0 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 12:37:20 -0600 Subject: [PATCH 07/11] Add hwaccel arg for disabling gamma --- frigate/ffmpeg_presets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index 19103cdf85..1cbb8af416 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -94,7 +94,7 @@ def get_selected_gpu(self) -> str: FFMPEG_HWACCEL_VAAPI: "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2},hwdownload,eq=gamma=1.05", "preset-intel-qsv-h264": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", "preset-intel-qsv-h265": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", - FFMPEG_HWACCEL_NVIDIA: "-r {0} -vf fps={0},scale_cuda=w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", + FFMPEG_HWACCEL_NVIDIA: "-r {0} -vf fps={0},scale_cuda=w={1}:h={2},hwdownload,eq=gamma=1.05", "preset-jetson-h264": "-r {0}", # scaled in decoder "preset-jetson-h265": "-r {0}", # scaled in decoder "preset-rk-h264": "-r {0} -vf scale_rkrga=w={1}:h={2}:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p", @@ -185,6 +185,9 @@ def parse_preset_hardware_acceleration_scale( else: scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"]) + if ",hwdownload,eq=gamma=1.05" in scale and os.environ.get("FFMPEG_DISABLE_GAMMA_EQUALIZER") is not None: + scale.replace(",hwdownload,eq=gamma=1.05", ":format=nv12,hwdownload,format=nv12,format=yuv420p") + scale = scale.format(fps, width, height).split(" ") scale.extend(detect_args) return scale From cc42099ec8f14c62730cd6d6fb6b0352ae725e04 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 12:38:24 -0600 Subject: [PATCH 08/11] Formatting --- frigate/ffmpeg_presets.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index 1cbb8af416..d34c22e67e 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -185,8 +185,14 @@ def parse_preset_hardware_acceleration_scale( else: scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"]) - if ",hwdownload,eq=gamma=1.05" in scale and os.environ.get("FFMPEG_DISABLE_GAMMA_EQUALIZER") is not None: - scale.replace(",hwdownload,eq=gamma=1.05", ":format=nv12,hwdownload,format=nv12,format=yuv420p") + if ( + ",hwdownload,eq=gamma=1.05" in scale + and os.environ.get("FFMPEG_DISABLE_GAMMA_EQUALIZER") is not None + ): + scale.replace( + ",hwdownload,eq=gamma=1.05", + ":format=nv12,hwdownload,format=nv12,format=yuv420p", + ) scale = scale.format(fps, width, height).split(" ") scale.extend(detect_args) From 51dc47ce7edee48bbf1a5c7d689b5bd901c81f5e Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 12:47:44 -0600 Subject: [PATCH 09/11] Fix tests --- frigate/test/test_ffmpeg_presets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py index ac5e30a2d7..9e75e71331 100644 --- a/frigate/test/test_ffmpeg_presets.py +++ b/frigate/test/test_ffmpeg_presets.py @@ -78,7 +78,7 @@ def test_ffmpeg_hwaccel_scale_preset(self): " ".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" + "fps=10,scale_cuda=w=2560:h=1920,hwdownload,eq=gamma=1.05" in (" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])) ) From 7eec569cbcbf2ba08517315b89cb8af9df6e816f Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 12:52:22 -0600 Subject: [PATCH 10/11] Formatting --- frigate/test/test_ffmpeg_presets.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py index 9e75e71331..9879ae4ea0 100644 --- a/frigate/test/test_ffmpeg_presets.py +++ b/frigate/test/test_ffmpeg_presets.py @@ -77,9 +77,8 @@ def test_ffmpeg_hwaccel_scale_preset(self): assert "preset-nvidia-h264" not in ( " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) ) - assert ( - "fps=10,scale_cuda=w=2560:h=1920,hwdownload,eq=gamma=1.05" - in (" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])) + assert "fps=10,scale_cuda=w=2560:h=1920,hwdownload,eq=gamma=1.05" in ( + " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) ) def test_default_ffmpeg_input_arg_preset(self): From b15d3c857aeec7e80610e30de5dd5c2ac3177acb Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 19 Sep 2024 13:17:30 -0600 Subject: [PATCH 11/11] Fix nvidia --- frigate/ffmpeg_presets.py | 8 ++++---- frigate/test/test_ffmpeg_presets.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frigate/ffmpeg_presets.py b/frigate/ffmpeg_presets.py index d34c22e67e..574dc01773 100644 --- a/frigate/ffmpeg_presets.py +++ b/frigate/ffmpeg_presets.py @@ -91,10 +91,10 @@ def get_selected_gpu(self) -> str: PRESETS_HW_ACCEL_SCALE = { "preset-rpi-64-h264": "-r {0} -vf fps={0},scale={1}:{2}", "preset-rpi-64-h265": "-r {0} -vf fps={0},scale={1}:{2}", - FFMPEG_HWACCEL_VAAPI: "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2},hwdownload,eq=gamma=1.05", + FFMPEG_HWACCEL_VAAPI: "-r {0} -vf fps={0},scale_vaapi=w={1}:h={2},hwdownload,format=nv12,eq=gamma=1.05", "preset-intel-qsv-h264": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", "preset-intel-qsv-h265": "-r {0} -vf vpp_qsv=framerate={0}:w={1}:h={2}:format=nv12,hwdownload,format=nv12,format=yuv420p", - FFMPEG_HWACCEL_NVIDIA: "-r {0} -vf fps={0},scale_cuda=w={1}:h={2},hwdownload,eq=gamma=1.05", + FFMPEG_HWACCEL_NVIDIA: "-r {0} -vf fps={0},scale_cuda=w={1}:h={2},hwdownload,format=nv12,eq=gamma=1.05", "preset-jetson-h264": "-r {0}", # scaled in decoder "preset-jetson-h265": "-r {0}", # scaled in decoder "preset-rk-h264": "-r {0} -vf scale_rkrga=w={1}:h={2}:format=yuv420p:force_original_aspect_ratio=0,hwmap=mode=read,format=yuv420p", @@ -186,11 +186,11 @@ def parse_preset_hardware_acceleration_scale( scale = PRESETS_HW_ACCEL_SCALE.get(arg, PRESETS_HW_ACCEL_SCALE["default"]) if ( - ",hwdownload,eq=gamma=1.05" in scale + ",hwdownload,format=nv12,eq=gamma=1.05" in scale and os.environ.get("FFMPEG_DISABLE_GAMMA_EQUALIZER") is not None ): scale.replace( - ",hwdownload,eq=gamma=1.05", + ",hwdownload,format=nv12,eq=gamma=1.05", ":format=nv12,hwdownload,format=nv12,format=yuv420p", ) diff --git a/frigate/test/test_ffmpeg_presets.py b/frigate/test/test_ffmpeg_presets.py index 9879ae4ea0..0275469cdf 100644 --- a/frigate/test/test_ffmpeg_presets.py +++ b/frigate/test/test_ffmpeg_presets.py @@ -77,8 +77,9 @@ def test_ffmpeg_hwaccel_scale_preset(self): assert "preset-nvidia-h264" not in ( " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) ) - assert "fps=10,scale_cuda=w=2560:h=1920,hwdownload,eq=gamma=1.05" in ( - " ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"]) + assert ( + "fps=10,scale_cuda=w=2560:h=1920,hwdownload,format=nv12,eq=gamma=1.05" + in (" ".join(frigate_config.cameras["back"].ffmpeg_cmds[0]["cmd"])) ) def test_default_ffmpeg_input_arg_preset(self):