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.
Step 1: Install NVIDIA VAAPI driver
Option 1: Install driver from system repository
For Ubuntu 24.04 and higher, the driver package has been made into system repositories, though it’s a bit old.
First, press Ctrl+Alt+T
on keyboard to open up a terminal window, and run command to install it:
sudo apt install nvidia-vaapi-driver
Tips: You may run sudo apt update
to refresh package cache in case of issues..
Option 2: Install it from PPA (Unofficial)
For most recent version, I’ve made the driver package into the unofficial PPA for Ubuntu 22.04, Ubuntu 24.04, and Ubuntu 24.10.
- First, add the PPA by running command:
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.
- Then refresh system package cache by running command:
sudo apt update
- Finally, install the driver package:
sudo apt install nvidia-vaapi-driver
Option 3: Build the NVIDIA VA-API driver from source
Thanks to, you may run the commands below one by one to build the driver library from the source code.
1. First, press Ctrl+Alt+T
to open up a terminal window. When it opens, run command to install dependency packages:
sudo apt install meson gstreamer1.0-plugins-bad libffmpeg-nvenc-dev libva-dev libegl-dev libgstreamer-plugins-bad1.0-dev
2. Next, either go to the Github project page and download the source, or run the command below to clone the source:
git clone https://github.com/elFarto/nvidia-vaapi-driver.git
3. Then, navigate to the source folder:
cd nvidia-vaapi-driver/
If you downloaded the source tarball/zip using web-browser, then open Downloads folder, extract, and right-click on source folder and select “Open in Terminal”.
4. Finally, run the commands below to test, build and install:
./test.sh
meson setup build
meson install -C build
If everything goes well, it will output something looks like: Installing nvidia_drv_video.so to /usr/lib/x86_64-linux-gnu/dri.
Step 2: Verify the VA-API info
To display the information about VA-API driver, first run command to install the vainfo
package:
sudo apt install vainfo
Then run the command below in terminal to tell:
vainfo
For NVIDIA driver higher than version 525, you need to run export NVD_BACKEND=direct
first to enable direct backend control, and export LIBVA_DRIVER_NAME=nvidia
to specify the driver.
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).
Step 3: Config Firefox
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
(for Firefox 136 and earlier).media.hardware-video-decoding.force-enabled
(for Firefox 137 and newer).gfx.x11-egl.force-enabled
widget.dmabuf.force-enabled
Step 4: Setup Environment Variable
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:
- Specify driver name:
export LIBVA_DRIVER_NAME=nvidia
- Disable RDD process sandbox:
export MOZ_DISABLE_RDD_SANDBOX=1
- For NVIDIA 525 and higher, also set direct control:
export NVD_BACKEND=direct
- For legacy NVIDIA 470, specify the EGL vendor library name:
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
- For choice, you may also enable log for debugging purpose:
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:
- First, open home folder, press
Ctrl+h
, find out and click edit the .profile file.
- When file opens, add the previous
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.
Step 5: Verify
While playing a video using your Firefox web browser, you may using nvtop
command to verify.
- First, open terminal (
Ctrl+Alt+T
) and run command to install nvtop:sudo apt install nvtop
- Then, run
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.
Tips: for NVIDIA GPU that does NOT support VP8/VP9 codec, you may use the enhanced-h264ify add-on to block VP8/VP9 codecs on YouTube and use H264 instead.
Uninstall:
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.
Tried it on Mint and unfortunately it is not supported.
vainfo gives following message
vainfo
Trying display: wayland
Trying display: x11
libva info: VA-API version 1.20.0
libva error: vaGetDriverNames() failed with unknown libva error
vaInitialize failed with error code -1 (unknown libva error),exit
Did you try
export NVD_BACKEND=direct
before vainfo? It works good in my NVIDIA only desktop PC, but not for laptop with intel+nvidia GPUs.I did. Though when I typed vainfo –display drm instead I get this
vainfo –display drm
Trying display: drm
libva info: VA-API version 1.20.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.20 (libva 2.20.0)
vainfo: Driver version: VA-API NVDEC driver [direct backend]
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264Main : VAEntrypointVLD
VAProfileH264High : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain12 : VAEntrypointVLD
I think set
export LIBVA_DRIVER_NAME=nvidia
environment should work for you.now it works but I am not sure if Firefox also decodes. On command line after running /usr/bin/firefox I got
libva info: VA-API version 1.20.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva error: /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so init failed
libva info: va_openDriver() returns 1
Nvtop does not show any Compute letter, only Graphic, while the Nvidia command shows
0 35463 G – – – – firefox
# gpu pid type sm mem enc dec command
# Idx # C/G % % % % name
0 1326 G – – – – Xorg
0 1769 G 0 1 – – cinnamon
0 35463 G – – – – firefox
It’s not decoding. For better help, it’s recommended to set
export NVD_LOG=1
first for log. Then, report to https://github.com/elFarto/nvidia-vaapi-driver/issues which can also help others with similar issue.Does not work.
vainfo works and show vdpau with list of Supported profile and entrypoints like on screenshots.
Starting firefox – it also print to terminal:
libva info: VA-API version 1.20.0
libva info: User environment variable requested driver ‘nvidia’
libva info: Trying to open /usr/lib64/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_20
libva info: va_openDriver() returns 0
I tried mp4-web videos, webm, youtube – firefox still use CPU to decode video.
Video Engine Utilization on Nvidia is always 0.
And yes – vdpau works outside of Firefox like in mpv with vaapi or mpv with vdpau.
Update to my previous comment, with more info:
in about:support
I have
HARDWARE_VIDEO_DECODING FEATURE_HARDWARE_VIDEO_DECODING_NO_LINUX_NVIDIA
Firefox intentionally blacklisted all Nvidia GPUs in stable, look there:
https://askubuntu.com/questions/1477892/firefox-refuse-to-use-gpu-hardware-acceleration-with-nvidia-gpu-how-to-fix
Firefox Nightly – required to have video acceleration work on Nvidia with Firefox.
Yes this is 2024 year, and Firefox still can not do hardware video accelersation in Linux.
Unfortunately it doesn’t work to me too.
Firefox still uses way less CPU than Edge on YouTube (but more on Twitch), so I guess that something in this guide still did something great for YouTube.
For those that have double GPU (Intel + Nvidia) just switch from Nvidia On-Demand to Nvidia Performance in order to correctly use vaapi with mvp. For the videos on Firefox, still nothing.
It doesn’t work to me too..
I’ve lready posted a issue in elfarto nvidia-vaapi-driver:
https://github.com/elFarto/nvidia-vaapi-driver/issues/326
My vainfo output is:
libva info: VA-API version 1.20.0
libva info: User environment variable requested driver ‘nvidia’
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/nvidia_drv_video.so
libva info: Found init function __vaDriverInit_1_0
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.20 (libva 2.12.0)
vainfo: Driver version: VA-API NVDEC driver [direct backend]
vainfo: Supported profile and entrypoints
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileH264Main : VAEntrypointVLD
VAProfileH264High : VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileAV1Profile0 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain12 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
VAProfileHEVCMain444 : VAEntrypointVLD
VAProfileHEVCMain444_10 : VAEntrypointVLD
VAProfileHEVCMain444_12 : VAEntrypointVLD
Hello,
I made it work on an old system with an i5-3570K & nVidia GTX 1660 Ti running Ubuntu 22.04.5 LTS.
You need firstly to install these before you build the driver otherwise the YouTube above 1080p doesn’t work because is using VP9 codec.
sudo apt install meson gstreamer1.0-plugins-bad libffmpeg-nvenc-dev libva-dev libegl-dev
sudo apt install libgstreamer-plugins-bad1.0-dev
.After these download the driver from github elFarto’s page
nvidia-vaapi-driver-master.zip
and extract it. Open a terminal and navigate to the downloaded folder of the drivercd Downloads/nvidia-vaapi-driver-master
run the test script
./test.sh
After this you need to build the driver
meson setup build
meson install -C build
Then navigate to home folder open the file
.profile
and like the article above edit the environment variables.In my case:
# set VA-API driver to nVidia
export NVD_BACKEND=direct
export MOZ_DISABLE_RDD_SANDBOX=1
export LIBVA_DRIVER_NAME=nvidia
Finally you need to download the Firefox Nightly to make it work because the Firefox coming preinstalled with Ubuntu doesn’t work.
Then follow the article above and configure the browser:
media.ffmpeg.vaapi.enabled
gfx.x11-egl.force-enabled
widget.dmabuf.force-enabled
According on github comment “as of firefox 137, the option media.ffmpeg.vaapi.enabled has been replaced by
media.hardware-video-decoding.force-enabled“.
media.hardware-video-decoding.force-enabled
I hope Ji m can found some time to test all the above and update this article.