Translation(s): none


Video compression (codecs) require a fair bit of computing power even with modern multi-core CPUs. However, with modern graphics cards, it is often possible to offload the workload to the dedicated video encoder/decoders on the GPU.

GPUs are often much more (time) efficient at encoding and decoding video than the CPU, so by using hardware video acceleration, more resources can be made available to the rest of the system. For mobile use, this often also helps with power efficiency and battery life.

For long term video storage, CPU (software) encoding is still more space efficient at present.

Hardware video acceleration in Linux is currently supported by different APIs, with different levels of hardware (vendor) and software (programme) support.

APIs and Hardware / Software Support

The three main APIs used in hardware video acceleration are: VA-API, VDPAU, and NVENC/NVDEC.


Installation

VA-API

VA-API user space support is included as part of the Mesa package.

For Intel and AMD graphics cards, VA-API decoding works out-of-the-box.

Intel

For Intel, codec support depends on the GPU generation. The easiest way to find out which codecs your GPU supports is by searching Wikipedia (Intel ?QuickSync is basically VA-API with some extra vendor-specific optimisations) or through this table on this ?GitHub page.

The free drivers are sufficient for video decoding, however the non-free drivers are necessary for encoding.

For Gen 8+ Intel hardware, the free driver can be installed with the intel-media-va-driver package. The non-free driver is in the intel-media-va-driver-non-free package after adding a non-free component to your apt sources.

For older hardware (up to Gen 9 GPUs), the free driver is installed with the i965-va-driver package. The non-free driver can be installed with the i965-va-driver-shaders package after adding a non-free component to your apt sources.

If both drivers are installed, the newer driver from intel-media-va-driver is preferred over i965-va-driver (since Debian 11/Bullseye).

Driver selection can be overridden by setting the environment variable LIBVA_DRIVER_NAME to a specific driver, e.g., LIBVA_DRIVER_NAME=i965 (to use the driver from i965-va-driver on Bullseye) or LIBVA_DRIVER_NAME=iHD (to use the driver from intel-media-va-driver on Debian 10/Buster). See EnvironmentVariables for more details on how to set this environment variable system-wide or per user.

In some cases, it is required to enable the GuC/HuC firmware specifically to make hardware video acceleration functional (for both decoding/encoding). The firmware files reside in firmware-misc-nonfree and loading is controlled by i915.enable_guc kernel option, which could be specified in kernel command line or an modprobe.d entry looks like:

options i915 enable_guc=2

This kernel module option would taint the kernel even if the firmware is not actually loaded. Supported value depends on hardware, and could be one of:

For Gen 11+ GPUs, the Xe driver is still experimental, but has been available in the Linux kernel since version 6.8 (bookworm-backports or trixie).

AMD

For AMD, codec support generally lagged (a few years) behind Intel. The list of codecs supported by your GPU model is listed on Wikipedia.

Support can be added by installing the mesa-va-drivers package.

Nvidia

For the open source Nouveau drivers, VA-API is supported with the mesa-va-drivers package.

For the proprietary Nvidia drivers, VA-API support can be added by installing the nvidia-vaapi-driver package. This is intended mostly for web browser support and may not correctly work in other apps. Currently, only decoding is supported.

Generally for Nvidia GPUs using the proprietary driver, NVENC is used for hardware video encoding (see below).

VDPAU

VDPAU is older and faces considerably more limitations compared to VA-API. It is not supported by any major browsers, except for GNOME Web (epiphany).

However, for some users (mostly using older Nvidia proprietary drivers), it may be the only option for local media playback. MPV is recommended for this.

Intel

It is heavily recommended to use VA-API with Intel.

VDPAU support is poor on Intel hardware. Although you could enable VDPAU through OpenGL/VA-API backend with the vdpau-driver-all package, there are severe stability issues and may not work at all on some Intel GPUs.

AMD

