如何在 Ubuntu 或 Linux Mint 启用 Chromium 硬件加速的视频解码
Chrome 视频 硬件加速
![](/data/attachment/album/201809/13/002801b8ea5855wfo7v7kw.jpg)


你或许已经注意到了，在 Linux 上使用 Google Chrome 或 Chromium 浏览器在 YouTube 或其它类似网站观看高清视频会增加你的 CPU 使用率，如果你用的是笔记本，电脑会发热而且电池会很快用完。这是因为 Chrome/Chromium（Firefox 也是如此，但是 Firefox 的问题没有办法解决）在 Linux 上不支持硬件加速的视频解码。


这篇文章讲述了如何在 Linux 环境安装带有 VA-API 补丁的 Chromium 开发版，它支持 GPU 加速的视频解码，可以显著减少观看在线高清视频时的 CPU 使用率，这篇教程只适用于 Intel 和 Nvidia 的显卡，我没有 ATI/AMD 的显卡可以试验，也没有使用过这几种显卡。


这是 Chromium 浏览器在 Ubuntu18.04 中，在没有 GPU 加速视频解码的情况下播放一个 1080p 的 YouTube 视频：


![](/data/attachment/album/201809/13/002931b4jucqzy2immcmry.png)


这是带有 VA-API 补丁的 Chromium 浏览器在 Ubuntu18.04 中，在带有 GPU 加速视频解码的情况下播放同样的 1080p 的 YouTube 视频：


![](/data/attachment/album/201809/13/002954l1a2awffpf2g0181.png)


注意截图中的 CPU 使用率。两张截图都是在我老旧而依然强大的桌面计算机上捕捉的。在我的笔记本电脑上，没有硬件加速的 Chromium 带来更高的 CPU 使用率。


