How To Enable Hardware Acceleration In Chromium On Ubuntu Or Linux Mint (VA-API Patched PPA Builds)

You may have noticed that watching HD videos from Youtube and other similar websites in Google Chrome or Chromium browsers on Linux considerably increases your CPU usage and, if you use a laptop, it gets quite hot and the battery drains very quickly. That's because Chrome / Chromium (Firefox too but there's no way to force this) doesn't support hardware accelerated video decoding on Linux.

This article explains how to install a Chromium beta or development build which includes a patch that enables VA-API on Linux, bringing support for GPU accelerated video decoding, which should significantly decrease the CPU usage when watching HD videos online. The instructions cover only Intel and Nvidia graphics cards, as I don't have an ATI/AMD graphics card to try this, nor do I have experience with such graphics cards, but from what I've read, this should work with ATI/AMD graphics too.

This is Chromium from the Ubuntu (18.04) repositories without GPU accelerated video decoding playing a 1080p YouTube video:

Chromium browser no hardware acceleration

The same 1080p YouTube video playing in Chromium with the VA-API patch and hardware accelerated video decode enabled on Ubuntu 18.04:


Notice the CPU usage in the screenshots. Both screenshots were taken on my old, but still quite powerful desktop. On my laptop, the Chromium CPU usage without hardware acceleration goes way higher.

The patch to add VA-API support to Chromium on Linux, titled "Enable VAVDA, VAVEA and VAJDA on linux with VAAPI only" was was initially submitted to Chromium more than a year ago, but it has yet to be merged.

