Hardware-accelerated video playback is typically available with modern GPUs. Unforunately,
Linux distributions typically don't enable out-of-the-box support for it in Firefox.
This document covers what's needed to enable such support.
Several NVidia-specific details are mentioned (namely use of
Nvidia NVDEC)
but is GPU-agnostic overall.
To see which video formats are supported by your hardware run vainfo
Note: Support for GPU video acceleration is only available for Firefox (Chrome does not support it).
Install the Video Acceleration API (VAAPI) implementation that uses Nvidia NVDEC as a backend.
There is one implementation available: nvidia-vaapi-driver
. This only supports decoding, not encoding, but suffices for Firefox acceleration. This is available via most distributions’ package managers but for those that don’t offer it (e.g. older Ubuntu versions) it can be easily installed manually:
apt install build-essential git gstreamer1.0-plugins-bad libgstreamer-plugins-bad1.0-dev libffmpeg-nvenc-dev libva-dev libegl-dev meson
git clone https://github.com/elFarto/nvidia-vaapi-driver
cd nvidia-vaapi-driver/
meson setup build
sudo meson install -C build
This driver also supports recent versions (≥0.3.5) of the mpv video player using mpv --hwdec=vaapi
. It is not needed though since using mpv --hwdec=auto
should already work fine for accelerated playback (one can also put hwdec=auto
into ~/.config/mpv/mpv.conf
).
Make sure that the nvidia_drm
module is loaded with modeset support. This is done by setting the nvidia-drm.modeset=1
kernel parameter. It should be sufficient to include the following lines in /etc/modprobe.d/nvidia-graphics-drivers-kms.conf
# This file was generated by nvidia-driver-535
# Set value to 0 to disable modesetting
options nvidia-drm modeset=1
If correctly-configured then cat /sys/module/nvidia_drm/parameters/modeset
should output Y
and lsmod|grep nvidia_drm
should include something like nvidia_modeset 1314816 18 nvidia_drm
The /etc/glvnd/egl_vendor.d/10_nvidia.json
file advertises the EGL library. This file is missing on some systems. To create it run the following as root
:
cat > /etc/glvnd/egl_vendor.d/10_nvidia.json << END
{
"file_format_version" : "1.0.0",
"ICD" : {
"library_path" : "libEGL_nvidia.so.0"
}
}
END
Environment variables can be placed in /etc/environment
or in a wrapper script. The following variables should be set:
MOZ_DISABLE_RDD_SANDBOX=1
LIBVA_DRIVER_NAME=nvidia
MOZ_X11_EGL=1
Details:
MOZ_DISABLE_RDD_SANDBOX=1
→ Disable the Remote Data Decoder process sandbox
LIBVA_DRIVER_NAME=nvidia
→ This should be set to match your hardware:
MOZ_X11_EGL=1
→ Forces Firefox to use the EGL) backend when running under X11.
Alternatively, one can set gfx.x11-egl.force-enabled=true
within Firefox (test first before doing so).
These are set via about:config (manually enter it since for security reasons the page can't be linked to from here).
All options under DOM and Media GPU Decode must be set for GPU-accelerated video playback.
gfx.webrender.all
→ true
Forces WebRender to always be used. WebRender is a GPU-based 2D rendering engine written in Rust. See the Gitgub page for details.
layers.gpu-process.enabled
→ true
Enable running GPU-specific layer rendering code (e.g. compositing) in a separate process. This can reduce the probability of a bug in such code crashing the entire browser.
layers.mlgpu.enabled
→ true
Enable use of the GPU for compositing (I think).
media.ffmpeg.vaapi.enabled
→ true
Enables use of the Video Acceleration API.
media.gpu-process-decoder
→ true
Enable running GPU-based media decoder code in a separate process. This can reduce the probability of a bug in such code crashing the entire browser.
media.rdd-ffmpeg.enabled
→ true
Required for H264 playback via VAAPI. It was previously set false to prevent crashes of the Remote Data Decoder process; the issues that led to crashes have been mostly resolved.
widget.dmabuf.force-enabled
→ true
If set then forces the use of kernel’s dma-buf subsystem. This is likely needed for accelerated video playback (especially under Wayland). There have been reports that this may prevent system suspend/resume from working properly; see this issue for details and fixes.
dom.webgpu.enabled
→ trueTest basic support by running eglinfo -B | grep -C2 'EGL vendor string:'
If things are working correctly then running correctly this will output:
X11 platform:
EGL API version: 1.5
EGL vendor string: NVIDIA
EGL version string: 1.5
EGL client APIs: OpenGL_ES OpenGL
--
Device platform:
EGL API version: 1.5
EGL vendor string: NVIDIA
EGL version string: 1.5
EGL client APIs: OpenGL_ES OpenGL
If things are not correct then the output will be:
libEGL warning: DRI3: Screen seems not DRI3 capable
libEGL warning: DRI2: failed to authenticate
X11 platform:
EGL API version: 1.5
EGL vendor string: Mesa Project
EGL version string: 1.5
EGL client APIs: OpenGL OpenGL_ES
Next open Firefox and go to about:support (manually enter it since for security reasons the page can't be linked to from here).
The following should be visible:
WebRender
WebRender (software)
EGL
and not with GLX
Yes
NVIDIA GeForce RTX 3050/PCIe/SSE2
0x10de
0x2507
nvidia/unknown
535.129.3.0
0
Yes
llvmpipe (LLVM 15.0.7, 256 bits)
Mesa
llvmpipe (LLVM 15.0.7, 256 bits)
mesa/llvmpipe
23.2.1.0
0
BLOCKLIST_FEATURE_FAILURE_SOFTWARE_GL
FEATURE_FAILURE_REQUIRES_EGL
Supported
:
Checking that video decoding is being done on the GPU:
Open nvidia-settings
and switch to the GPU section. The Video Engine Utilization value should be non-zero (e.g. 1%).
To make the GPU usage more apparent one can pause the video then hold down the , or . key, this should make the GPU usage jump up to ~20-50%.
One can see which processes are using the GPU using nvidia-smi
When Firefox is running it should appear multiple times under Processes with the types listed G
.C+G
.