NVIDIA Firefox hardware video decoding on Linux Mint 21 / Ubuntu 22.04 (jammy) VA-API
Update August 2022: This also works fine on Linux Mint 21 and Ubuntu 22.04 Jammy Jellyfish
Update October 2022: The mesa drivers ppa no longer supports Ubuntu 20.04 (or systems based on this), therefore I recommend to update to 22.04 before attempting this.
Warning: This guide involves using nightly builds of packages and there are is a chance that it doesn't work as expected or causes a boot failure. I recommend to install timeshift or appropriate snapshot tool to backup your system first so you can restore back if needed.
One of the issues with using Linux as a desktop is watching video. This has improved considerably over the last couple of years with Firefox adding hardware decoding support via VA-API for Linux desktops and if your PC has an Intel Graphics chip (usually on the processor), it's simple enough to enable it.
This improved the experience on my laptop. Even though that has an NVIDIA graphics card, is also has Intel graphics built into the Core i5 chip.
The desktop though runs an AMD Ryzen 5 3600 which has no graphics. Graphics is handled by an NVIDIA GeForce GTX 1660 6GB card (which I now feel extremely fortunate to have brought right at the end of 2019 for £173).
Playing games works well (another improvement for the Linux desktop in recent years), but watching videos previously relied on pure CPU decoding, which although worked fine, would consume some CPU power and occasionally cause the fans to speed up / slow down. Yes, I might have solved that by tweaking fan curves in the BIOS, but I'd been waiting for the day where either NVIDIA adds VA-API support in their driver, Firefox adds NVENC support (NVIDIA's proprietary API), or someone writes a working implementation that can use NVENC and implement VA-API for Firefox.
I'm aware the open source nouveau drivers, which do give VA-API support, but they come with new disadvantages.
Thanks to the community, we have something at last. I've got it working in Linux Mint 20 and hopefully the notes I've taken will help others do so, or those on Ubuntu 20.04 or other distros based on it (e.g., Pop!_OS).
Note: I've done this on both my existing install and in a clean install, so instructions below should be pretty close. Let me know if you've had to fix anything though so I can update instructions to help others. Much of the work is on the command line as it's easier to copy/paste. You could replace the apt install commands with finding the relevant package in the Software Manager if you want.
The magic driver is here: https://github.com/elFarto/nvidia-vaapi-driver. Before we clone it and try installing it though, there are a number of dependencies you probably need.
Firefox
Firefox should be version 96 or later. Mint should have updated you to the Mozilla built version as of January 2022. You'll need to set the following settings in about:config
- media.ffmpeg.vaapi.enabled
- media.rdd-ffmpeg.enabled
- gfx.x11-egl.force-enabled
The driver does not support Chrome, Chromium, Edge or others.
VA-API / VAINFO and LIBVA-DEV
You'll need this if you haven't got it already.
sudo apt install vainfo libva-dev
For those with Intel graphics
If you have Intel graphics, including hybrid Intel+NVIDIA, just install the Intel drivers and vainfo above.
sudo apt install i965-va-driver
Run vainfo to confirm the driver is found and all is good, Firefox should start using hardware decoding (where the hardware supports it)
NVIDIA drivers
If you've only got NVIDIA graphics, read on. First ensure your drivers are up to date.
In Linux Mint, it's simple to go to the Driver Manager and NVIDIA drivers should get listed there. Pick the latest, which at this time is nvidia-driver-495.
I also recommend switching to a recent Kernel / HWE if your hardware is within the last three years. In Mint, you can do this in the Update Manager -> View -> Linux Kernels. Pick the most recent 5.13.
Ninja, Meson and Python3
sudo apt install git sudo apt install ninja-build sudo apt install python3-pip sudo pip3 install meson
Gsteamer and Mesa graphics drivers
Note that libgstreamer-plugins-bad1.0-dev package is quite large (139MB download and 592MB disk space including dependencies at time of writing). The dist-upgrade after adding the ppa is also heavy (84.5MB download, 237MB disk space), so have a good Internet connection/mirror and disk space.
sudo apt install libgstreamer-plugins-bad1.0-0 sudo apt install libgstreamer-plugins-bad1.0-dev sudo add-apt-repository ppa:oibaf/graphics-drivers sudo apt update sudo apt dist-upgrade sudo apt install gstreamer1.0-vaapi (this may be auto-installed)
Update: On Linux Mint 21, I did have to issue a "sudo apt --fix-broken install" after the dist-upgrade. This appears to work fine after that though.
NV-CODEC headers
This is small and make / make install look like they do very little, but it's needed!
cd ~ mkdir nv-codec-headers_build cd nv-codec-headers_build git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git cd nv-codec-headers make sudo make install
NVIDIA DRM
sudo nano /etc/default/grub
Add "nvidia_drm.modeset=1" to GRUB_CMDLINE_LINUX_DEFAULT, e.g.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nvidia_drm.modeset=1"
sudo update-grub
Reboot!
NVIDIA VA-API Driver
cd ~ git clone https://github.com/elFarto/nvidia-vaapi-driver.git cd nvidia-vaapi-driver meson setup build sudo meson install -C build sudo nano /etc/environment
Add these lines
LIBVA_DRIVER_NAME=nvidia MOZ_DISABLE_RDD_SANDBOX=1
Reboot again.
Test with vainfo
vainfo
libva info: VA-API version 1.13.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.13 (libva 2.6.0) vainfo: Driver version: VA-API NVDEC driver vainfo: Supported profile and entrypoints VAProfileMPEG2Simple : VAEntrypointVLD VAProfileMPEG2Main : VAEntrypointVLD VAProfileVC1Simple : VAEntrypointVLD VAProfileVC1Main : VAEntrypointVLD VAProfileVC1Advanced : VAEntrypointVLD <unknown profile> : VAEntrypointVLD VAProfileH264Main : VAEntrypointVLD VAProfileH264High : VAEntrypointVLD VAProfileH264ConstrainedBaseline: VAEntrypointVLD VAProfileHEVCMain : VAEntrypointVLD VAProfileVP8Version0_3 : VAEntrypointVLD VAProfileVP9Profile0 : VAEntrypointVLD
If there are issues, adding "export NVD_LOG=1" before calling vainfo may provide clues.
On my second attempt, after the second reboot I did find the NVIDIA drivers were no longer used, and Mint warned me of this after boot. If this happens to you, simple go to the driver manager and apply the NVIDIA drivers again.
I've tried both youtube.com and the BBC's iplayer and FHD video uses no more than 1% CPU. The NVIDIA card doesn't break a sweat either and the PC is very quiet now when playing videos online.
Many thanks to Stephen's NVIDIA VA-API Driver, and also these links that have helped:
- https://launchpad.net/~oibaf/+archive/ubuntu/graphics-drivers
- http://lifestyletransfer.com/how-to-install-gstreamer-vaapi-plugins-on-ubuntu/
- https://itectec.com/ubuntu/ubuntu-how-to-install-compile-nvenc-in-ubuntu/
- https://askubuntu.com/questions/1212424/update-meson-on-ubuntu-18-04-4-lts-force-update
- https://wiki.archlinux.org/title/Hardware_video_acceleration
- https://wiki.archlinux.org/title/Firefox#Hardware_video_acceleration