“只需 VA-API 即可在 Linux 启用 VAVDA、VAVEA 和 VAJDA” 这个[补丁](https://chromium-review.googlesource.com/c/chromium/src/+/532294)在一年多以前就提交给了 Chromium，但是它还没有合并。


Chrome 有一个选项可以覆盖软件渲染列表（`#ignore-gpu-blacklist`），但是这个选项不能启用硬件加速的视频解码。启用这个选项以后，你或许会在访问 `chrome://gpu` 时发现这些信息：“*Video Decode: Hardware accelerated* “，然而这个并不意味着真的可以工作。在 YouTube 打开一个高清视频并用诸如 `htop` 的工具查看 CPU 使用率（这是我在以上截图中用来查看 CPU 使用率的）。因为 GPU 视频解码没有真的被启用，你应该看到较高的 CPU 使用率。下面有一个部分是关于检查你是否真的在使用硬件加速的视频解码的。


**文中使用的 Chromium 浏览器 Ubuntu 版启用 VA-API 的补丁在[这个地址](https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches)可以获得**


### 在 Ubuntu 和 Linux Mint 安装和使用带有 VA-API 支持的 Chromium 浏览器


每个人都该知道 Chromium 开发版本没有理想中那么稳定。所以你可能发现 bug，它可能会发生崩溃等情况。它现在可能正常运行，但是谁知道几次更新以后会发生什么。


还有，如果你想启用 Widevine 支持（这样你才能观看 Netflix 视频和 YouTube 付费视频），Chromium dev 分支 PPA 要求你执行一些额外步骤。 如果你想要一些功能，比如同步，也是如此（需要注册 API 密钥还要在你的系统上设置好）。执行这些任务的说明在 [Chromium 开发版本的 PPA](https://launchpad.net/%7Esaiarcot895/+archive/ubuntu/chromium-dev) 中有详细解释。


对于 Nvidia 显卡，vdpau 视频驱动程序需要更新以便显示 vaQuerySurfaceAttributes。所以 Nvidia 需要使用打过补丁的 vdpau-va-driver。值得庆幸的是，Chromium-dev PPA 提供了这个打过补丁的包。


带有 VA-API 补丁的 Chromium 也可用于其它 Linux 发行版，在第三方仓库，比如说 [Arch Linux](https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go)（对于 Nvidia 你需要[这个](https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/)补丁过的 libva-vdpau-driver）。如果你不使用 Ubuntu 或 Linux Mint，你得自己找那些包。


#### 1、安装带有 VA-API 补丁的 Chromium


有一个带 VA-API 补丁的 Chromium Beta PPA，但是它缺少适用于 Ubuntu 18.04 的 vdpau-video。如果你需要，你可以使用这个 [Beta PPA](https://launchpad.net/%7Esaiarcot895/+archive/ubuntu/chromium-beta)，而不是我在下面的步骤中使用 [Dev PPA](https://launchpad.net/%7Esaiarcot895/+archive/ubuntu/chromium-dev/+packages)，不过如果你使用 Nvidia 显卡，你需要从这个 Dev PPA 中下载安装 vdpau-va-driver，并确认 Ubuntu/Linux Mint 不更新这个包（有点复杂，如果你准备根据下面步骤使用 Dev PPA 的话，不需要手动做这些）。


你可以添加 [Chromium 开发分支 PPA](https://launchpad.net/%7Esaiarcot895/+archive/ubuntu/chromium-dev)，并在 Ubuntu 或 Linux Mint（及其它基于 Ubuntu 的发行版，如 elementary，以及 Ubuntu 或 Linux Mint 的风味版，如 Xubuntu、Kubuntu、Ubuntu MATE、Linux Mint MATE 等等）上安装最新的 Chromium 浏览器开发版：



```
sudo add-apt-repository ppa:saiarcot895/chromium-dev
sudo apt-get update
sudo apt install chromium-browser

```

#### 2、安装 VA-API 驱动


对于 Intel 的显卡，你需要安装 `i965-va-driver` 这个包（它可能早就安装好了）



```
sudo apt install i965-va-driver
```

对于 Nvidia 的显卡（在开源的 Nouveau 驱动和闭源的 Nvidia 驱动上，它应该都有效）， 安装 `vdpau-va-driver`：



```
sudo apt install vdpau-va-driver
```

#### 3、在 Chromium 启用硬件加速视频选项


复制这串地址，粘贴进 Chromium 的 URL 栏: `chrome://flags/#enable-accelerated-video` （或者在 `chrome://flags` 搜索 `Hardware-accelerated video` ）并启用它，然后重启 Chromium 浏览器。


在默认的 Google Chrome / Chromium 版本，这个选项不可用，但是你可以在启用了 VP-API 的 Chromium 版本启用它。


#### 4、安装 [h264ify](https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal) Chrome 扩展


YouTube（可能还有其它一些网址也是如此）默认使用 VP8 或 VP9 编码解码器，许多 GPU 不支持这种编码解码器的硬件解码。h264ify 会强制 YouTube 使用大多数 GPU 都支持的 H.264 而不是 VP8/VP9。


这个扩展还能阻塞 60fps 的视频，对低性能机器有用。


你可以在视频上右键点击，并且选择 `Stats for nerds` 以查看 Youtube 视频所使用额编码解码器，如果启用了 h264ify 扩展，你可以看到编码解码器是 avc / mp4a。如果没有启用，编码解码器应该是 vp09 / opus。


### 如何检查 Chromium 是否在使用 GPU 视频解码


在 YouTube 打开一个视频，然后，在 Chromium 打开一个新的标签页并将以下地址输入 URL 栏：`chrome://media-internals`。


在 `chrome://media-internals` 标签页中，点击视频的 URL（为了展开它）， 往下滚动查看 `Player Properties` 的下面，你应该可以找到 `video_decoder` 属性。如果`video_decoder` 的值是 `GpuVideoDecoder` ，这说明当前在另一个标签页播放的 YouTube 视频正在使用硬件加速的的视频解码。


![](/data/attachment/album/201809/13/003015wmkss5dmgiiims3m.png)


如果它显示的是 `FFmpegVideoDecoder` 或 `VpxVideoDecoder` ，说明加速视频解码无效或者你忘记安装或禁用了 h264ify 这个 Chrome 扩展。


如果无效，你可以通过在命令行运行 `chromium-browser` ，通过查看是否有 VA-API 相关的错误显示出来以调试。你也可以运行 `vainfo`（在 Ubuntu 或 Linux Mint 上安装：`sudo apt install vainfo`）和 `vdpauinfo` （对于 Nvidia，在 Ubuntu 或 Linux Mint 上安装：`sudo apt install vdpauinfo`）并且查看是否有显示任何错误。




---


via: <https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html>


作者：[Logix](https://plus.google.com/118280394805678839070) 选题：[lujun9972](https://github.com/lujun9972) 译者：[GraveAccent](https://github.com/GraveAccent) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# 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 is Chromium from the Ubuntu (18.04) repositories without GPU accelerated video decoding playing a 1080p YouTube video:



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


~~Chrome has an option to override the software rendering list (~~ There's also a section below for how to check if you're actually using hardware accelerated video decoding.









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




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



You can add the





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.





And paste the following:



Now save the file and exit (in Nano, save using






And paste the following:



Now save the file and exit (in Nano, save using







For Intel graphics cards Gen 7 and older, you'll need to install the



For Intel graphics Gen 8 and newer:





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.




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









Open a video on YouTube. Then press




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:



And then purge the Chromium PPA you have added:




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



**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:

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](https://chromium-review.googlesource.com/c/chromium/src/+/532294)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.`#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.**[[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](https://www.linuxuprising.com/2021/01/how-to-enable-hardware-accelerated.html)**The patches used by the Chromium Ubuntu builds with VA-API enabled used in this article are available**

[here](https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches).


**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](https://www.linuxuprising.com/2019/06/ubuntu-devs-testing-chromium-browser.html), 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](https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev)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](https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go)(for Nvidia you'll need

[this](https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/)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**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:

[Beta branch PPA](https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta)`sudo add-apt-repository ppa:saiarcot895/chromium-beta`


You can add the

**Chromium**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:

[Dev branch PPA](https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev)`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:**

`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:**

`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`


**, you can download the patched**__For those using Ubuntu 20.10 or newer (for which this package was not uploaded to the PPA)__`vdpau-va-driver`

DEB package [from here](http://ppa.launchpad.net/saiarcot895/chromium-dev/ubuntu/pool/main/v/vdpau-video/)(you'll also need this[libvdpau1](https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+files/libvdpau1_1.4-2~ubuntu20.04.1_amd64.deb)), and install it manually. It works not only on Ubuntu 20.04, but also on newer versions.**5. Enable the Hardware-accelerated video option in Chromium.**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](https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal)Chrome extension. In case this extension doesn't work for you, install[enchanced-h264ify](https://chrome.google.com/webstore/detail/enhanced-h264ify/omkfmpieigblcllmkgbflkikinpkodlk)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.**[[Edit]] Nvidia users:**the patched vdpau-va-driver mentioned above no longer hardware accelerates VP9 in Chromium-based browser. So you must use the h264ify extension and avoid VP9 in order to get hardware-accelerated video decode.

**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. [[Edit]] With Chromium 91 and newer, you'll also need to add the `VDAVideoDecoder`

flag. [[Another edit]] For most, a new flag is also required: `--disable-features=UseChromeOSDirectVideoDecoder`

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

`chromium-browser --use-gl=desktop --enable-features=VaapiVideoDecode --disable-features=UseChromeOSDirectVideoDecoder`


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 --enable-features=VaapiVideoDecoder --disable-features=UseChromeOSDirectVideoDecoder %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:If it says the decoder name is


If it's not working, you could try to debug it by running

`VideoDecode Accelerator`

or `VDAVideoDecoder`

(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`