Difference between revisions of "Hardware video acceleration in Web browsers"
(Fork from /r/linux_gaming) |
|||
Line 35: | Line 35: | ||
# 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 | # 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 | ||
# Nvidia users out of luck again | # 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 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). | |||
{{Warning|Problem='''NEEDS SPECIFYING:''' Does this file work for other chromium based browsers and chromium itself?}} | |||
$HOME/.config/chrome-flags.conf: | |||
<pre> | |||
--enable-features=VaapiVideoDecoder | |||
--use-gl=desktop | |||
</pre> | |||
== Epiphany/Gnome Web == | == Epiphany/Gnome Web == |
Revision as of 15:21, 16 January 2022
Introduction
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.
Firefox
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:
- both 30fps/60fps or higher videos play smoothly at resolutions supported by gpu decoder.
- CPU usage is significantly reduced while playing videos
The problems:
- The colour 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+!)
- Nvidia users out of luck (for now)
Chromium
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 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:
- 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
- Videos are played colour accurately
The problems:
- 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
- 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 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).
$HOME/.config/chrome-flags.conf:
--enable-features=VaapiVideoDecoder --use-gl=desktop
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:
- both 30fps/60fps or higher videos play smoothly at resolutions supported by gpu decoder
- Videos are color accurate
- Works for nVidia users
- Good reduction in CPU usage
The problems:
- Lack of extensions
- 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
Alternatives
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:
- CPU utilisation better than firefox and chrome
- Videos are played with accurate colours
- Works for NVIDIA users
The problems:
- Many sites with DRM (such as most paid streaming services) and those using custom video players may not work.
Further Reading
- Arch Wiki - Hardware Accelerated Video - Resource on setting up hardware video acceleration and installing
vainfo
- Arch Wiki - Web Browsers - List of web browsers available in Linux