Chrome has an option to override the software rendering list (#ignore-gpu-blacklist), but this option does not enable hardware accelerated video decoding. After enabling this option, you may find the following when visiting chrome://gpu: "Video Decode: Hardware accelerated", but this does not mean it actually works. Open a HD video on YouTube and check the CPU usage in a tool such as htop (this is what I'm using in the screenshots above to check the CPU usage) - you should see high CPU usage because GPU video decoding is not actually enabled. There's also a section below for how to check if you're actually using hardware accelerated video decoding. [[Edit]] This is no longer true. Google Chrome and other Chromium-based web browsers now have VA-API support by default. However, it's not enabled by default. See this for more information: How To Enable Hardware Accelerated Video Decode In Google Chrome, Brave, Vivaldi And Opera Browsers On Debian, Ubuntu Or Linux Mint

The patches used by the Chromium Ubuntu builds with VA-API enabled used in this article are available here.

As an added benefit, by using Chromium with VA-API installed from PPA you get to have native Chromium builds (actual DEB packages) on Ubuntu, instead of the new default Snap Chromium builds, which Ubuntu has started pushing by default.

Installing and using Chromium browser with VA-API support on Ubuntu or Linux Mint


It should be clear to everyone reading this that Chromium Beta or Dev Branch is not considered stable. So you might find bugs, it may crash, etc. It works fine right now but who knows what may happen after some update. Using the PPAs below will overwrite your current stable Chromium installation (if already installed).

What's more, the Chromium Beta and Dev Branch PPA repositories used in this article requires performing some extra steps if you want to enable Widevine support (so you can play Netflix videos and paid YouTube videos, etc.), or if you need features like Sync (which needs registering an API key and setting it up on your system). Instructions for performing these tweaks are explained in the Chromium Dev Branch PPA description.

For Nvidia graphics, the vdpau video driver needs to be updated in order to implement vaQuerySurfaceAttributes. So a patched vdpau-va-driver is required to use this with Nvidia. Thankfully, the Chromium-dev PPA provides this patched package and I'll link it so you can manually download it in case you want to use the Beta PPA.

Chromium with the VA-API patch is also available for some other Linux distributions, in third-party repositories, like Arch Linux (for Nvidia you'll need this patched libva-vdpau-driver) for example. If you don't use Ubuntu or Linux Mint, you'll have to find these packages yourself.

1. Add the Chromium with VA-API support PPA.

Chromium with VA-API support is available in two PPA repositories - one which has Chromium Beta and another one with Chromium Dev. Choose one from the 2 (and only add one)! The Beta PPA should be more stable.

To add the Chromium Beta branch PPA and install Chromium browser in Ubuntu, Linux Mint, and Ubuntu or Linux Mint flavors like Xubuntu, Kubuntu, Ubuntu MATE, Lubuntu, Linux Mint MATE, et.c, using:

sudo add-apt-repository ppa:saiarcot895/chromium-beta

You can add the Chromium Dev branch PPA and install the latest Chromium browser development build in either Ubuntu or Linux Mint (and other Ubuntu-based Linux distributions, including elementary, as well as Ubuntu or Linux Mint flavors like Xubuntu, Kubuntu, Ubuntu MATE, Linux Mint MATE and so on) using:

sudo add-apt-repository ppa:saiarcot895/chromium-dev

2. Pin the PPA with a priority of 1001.

The Chromium version from the PPA may be overwritten by an Ubuntu update. To avoid this, we can pin the Chromium VAAPI PPA packages to have a priority of 1001 (with 500 being default on Ubuntu, and > 1000 meaning to install the packages even if it's a downgrade), so the packages from the PPA are not overwritten by any Ubuntu updates, and they can be installed even if the version on the system is newer. We'll do this as follows.

  • for the Beta PPA:
Run this in a terminal:

sudo nano /etc/apt/preferences.d/saiarcot895-chromium-beta-pin-1001

And paste the following:

Package: *
Pin: release o=LP-PPA-saiarcot895-chromium-beta
Pin-Priority: 1001

Now save the file and exit (in Nano, save using Ctrl + o, then exit with Ctrl + x).


  • for the Dev PPA:
Run this in a terminal:

sudo nano /etc/apt/preferences.d/saiarcot895-chromium-dev-pin-1001

And paste the following:

Package: *
Pin: release o=LP-PPA-saiarcot895-chromium-dev
Pin-Priority: 1001

Now save the file and exit (in Nano, save using Ctrl + o, then exit with Ctrl + x).

3. Install Chromium Browser from the Saiarcot895 (VA-API) PPA:

sudo apt update

sudo apt install chromium-browser

4. Install the VA-API driver

For Intel graphics cards Gen 7 and older, you'll need to install the i965-va-driver-shaders package (it may already be installed):

sudo apt install i965-va-driver-shaders

For Intel graphics Gen 8 and newer:

sudo apt install intel-media-va-driver-non-free

For Nouveau and AMD drivers (I don't have AMD graphics, so I can't try this; as for Nouveau, it didn't work for me so I had to use the proprietary Nvidia drivers, but maybe it works for you):

sudo apt install mesa-va-drivers

For Nvidia graphics cards using the proprietary drivers you need the patched vdpau-va-driver from the Chromium Dev PPA. If you've added the Chromium Dev PPA, you can install it using this command (for Ubuntu versions up to 20.04):

sudo apt install vdpau-va-driver

For those using Ubuntu 20.10 or 21.04 (for which this package was not uploaded to the PPA), you can download the patched vdpau-va-driver DEB package from here (you'll also need this libvdpau1), and install it manually. It works not only on Ubuntu 20.04, but also on 20.10 and 21.04.

5. Enable the Hardware-accelerated video option in Chromium.

Copy and paste the following in the Chrome URL bar: chrome://flags/#enable-accelerated-video-decode (or search for the Hardware-accelerated video decode option in chrome://flags) and enable it. Then also enable Override software rendering list: chrome://flags/#ignore-gpu-blocklist. When you're done, restart Chromium browser.

On a default Google Chrome / Chromium build, this option shows as unavailable, but you'll be able to enable it now because we've used the VA-API enabled Chromium build.

6. Install h264ify Chrome extension. In case this extension doesn't work for you, install enchanced-h264ify instead.

YouTube (and probably some other websites as well) uses VP8 or VP9 video codecs by default, and many GPUs don't support hardware decoding for this codec. The h264ify extension will force YouTube to use H.264, which should be supported by most GPUs, instead of VP8/VP9.

This extension can also block 60fps videos, useful on lower end machines.

You can check the codec used by a YouTube video by right-clicking on the video and selecting Stats for nerds. With the h264ify extension enabled, you should see avc / mp4a as the codecs. Without this extension, the codec should be something like vp09 / opus.

7. Starting with Chromium 76, you need to launch Chromium browser with the --use-gl=desktop flag in order to disable ANGLE. Without this, hardware accelerated video decode won't work. 

So you'll need to launch Chromium Browser like this:

chromium-browser --use-gl=desktop

You can copy the Chromium desktop file from /usr/share/applications/ to ~/.local/share/applications/, and modify its Exec line to include this flag. This way when launching Chromium Browser it will automatically use this flag (and it won't be overwritten by updates):

cp /usr/share/applications/chromium-browser.desktop ~/.local/share/applications/

sed -i 's/Exec=chromium-browser %U/Exec=chromium-browser --use-gl=desktop %U/' ~/.local/share/applications/chromium-browser.desktop


How to check if Chromium is using GPU video decoding


Open a video on YouTube. Then press Ctrl + Shift + i to open the Chrome DevTools. From the 3 vertical dots menu, click on More tools -> Media. Then click on the video title in the left-hand side panel of DevTools (Players section), and look in the Video Decoder section of the Media tab from Chrome DevTools:

Chromium hardware-accelerated video decode Linux

If it says the decoder name is VideoDecode Accelerator (previously it was MojoVideoDecoder, and before that it was GpuVideoDecoder, so if you get any of those and you're using an older browser version, that's ok, you have hardware acceleration), and Hardware decoder is true, then you're using hardware-accelerated video decoding. If it says FFmpegVideoDecoder, VpxVideoDecoder or Dav1dVideoDecoder (and in this case, the Hardware decoder should say false), your web browser is not using hardware-accelerated video decoding.

If it's not working, you could try to debug it by running chromium-browser from the command line and see if it shows any VA-API related errors. You can also run vainfo (install it in Ubuntu or Linux Mint: sudo apt install vainfo) and vdpauinfo (for Nvidia; install it in Ubuntu or Linux Mint: sudo apt install vdpauinfo) and see if it shows an error.

Important note: If you see a completely white video image after doing this (but you see MojoVideoDecoder), check chrome://flags and make sure that Vulkan is not enabled there. Having Vulkan enabled but launching the browser using the --use-gl=desktop option will cause this to happen.
 

How to remove Chromium with VA-API patches and use the official stable Ubuntu / Linux Mint Chromium builds


If you want to completely remove the Chromium with VA-API builds from your system, and revert to the official stable Chromium browser builds provided by Ubuntu / Linux Mint, you can purge the PPA.

To purge a PPA you'll need the PPA purge utility, which can be installed using:

sudo apt install ppa-purge

And then purge the Chromium PPA you have added:

  • Chromium Beta PPA:
sudo ppa-purge ppa:saiarcot895/chromium-beta

  • Chromium Dev PPA:
sudo ppa-purge ppa:saiarcot895/chromium-dev

Let's also remove the APT preferences file that we used to pin this PPA, because it's no longer doing anything:

sudo rm /etc/apt/preferences.d/saiarcot895-chromium-*-pin-1001