frigate/docs/docs/configuration/nvdec.md

111 lines
4.7 KiB
Markdown
Raw Normal View History

2021-01-21 03:26:49 +03:00
---
id: nvdec
title: nVidia hardware decoder
---
2020-11-07 20:57:10 +03:00
Certain nvidia cards include a hardware decoder, which can greatly improve the
2021-01-21 03:26:49 +03:00
performance of video decoding. In order to use NVDEC, a special build of
2020-11-07 20:57:10 +03:00
ffmpeg with NVDEC support is required. The special docker architecture 'amd64nvidia'
2021-01-21 03:26:49 +03:00
includes this support for amd64 platforms. An aarch64 for the Jetson, which
2020-11-07 20:57:10 +03:00
also includes NVDEC may be added in the future.
## Docker setup
### Requirements
2021-01-21 03:26:49 +03:00
2020-11-07 20:57:10 +03:00
[nVidia closed source driver](https://www.nvidia.com/en-us/drivers/unix/) required to access NVDEC.
[nvidia-docker](https://github.com/NVIDIA/nvidia-docker) required to pass NVDEC to docker.
### Setting up docker-compose
In order to pass NVDEC, the docker engine must be set to `nvidia` and the environment variables
`NVIDIA_VISIBLE_DEVICES=all` and `NVIDIA_DRIVER_CAPABILITIES=compute,utility,video` must be set.
In a docker compose file, these lines need to be set:
2021-01-21 03:26:49 +03:00
2020-11-07 20:57:10 +03:00
```
services:
frigate:
...
image: blakeblackshear/frigate:stable-amd64nvidia
runtime: nvidia
environment:
- NVIDIA_VISIBLE_DEVICES=all
2021-01-21 03:26:49 +03:00
- NVIDIA_DRIVER_CAPABILITIES=compute,utility,video
2020-11-07 20:57:10 +03:00
```
### Setting up the configuration file
2021-01-21 03:26:49 +03:00
In your frigate config.yml, you'll need to set ffmpeg to use the hardware decoder.
The decoder you choose will depend on the input video.
2020-11-07 20:57:10 +03:00
A list of supported codecs (you can use `ffmpeg -decoders | grep cuvid` in the container to get a list)
2021-01-21 03:26:49 +03:00
2020-11-07 20:57:10 +03:00
```
V..... h263_cuvid Nvidia CUVID H263 decoder (codec h263)
V..... h264_cuvid Nvidia CUVID H264 decoder (codec h264)
V..... hevc_cuvid Nvidia CUVID HEVC decoder (codec hevc)
V..... mjpeg_cuvid Nvidia CUVID MJPEG decoder (codec mjpeg)
V..... mpeg1_cuvid Nvidia CUVID MPEG1VIDEO decoder (codec mpeg1video)
V..... mpeg2_cuvid Nvidia CUVID MPEG2VIDEO decoder (codec mpeg2video)
V..... mpeg4_cuvid Nvidia CUVID MPEG4 decoder (codec mpeg4)
V..... vc1_cuvid Nvidia CUVID VC1 decoder (codec vc1)
V..... vp8_cuvid Nvidia CUVID VP8 decoder (codec vp8)
V..... vp9_cuvid Nvidia CUVID VP9 decoder (codec vp9)
2021-01-21 03:26:49 +03:00
```
2020-11-07 20:57:10 +03:00
For example, for H265 video (hevc), you'll select `hevc_cuvid`. Add
`-c:v hevc_covid` to your ffmpeg input arguments:
```
ffmpeg:
input_args:
...
2021-01-21 03:26:49 +03:00
- -c:v
2020-11-07 20:57:10 +03:00
- hevc_cuvid
```
If everything is working correctly, you should see a significant improvement in performance.
Verify that hardware decoding is working by running `nvidia-smi`, which should show the ffmpeg
processes:
```
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.38 Driver Version: 455.38 CUDA Version: 11.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce GTX 166... Off | 00000000:03:00.0 Off | N/A |
| 38% 41C P2 36W / 125W | 2082MiB / 5942MiB | 5% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
2021-01-21 03:26:49 +03:00
2020-11-07 20:57:10 +03:00
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 12737 C ffmpeg 249MiB |
| 0 N/A N/A 12751 C ffmpeg 249MiB |
| 0 N/A N/A 12772 C ffmpeg 249MiB |
| 0 N/A N/A 12775 C ffmpeg 249MiB |
| 0 N/A N/A 12800 C ffmpeg 249MiB |
| 0 N/A N/A 12811 C ffmpeg 417MiB |
| 0 N/A N/A 12827 C ffmpeg 417MiB |
+-----------------------------------------------------------------------------+
```
To further improve performance, you can set ffmpeg to skip frames in the output,
using the fps filter:
```
output_args:
2021-01-21 03:26:49 +03:00
- -filter:v
2020-11-07 20:57:10 +03:00
- fps=fps=5
```
This setting, for example, allows Frigate to consume my 10-15fps camera streams on
my relatively low powered Haswell machine with relatively low cpu usage.