GPU Accelerated Video Decoding

Modern GPUs often offer hardware accelerated video decoding, which can potentially yield a dramatic reduction in CPU usage during video playback, depending on the codec used and other properties of the video. Both hardware as well as software support are required for this functionality, and the latter in particular (at least in the Linux world) has undergone much evolution in recent years. Online documentation is therefore sparse and incomplete, inconsistent, and often outdated. The following are some notes regarding the use of hardware accelerated video decoding on Debian Stretch.

Benefits

Whether hardware acceleration is a good idea in general is actually debatable. One of the MPV developers has claimed, as recently as July 2017, that “hwdec is usually a bad idea unless absolutely needed”, and ArchWiki still claims (as of July 20, 2018), that:

On the other hand, in at least some relatively typical scenarios, the performance gains of using hardware decoding can be huge, with reductions in CPU usage of around 90%.

Library and API Support

There are two main software frameworks for hardware acceleration currently in use on Linux: Video_Acceleration_API [VA-API] and VDPAU. The former should generally be used with Intel Graphics hardware, and the latter with Nvidia hardware. For more information, see the ArchWiki page on Hardware video acceleration.

VA-API

VA-API software support is provided by various Debian packages, including the various driver packages (e.g., va-driver-all, i965-va-driver, etc.) and the underlying library package (libva1). A useful utility is vainfo (provided by the vainfo package), which provides information about available VA-API capabilities, including the list of codecs for which hardware acceleration is available.

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 (see above). 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.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.]

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

Multithreading Conflict

An unfortunate limitation of VLC (actually of FFmpeg, on which VLC is based) is that hardware acceleration cannot be used if multithreading is enabled (Threading is controlled via [All preferences] “Input / Codecs → FFmpeg → Threads”: a value of 0 enables multithreading, and a value of 1 disables it). If multithreading is enabled, the request for hardware acceleration will be silently ignored, although the output of VLC invoked with the -v flag will include a line like:

[00007fdf8ce97280] avcodec decoder warning: thread type 1: disabling hardware acceleration