For Ubuntu machine with NVIDIA graphics card, here’s how to implement hardware acceleration for video playback in Firefox web browser.
Firefox so far only supports VA-API for GPU decoding to offload CPU and save power. Both Intel and AMD GPUs support VA-API. However, NVIDIA so far supports the api only through the open-source Nouveau driver.
If you have only NVIDIA GPU running with proprietary driver, then hardware video acceleration does not work out-of-the-box for Firefox.
For choice, there are libvdpau-va-gl1
driver (h.264 only) or libva-vdpau-driver, but both seems no longer updated. The best choice so far is the free open-source nvidia vaapi driver.
NOTE 1: This tutorial so far does not work on Optimus laptop, see this bug report for details.
NOTE 2: This is so far for Firefox only, since other players such as MPV support NVIDIA’s NVDEC out-of-the-box.
NOTE 3: It’s not working for the pre-installed Firefox Snap in my test, since it runs in sandbox. Try installing the official deb package or Mozilla PPA package.
The driver package has been made into Ubuntu repository since Ubuntu 23.10.
So current Ubuntu 23.10 & Ubuntu 24.04 users can simply press Ctrl+Alt+T
to open terminal, and run command to install it:
sudo apt install nvidia-vaapi-driver
For most recent version, there’s an unofficial PPA contains the package for Ubuntu 22.04, Ubuntu 23.10, and Ubuntu 24.04.
sudo add-apt-repository ppa:ubuntuhandbook1/nvidia-vaapi
Type user password when it asks (no asterisk feedback) for sudo authentication and hit Enter to continue.
sudo apt update
sudo apt install nvidia-vaapi-driver
Then, also install the vainfo
to verify the vaapi info:
sudo apt install vainfo
Now in terminal window, run command:
vainfo
For NVIDIA driver higher than version 525, you need to run export NVD_BACKEND=direct
first to enable direct backend control.
It should outputs something like the screenshot below shows you, including va-api version, and driver version (VA-API NVDEC driver), along with supported codecs.
You can try playing a video file from command line, using MPV (higher than v0.36) to verify if va-api works:
mpv --hwdec=vaapi /path/to/video-file
It shout outputs something looks like Using hardware decoding (vaapi).
Now launch Firefox, type about:config
and hit Enter, then click “Accept the Risk and Continue” to go settings page.
Next, type following keys one by one in filter box, and set them to true:
media.ffmpeg.vaapi.enabled
gfx.x11-egl.force-enabled
widget.dmabuf.force-enabled
In terminal window (Ctrl+Alt+T), run following commands one by one to setup the environment variable for Firefox va-api to work on NVIDIA:
export LIBVA_DRIVER_NAME=nvidia
export MOZ_DISABLE_RDD_SANDBOX=1
export NVD_BACKEND=direct
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
export NVD_LOG=1
Finally, start Firefox from same terminal window /usr/bin/firefox
and play a video to verify (see next step).
If it works, you can make the environment variables permanent via following steps:
Ctrl+h
, find out and click edit the .profile file.export
commands that you run (exclude the NVD_LOG) into end as new lines Finally, save the file.You need to log out and back in to make the .profile
file changes to work.
While playing a video using your Firefox web browser, you may using nvtop
command to verify.
Ctrl+Alt+T
) and run command to install nvtop: sudo apt install nvtop
nvtop
command in terminal while video playback. If the GPU is decoding, then there’s a line in bottom marked as Compute type, with info of which process and command. In the case, it should be something to do with firefox.For choice, you may also run nvidia-smi pmon
instead, there should be type C in output for corresponding process while playback.
For more, see nvidia-vaapi-driver in github page.
If the driver somehow does not work for you, you may remove it by running command in terminal:
sudo apt remove --autoremove nvidia-vaapi-driver
Also, remove the PPA (if added) via command:
sudo add-apt-repository --remove ppa:ubuntuhandbook1/nvidia-vaapi
You may also go to about:config
page in Firefox to undo the changes you did, and remove the export
(if set) lines in .profiles
file.
The post Get Firefox VA-API Hardware Acceleration working on NVIDIA GPU appeared first on Osgrove.
The Linux terminal is a powerful tool allowing users to control their system precisely and…
Welcome to the Ubuntu Weekly Newsletter, Issue 876 for the week of January 19 –…
Canonical Ceph with IntelⓇ Quick Assist Technology (QAT) Photo by v2osk on Unsplash When storing…
Introduction Using Kafka for Remote Procedure Calls (RPC) might raise eyebrows among seasoned developers. At…
This article provides a guide for how to install PalWorld on Ubuntu VPS server. How…
Using APT to manage software on Ubuntu (or similar Linux systems) is generally simple. It…