From 03b1d5eb3828c2636a00b3df469210f9e09ee6c2 Mon Sep 17 00:00:00 2001 From: Chandler Newby Date: Wed, 19 Apr 2023 12:54:13 -0600 Subject: [PATCH 1/4] Add docs for getting intel_gpu_top to work without privileged mode --- .../configuration/hardware_acceleration.md | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index c01bf74ebf..0af3d1a90d 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -15,7 +15,9 @@ ffmpeg: hwaccel_args: preset-rpi-64-h264 ``` -### Intel-based CPUs (<10th Generation) via VAAPI +### Intel-based CPUs + +#### Intel-based CPUs (<10th Generation) via VAAPI 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 if QSV does not work. @@ -26,24 +28,50 @@ ffmpeg: **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). -### Intel-based CPUs (>=10th Generation) via Quicksync +#### Intel-based CPUs (>=10th Generation) via Quicksync QSV must be set specifically based on the video encoding of the stream. -#### H.264 streams +##### H.264 streams ```yaml ffmpeg: hwaccel_args: preset-intel-qsv-h264 ``` -#### H.265 streams +##### H.265 streams ```yaml ffmpeg: hwaccel_args: preset-intel-qsv-h265 ``` +#### Docker Configuration + +Additional configuration is needed for the Docker container to be able to access the `intel_gpu_top` command for GPU stats. Two possible changes need to be made: 1) Adding the `CAP_PERFMON` capability and 2) Setting the `perf_event_paranoid` low enough to allow access to the perfomance event system. + +##### CAP_PERFMON + +Only recent versions of Docker support the `CAP_PERFMON` capability. You can test to see if yours supports it by running: `docker run --cap-add=CAP_PERFMON hello-world` + +Pass `cap-add=CAP_PERFMON` to the container. With docker compose, that looks like this: + +```yaml +services: + frigate: + ... + cap_add: + - CAP_PERFMON +``` + +With docker run, add `--cap-add=CAP_PERFMON` to the `docker run` command. + +##### perf_event_paranoid + +_Note: This setting must be changed for the enitre system._ + +Depending on your OS and kernel configuration, you may need to change the `/proc/sys/kernel/perf_event_paranoid` kernel tunable. You can test the change by running `sudo sh -c 'echo 2 >/proc/sys/kernel/perf_event_paranoid'` which will persist until a reboot. Make it permanent by running `sudo sh -c 'echo kernel.perf_event_paranoid=1 >> /etc/sysctl.d/local.conf'` + ### AMD/ATI GPUs (Radeon HD 2000 and newer GPUs) via libva-mesa-driver VAAPI supports automatic profile selection so it will work automatically with both H.264 and H.265 streams. From 0c5659121d8badb384e644c1b232b7e05a607acd Mon Sep 17 00:00:00 2001 From: Chandler Date: Wed, 19 Apr 2023 13:44:34 -0600 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Nicolas Mowen --- docs/docs/configuration/hardware_acceleration.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 0af3d1a90d..7428e58637 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -17,7 +17,7 @@ ffmpeg: ### Intel-based CPUs -#### Intel-based CPUs (<10th Generation) via VAAPI +#### Via VAAPI 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 if QSV does not work. @@ -28,7 +28,7 @@ ffmpeg: **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). -#### Intel-based CPUs (>=10th Generation) via Quicksync +#### Via Quicksync (>=10th Generation only) QSV must be set specifically based on the video encoding of the stream. @@ -48,7 +48,10 @@ ffmpeg: #### Docker Configuration -Additional configuration is needed for the Docker container to be able to access the `intel_gpu_top` command for GPU stats. Two possible changes need to be made: 1) Adding the `CAP_PERFMON` capability and 2) Setting the `perf_event_paranoid` low enough to allow access to the perfomance event system. +Additional configuration is needed for the Docker container to be able to access the `intel_gpu_top` command for GPU stats. Three possible changes can be made: +1. Run the container as privileged. +2. Adding the `CAP_PERFMON` capability. +3. Setting the `perf_event_paranoid` low enough to allow access to the perfomance event system. ##### CAP_PERFMON From a50fd9f37ea04f0f1fbae7d2b467ff0c9e14c94f Mon Sep 17 00:00:00 2001 From: Chandler Newby Date: Wed, 19 Apr 2023 13:54:18 -0600 Subject: [PATCH 3/4] Address more review comments --- .../configuration/hardware_acceleration.md | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index 7428e58637..a681e26d3b 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -28,7 +28,7 @@ ffmpeg: **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). -#### Via Quicksync (>=10th Generation only) +#### Via Quicksync (>=10th Generation only) QSV must be set specifically based on the video encoding of the stream. @@ -46,32 +46,68 @@ ffmpeg: hwaccel_args: preset-intel-qsv-h265 ``` -#### Docker Configuration +#### Docker Configuration - intel_gpu_top Additional configuration is needed for the Docker container to be able to access the `intel_gpu_top` command for GPU stats. Three possible changes can be made: + 1. Run the container as privileged. 2. Adding the `CAP_PERFMON` capability. -3. Setting the `perf_event_paranoid` low enough to allow access to the perfomance event system. +3. Setting the `perf_event_paranoid` low enough to allow access to the performance event system. + +##### Run as privileged + +This method works, but it gives more permissions to the container than are actually needed. + +###### Docker Compose - Privileged + +```yaml +services: + frigate: + ... + image: ghcr.io/blakeblackshear/frigate:stable + privileged: true +``` + +###### Docker Run CLI - Privileged + +```bash +docker run -d \ + --name frigate \ + ... + --privileged \ + ghcr.io/blakeblackshear/frigate:stable +``` ##### CAP_PERFMON Only recent versions of Docker support the `CAP_PERFMON` capability. You can test to see if yours supports it by running: `docker run --cap-add=CAP_PERFMON hello-world` -Pass `cap-add=CAP_PERFMON` to the container. With docker compose, that looks like this: +###### Docker Compose - CAP_PERFMON ```yaml services: frigate: ... - cap_add: - - CAP_PERFMON + image: ghcr.io/blakeblackshear/frigate:stable + cap_add: + - CAP_PERFMON ``` -With docker run, add `--cap-add=CAP_PERFMON` to the `docker run` command. +###### Docker Run CLI - CAP_PERFMON + +```bash +docker run -d \ + --name frigate \ + ... + --cap-add=CAP_PERFMON \ + ghcr.io/blakeblackshear/frigate:stable +``` ##### perf_event_paranoid -_Note: This setting must be changed for the enitre system._ +_Note: This setting must be changed for the entire system._ + +For more information on the various values across different distributions, see https://askubuntu.com/questions/1400874/what-does-perf-paranoia-level-four-do. Depending on your OS and kernel configuration, you may need to change the `/proc/sys/kernel/perf_event_paranoid` kernel tunable. You can test the change by running `sudo sh -c 'echo 2 >/proc/sys/kernel/perf_event_paranoid'` which will persist until a reboot. Make it permanent by running `sudo sh -c 'echo kernel.perf_event_paranoid=1 >> /etc/sysctl.d/local.conf'` @@ -90,15 +126,15 @@ ffmpeg: While older GPUs may work, it is recommended to use modern, supported GPUs. NVIDIA provides a [matrix of supported GPUs and features](https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new). If your card is on the list and supports CUVID/NVDEC, it will most likely work with Frigate for decoding. However, you must also use [a driver version that will work with FFmpeg](https://github.com/FFmpeg/nv-codec-headers/blob/master/README). Older driver versions may be missing symbols and fail to work, and older cards are not supported by newer driver versions. The only way around this is to [provide your own FFmpeg](/configuration/advanced#custom-ffmpeg-build) that will work with your driver version, but this is unsupported and may not work well if at all. -A more complete list of cards and ther compatible drivers is available in the [driver release readme](https://download.nvidia.com/XFree86/Linux-x86_64/525.85.05/README/supportedchips.html). +A more complete list of cards and their compatible drivers is available in the [driver release readme](https://download.nvidia.com/XFree86/Linux-x86_64/525.85.05/README/supportedchips.html). If your distribution does not offer NVIDIA driver packages, you can [download them here](https://www.nvidia.com/en-us/drivers/unix/). -#### Docker Configuration +#### Docker Configuration - Nvidia GPU Additional configuration is needed for the Docker container to be able to access the NVIDIA GPU. The supported method for this is to install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker) and specify the GPU to Docker. How you do this depends on how Docker is being run: -##### Docker Compose +##### Docker Compose - Nvidia GPU ```yaml services: @@ -115,7 +151,7 @@ services: capabilities: [gpu] ``` -##### Docker Run CLI +##### Docker Run CLI - Nvidia GPU ```bash docker run -d \ From 5df089fd23a66c44e0d963f0570aa4efb979c933 Mon Sep 17 00:00:00 2001 From: Chandler Date: Wed, 19 Apr 2023 14:05:50 -0600 Subject: [PATCH 4/4] Rename sections Co-authored-by: Nicolas Mowen --- docs/docs/configuration/hardware_acceleration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/configuration/hardware_acceleration.md b/docs/docs/configuration/hardware_acceleration.md index a681e26d3b..0ada027a92 100644 --- a/docs/docs/configuration/hardware_acceleration.md +++ b/docs/docs/configuration/hardware_acceleration.md @@ -46,7 +46,7 @@ ffmpeg: hwaccel_args: preset-intel-qsv-h265 ``` -#### Docker Configuration - intel_gpu_top +#### Configuring Intel GPU Stats in Docker Additional configuration is needed for the Docker container to be able to access the `intel_gpu_top` command for GPU stats. Three possible changes can be made: @@ -130,7 +130,7 @@ A more complete list of cards and their compatible drivers is available in the [ If your distribution does not offer NVIDIA driver packages, you can [download them here](https://www.nvidia.com/en-us/drivers/unix/). -#### Docker Configuration - Nvidia GPU +#### Configuring Nvidia GPUs in Docker Additional configuration is needed for the Docker container to be able to access the NVIDIA GPU. The supported method for this is to install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker) and specify the GPU to Docker. How you do this depends on how Docker is being run: