Hardware video acceleration in Web browsers

From Linux Gaming
Revision as of 23:37, 23 April 2023 by Kkiot (talk | contribs) (→‎Firefox: Mark Firefox section as outdated.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Hardware accelerated video makes it possible for the video card to decode/encode video, thus offloading the CPU and saving power.

This article gives detail on enabling hardware video acceleration in browsers used in Linux. This article details them for Firefox and Chromium, but similar instructions apply to other browsers based on the above two.


This page needs work, for the following reason(s): Section outdated. NVIDIA users have been able to use hardware acceleration since a while: instructions are missing.

Firefox currently supports hardware acceleration on both x11 and Wayland. This is tested on Firefox 96 (nightly). The following settings need to be changed in about:config:

media.ffmpeg.vaapi.enabled  true
gfx.webrender.all           true
media.ffvpx.enabled         false

In addition, while running X11, Firefox should be launched with variable MOZ_X11_EGL=1 . Also, users should ensure that vaapi is available by installing/running vainfo in terminal. In cases where GPU only supports h.264 decode, its beneficial to install h.264ify.

What works:

  1. both 30fps/60fps or higher videos play smoothly at resolutions supported by GPU decoder.
  2. CPU usage is significantly reduced while playing videos

The problems:

  1. The color of videos appears washed out. (0,0,0) is mapped to (16,16,16) and (255,255,255) to (235,235,235). Bug 1726186 (Fixed on Firefox 96+!)
  2. Nvidia users out of luck (for now)


Chromium also supports hardware acceleration in x11 and Wayland. This too was tested in chromium-dev 97. To enable it, first set chrome://flags/#ignore-gpu-blocklist to disabled. Then launch chromium with the following flags:

--use-gl=desktop --enable-features=VaapiVideoDecoder

In theory, --use-gl=desktop should not be required in Wayland, but the wiki editor couldn't get it to work without it. Also h.264ify will be required as stated above.

What works:

  1. both 30fps/60fps or higher videos play smoothly at resolutions supported by GPU decoder, unless Vulkan backend is enabled through flags. However there is little reason to enable it for now
  2. Videos are played color accurately

The problems:

  1. CPU usage reduction is minimal. I could not observe significant improvement in reduction of CPU load or improved battery life ( on different machine) despite confirming that hardware video acceleration was working while playing videos
  2. Nvidia users out of luck again

Google chrome and other flavors

Same should work for google chrome (and other chromium-based browsers like Brave, Vivaldi, edge etc.)

There is a config file for google chrome located at $HOME/.config/chrome-flags.conf (if file does not exist, create it), where you can put flags that chrome should start with by default (because starting browser with parameters sometimes can be hard/pain).

NEEDS SPECIFYING: Does this file work for other chromium based browsers and chromium itself?



Nvidia GPUs

For full GPU acceleration with Nvidia GPUs it's required to set 2 additional flags:

--ignore-gpu-blocklist --enable-zero-copy

Optimizing performance

For better performance it is recommended to set 2 additional flags:

--enable-gpu-rasterization --canvas-oop-rasterization

Epiphany/Gnome Web

Based on GTKwebkit, it provides another option for users that may be not as powerful as chrome or Firefox, but still fairly usable for modern web. To enable hardware accelerated video, first install gstreamer-vaapi for AMD/Intel GPUs or gst-plugins-bad and nvidia-utils for Nvidia GPUs. Then run:

gsettings set org.gnome.Epiphany.web:/ hardware-acceleration-policy 'always'

What works:

  1. both 30fps/60fps or higher videos play smoothly at resolutions supported by gpu decoder
  2. Videos are color accurate
  3. Works for Nvidia users
  4. Good reduction in CPU usage

The problems:

  1. Lack of extensions
  2. No simple way to limit video codec to h.264, hence older GPUs will lack hardware video acceleration in most videos with codecs other than h.264


VLC and MPV both support proper hardware accelerated video in Linux. They can be set to launch when a video is played in a browser. This can be done in Firefox with Open in vlc or ff2mpv extension or other similar extensions. Similarly for chromium, Play with MPV or Play with VLC or similar.

What works:

  1. CPU utilization better than Firefox and chrome
  2. Videos are played with accurate colors
  3. Works for NVIDIA users

The problems:

  1. Many sites with DRM (such as most paid streaming services) and those using custom video players may not work.

Further Reading