To enable VDPAU support for the free (amdgpu) and proprietary ((radeon) AMD drivers, install the vdpau-driver-all package.

Nvidia

To enable VDPAU support on the open source Nouveau drivers, install the vdpau-driver-all package.

For the proprietary NVIDIA drivers, you must choose the correct package for your nvidia driver version.

If you have installed the latest drivers via the nvidia-driver package, then you can simply install the nvidia-vdpau-driver package.

However, if you're using a legacy nvidia driver, you must choose the appropriate package from: nvidia-legacy-304xx-vdpau-driver, nvidia-legacy-340xx-vdpau-driver, nvidia-legacy-390xx-vdpau-driver etc.

NVENC/NVDEC

NVDEC is supported by the libnvcuvid1 package.

For the legacy nvidia drivers, you must choose the libnvidia-legacy-304xx-nvcuvid1, libnvidia-legacy-340xx-nvcuvid1, or libnvidia-legacy-390xx-nvcuvid1 package.

NVENC is supported by the libnvidia-encode1 package.

For the legacy drivers, choose either the libnvidia-legacy-340xx-encode1 or libnvidia-legacy-390xx-encode1 package.

These are non-free runtime libraries in the non-free repo.

Applications in Debian's main archive including FFmpeg (starting with libavcodec58 7:4.4.1-2) and users of FFmpeg's libraries will load the libraries from the non-free driver if they are available.


Checking hardware support

You can find a full report of which codecs are supported by VA-API or VDPAU by your hardware by installing the vainfo and vdpauinfo packages and running their commands vainfo and vdpauinfo.

Vainfo

vainfo will display which video codecs are supported by your GPU for for decoding and encoding.

VAEntrypointVLD = decode
VAEntrypointEnc* = encode

OR

Wikipedia has an easy to read chart for Intel GPUs: https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video#Hardware_decoding_and_encoding

For AMD GPUs, there is also an wikipedia entry, but it is less easy to read: https://en.wikipedia.org/wiki/Graphics_Core_Next#Comparison_of_GCN_GPUs

Nvidia codec support

For Nvidia, check this wikipedia page for codec support.


GPU monitoring tools

Intel GPU top

Intel GPU hardware acceleration can be confirmed via intel_gpu_top found in intel-gpu-tools.

Anything greater than 0% in the "ENGINE Video" section confirms it is working in whatever application and codec you are testing e.g:

# intel_gpu_top
intel-gpu-top -  173/ 174 MHz;   71% RC6;  0.16 Watts;      403 irqs/s

      IMC reads:     1020 MiB/s
     IMC writes:      226 MiB/s

          ENGINE      BUSY                             MI_SEMA MI_WAIT
     Render/3D/0    5.12% |█▎                        |      0%      0%
       Blitter/0    0.00% |                          |      0%      0%
         Video/0    6.47% |█▋                        |      0%      0%
  VideoEnhance/0    0.00% |                          |      0%      0%

Note: If using intel_gpu_top, test each application individually.

Radeon top

For AMD GPUs, a similar monitoring tool is radeon-top.

NVtop

For Nvidia, use nvtop.


Application Support

Application support for hardware acceleration varies, and each application requires individual configuration. Following are details for various applications.

mpv

mpv has good hardware acceleration support, although it is not enabled by default. To enable it, use the --hwdec command line switch. It can also be made the default by adding a line like “hwdec” to the mpv configuration file (e.g., $HOME/.config/mpv/mpv.conf). [hwdec can also take various values, although ideally supplying the switch with no value should be sufficient. See the mpv manpage for more details (which recommends not to set the switch).]

If hardware acceleration is being used, mpv’s output will contain lines like the following:

libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
AO: [alsa] 48000Hz stereo 2ch float
Using hardware decoding (vaapi).
VO: [opengl] 1920x816 vaapi

VLC

Hardware acceleration in VLC is controlled in the GUI via “Tools → Preferences → Input / Codecs → Hardware-accelerated decoding”, or via the CLI option –avcodec-hw value [‘value’ is mandatory].

If hardware acceleration is being used, VLC’s output will contain lines like the following:

libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
[00007f082ce97280] avcodec decoder: Using Intel i965 driver for Intel(R) Broadwell - 1.7.3 for hardware decoding

Please beaware that VLC 3.0.x in bookworm has limited VA-API support. Hardware accelerating using VDPAU is expected to work.

Browser support

Web video is one of the most important use-cases for hardware video acceleration, as without it, sites like YouTube will cause heavy CPU usage (and therefore power consumption), a particular concern on mobile devices such as laptops and tablets.

As of Debian 11/Bullseye:

VDPAU isn't supported at all in Chromium or Firefox. The only browser that supports it is GNOME Web, available in the epiphany-browser package. GNOME Web leverages GStreamer for this support, also requiring the gstreamer1.0-plugins-bad package for VDPAU support to work properly.


CategoryPermalink