<linkrel="alternate"type="application/rss+xml"href="/frigate/blog/rss.xml"title="Frigate Blog RSS Feed">
<linkrel="alternate"type="application/atom+xml"href="/frigate/blog/atom.xml"title="Frigate Blog Atom Feed"><titledata-react-helmet="true">nVidia hardware decoder | Frigate</title><metadata-react-helmet="true"name="twitter:card"content="summary_large_image"><metadata-react-helmet="true"name="docusaurus_locale"content="en"><metadata-react-helmet="true"name="docusaurus_version"content="current"><metadata-react-helmet="true"name="docusaurus_tag"content="docs-default-current"><metadata-react-helmet="true"property="og:title"content="nVidia hardware decoder | Frigate"><metadata-react-helmet="true"name="description"content="Certain nvidia cards include a hardware decoder, which can greatly improve the"><metadata-react-helmet="true"property="og:description"content="Certain nvidia cards include a hardware decoder, which can greatly improve the"><metadata-react-helmet="true"property="og:url"content="https://blakeblackshear.github.io/frigate/configuration/nvdec"><linkdata-react-helmet="true"rel="shortcut icon"href="/frigate/img/favicon.ico"><linkdata-react-helmet="true"rel="canonical"href="https://blakeblackshear.github.io/frigate/configuration/nvdec"><linkrel="stylesheet"href="/frigate/styles.3cef2c0e.css">
performance of video decoding. In order to use NVDEC, a special build of
ffmpeg with NVDEC support is required. The special docker architecture 'amd64nvidia'
includes this support for amd64 platforms. An aarch64 for the Jetson, which
also includes NVDEC may be added in the future.</p><h2><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_prK2"id="docker-setup"></a>Docker setup<aclass="hash-link"href="#docker-setup"title="Direct link to heading">#</a></h2><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_prK2"id="requirements"></a>Requirements<aclass="hash-link"href="#requirements"title="Direct link to heading">#</a></h3><p><ahref="https://www.nvidia.com/en-us/drivers/unix/"target="_blank"rel="noopener noreferrer">nVidia closed source driver</a> required to access NVDEC.
<ahref="https://github.com/NVIDIA/nvidia-docker"target="_blank"rel="noopener noreferrer">nvidia-docker</a> required to pass NVDEC to docker.</p><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_prK2"id="setting-up-docker-compose"></a>Setting up docker-compose<aclass="hash-link"href="#setting-up-docker-compose"title="Direct link to heading">#</a></h3><p>In order to pass NVDEC, the docker engine must be set to <code>nvidia</code> and the environment variables
<code>NVIDIA_VISIBLE_DEVICES=all</code> and <code>NVIDIA_DRIVER_CAPABILITIES=compute,utility,video</code> must be set.</p><p>In a docker compose file, these lines need to be set:</p><divclass="mdxCodeBlock_1zKU"><divclass="codeBlockContent_actS"><divtabindex="0"class="prism-code language-undefined codeBlock_tuNs thin-scrollbar"><divclass="codeBlockLines_3uvA"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">services:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> frigate:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> ...</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> image: blakeblackshear/frigate:stable-amd64nvidia</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> runtime: nvidia</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> environment:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - NVIDIA_VISIBLE_DEVICES=all</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - NVIDIA_DRIVER_CAPABILITIES=compute,utility,video</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_2GIj">Copy</button></div></div><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_prK2"id="setting-up-the-configuration-file"></a>Setting up the configuration file<aclass="hash-link"href="#setting-up-the-configuration-file"title="Direct link to heading">#</a></h3><p>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.</p><p>A list of supported codecs (you can use <code>ffmpeg -decoders | grep cuvid</code> in the container to get a list)</p><divclass="mdxCodeBlock_1zKU"><divclass="codeBlockContent_actS"><divtabindex="0"class="prism-code language-undefined codeBlock_tuNs thin-scrollbar"><divclass="codeBlockLines_3uvA"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... h263_cuvid Nvidia CUVID H263 decoder (codec h263)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... h264_cuvid Nvidia CUVID H264 decoder (codec h264)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... hevc_cuvid Nvidia CUVID HEVC decoder (codec hevc)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... mjpeg_cuvid Nvidia CUVID MJPEG decoder (codec mjpeg)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... mpeg1_cuvid Nvidia CUVID MPEG1VIDEO decoder (codec mpeg1video)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... mpeg2_cuvid Nvidia CUVID MPEG2VIDEO decoder (codec mpeg2video)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... mpeg4_cuvid Nvidia CUVID MPEG4 decoder (codec mpeg4)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... vc1_cuvid Nvidia CUVID VC1 decoder (codec vc1)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... vp8_cuvid Nvidia CUVID VP8 decoder (codec vp8)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> V..... vp9_cuvid Nvidia CUVID VP9 decoder (codec vp9)</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_2GIj">Copy</button></div></div><p>For example, for H265 video (hevc), you'll select <code>hevc_cuvid</code>. Add
<code>-c:v hevc_covid</code> to your ffmpeg input arguments:</p><divclass="mdxCodeBlock_1zKU"><divclass="codeBlockContent_actS"><divtabindex="0"class="prism-code language-undefined codeBlock_tuNs thin-scrollbar"><divclass="codeBlockLines_3uvA"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">ffmpeg:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> input_args:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> ...</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - -c:v</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - hevc_cuvid</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_2GIj">Copy</button></div></div><p>If everything is working correctly, you should see a significant improvement in performance.
Verify that hardware decoding is working by running <code>nvidia-smi</code>, which should show the ffmpeg
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">+-----------------------------------------------------------------------------+</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| Processes: |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| GPU GI CI PID Type Process name GPU Memory |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| ID ID Usage |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">|=============================================================================|</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12737 C ffmpeg 249MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12751 C ffmpeg 249MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12772 C ffmpeg 249MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12775 C ffmpeg 249MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12800 C ffmpeg 249MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12811 C ffmpeg 417MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">| 0 N/A N/A 12827 C ffmpeg 417MiB |</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">+-----------------------------------------------------------------------------+</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_2GIj">Copy</button></div></div><p>To further improve performance, you can set ffmpeg to skip frames in the output,
using the fps filter:</p><divclass="mdxCodeBlock_1zKU"><divclass="codeBlockContent_actS"><divtabindex="0"class="prism-code language-undefined codeBlock_tuNs thin-scrollbar"><divclass="codeBlockLines_3uvA"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> output_args:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - -filter:v</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> - fps=fps=5</span></div></div></div><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_2GIj">Copy</button></div></div><p>This setting, for example, allows Frigate to consume my 10-15fps camera streams on