Enable FireFox Hardware Video Acceleration on Ubuntu


Firefox supports hardware video acceleration via VA-API and Wayland. Both Intel and AMD support VA-API. NVIDIA needs to use the open-source Nouveau or nvidia-vaapi-driver.

“Hardware video acceleration” and “Firefox” on ArchLinux are very useful and detail resource.

Most AMD cards earlier than Graphics Core Next (GCN) architecture fails to play YouTube videos with 1080p 60p with the help of UVD. The GPU decoder is just too slow.

Switch the Windowing System to Wayland

Wayland is a display server protocol similar to X11 or the X Window System.

In Ubuntu’s login screen, click the login name and pick up “Ubuntu on Wayland” in the lower right corner. If program icons disappear, launch any program with the Win key and they will appear quickly. It would go back to normal after a few minutes.

If the option is not available, edit /etc/gdm3/custom.conf to enable:

$sudo nano /etc/gdm3/custom.conf
WaylandEnable=true

For Ubuntu 22.04LTS and after, the default is Wayland. There is no need to change.

VA-API Support

NVIDIA’s propriety driver doesn’t support VA-API. Need to install an additional nvidia-vaapi-driver which is designed to implement VA-API using NVDEC for Firefox. It’s not NVIDIA’s official solution and might have problems with other software.

I have used ‘export MOZ_X11_EGL=1’ and ‘export MOZ_ENABLE_WAYLAND=1’ in /etc/environment with NVIDIA’s propriety driver on X11. There is no hardware video acceleration.

Configure Environment

First, run vainfo to check if there is any error

$sudo apt install vainfo
$sudo vainfo

error: XDG_RUNTIME_DIR not set in the environment.
libva info: VA-API version 1.7.0
libva info: User environment variable requested driver 'iHD'
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_7
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.7 (libva 2.6.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 ()
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointVLD

On the right column, “VAEntrypointVLD” means decoding support for this format while “VAEntrypointEncSlice” is encoding support.

Second, decide to configure for an individual user or system-wide

Pick one:

  1. For individual users: /.profile
  2. For System-wide: /etc/environment

Last, add the following options

For Intel HD

export LIBVA_DRIVER_NAME=iHD
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_ENABLE_WAYLAND=1

For AMD

export LIBVA_DRIVER_NAME=radeonsi
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_ENABLE_WAYLAND=1

For NVIDIA Nouveau

export LIBVA_DRIVER_NAME=nouveau
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_ENABLE_WAYLAND=1

For NVIDIA’s Propriety Driver

export LIBVA_DRIVER_NAME=nvidia
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_ENABLE_WAYLAND=1

Notes

  1. ‘LIBVA_DRIVER_NAME’ is not necessary if vainfo reports no errors
  2. ‘MOZ_DISABLE_RDD_SANDBOX = 1’ is a must-have because VA-API is blocked by RDD sandbox. This will disable it and won’t affect firefox VCN capability.

Logout and login again. Run about:support in Firefox URL. The “Window Protocole” would change from “xwayland” or “X11” to “wayland”.

Additional Install

Intel GPU Monitor

$sudo apt install intel-gpu-tools

Intel VA-API

Install only when vainfo reports errors.

$sudo apt install intel-media-va-driver

AMD & NVIDIA Nouveau VA-API

Install only when vainfo reports errors.

$sudo apt install mesa-va-drivers

Extra Codecs

To install libaribb24-0, libavcodec-extra, libavcodec-extra58, and libvo-amrwbenc0:

$sudo apt install libavcodec-extra

If “Install third party software for graphics and WiFi hardware and additional media formats” is ignored during Ubuntu installation, install manually:

$sudo apt install ubuntu-restricted-addons

ubuntu-restricted-extras installs both above, ttf-mscorefonts-installer and unrar. The latter two are not related to codecs.

$sudo apt install ubuntu-restricted-extras

Firefox Configurations

For Ubuntu 22.04LTS, the build-in Firefox has enabled it already. To disable, set “media.hardware-video-decoding.enabled” ➞ false

For earlier Ubuntu, run “about:config” in Firefox URL and configure:

Search for ‘ffmpeg’

“media.ffmpeg.vaapi.enabled” ➞ true

Search for ‘vpx’

“media.ffvpx.enabled” ➞ false
“media.navigator.mediadatadecoder_vpx_enabled” ➞ true
“media.rdd-vpx.enabled” ➞ false

Search for ‘webrender’

“gfx.webrender.all” ➞ true

Search for ‘hardware-video-decoding’

“media.hardware-video-decoding.enabled” ➞ true

Verify

Relaunch Firefox to apply.

Run about:support in Firefox URL.

If the “Window Protocol” is “wayland” and the “Graphics” ➞ “Compositing” is “WebRender”, video decode hardware acceleration is enabled.

On Ubuntu 22.10, the “Window Protocol” is “xwayland” and YouTube videos are still hardware decode accelerated.

Monitor GPU

Intel

$sudo intel_gpu_top
Hardware video acceleration is working if Video/0 is more than 0%.

AMD

For GCN 2.0 and later:

$sudo watch cat /sys/kernel/debug/dri/0/amdgpu_pm_info

Earlier than GCN 1.0:

$sudo watch cat /sys/kernel/debug/dri/0/radeon_pm_info

Check whether VCN or UVD enables when a video is played. It would refresh every 2 seconds.

radeontop shows nothing related to video decode. Both UVD (decode) and VCE (encode) usage are not tracked.

NVIDIA

nvidia-smi ships with NVIDIA’s proprierity drivers. It provides memory usage, GPU utilization, and temperature.

If the GPU is decoding, the GPU usage should increase while the CPU decrease. I also use the build-in System Monitor to check.

More discussion is in askUbuntu. If you know any tools to monitor GPU video decode, please shared in comments.

Reference

  1. GitHub: elFarto / nvidia-vaapi-driver
  2. ArchLinux: Hardware video acceleration
  3. ArchLinux: Firefox
  4. Wiki: Wayland (display server protocol)
  5. Wiki: ubuntu-restricted-extras
  6. UbuntuHandbook: Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
  7. askUbuntu: Enabling hardware acceleration in Firefox
  8. reddit: Using Firefox on Wayland? Make sure you have MOZ_ENABLE_WAYLAND set to 1!
  9. askUbuntu: Setting PATH variable in /etc/environment vs .profile
  10. askUbuntu: Enabling hardware acceleration in Firefox
  11. LinuxConfig.org: How to enable/disable wayland on Ubuntu 22.04 Desktop
  12. freedesktop.org: X Clients under Wayland (XWayland)
  13. blog.szypowi.cz: Enable Mozilla Firefox and Thunderbird on wayland in Ubuntu 20.04
  14. ubuntu Discourse: Enabling accelerated video decoding in Firefox on Ubuntu 21.04
  15. reddit: Firefox video hardware acceleration with Nvidia proprietary drivers?
  16. GitHub: clbr / radeontop
  17. GitHub: clbr /radeontop: question: which metric shows H264 decoding? #96
  18. nVidia DEVELOPER: NVIDIA System Management Interface
  19. askUbuntu: How to measure GPU usage?

One thought on “Enable FireFox Hardware Video Acceleration on Ubuntu

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.