Get Firefox VA-API Hardware Acceleration working on NVIDIA GPU

Last updated: January 31, 2024 — 10 Comments

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

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.

  • 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

Then, also install the vainfo to verify the vaapi info:

sudo apt install vainfo

Step 2: Verify the VA-API info

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, 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
  • 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.

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.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

10 responses to Get Firefox VA-API Hardware Acceleration working on NVIDIA GPU

  1. 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.

  2. 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

  3. 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.

  4. 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.

  5. 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.

  6. 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

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*