./ahmedhashim

NVDEC in the Browser

I was going through the packages on my Arch desktop to see what could be pruned or upgraded, and noticed that nothing was set up for my RTX 3080 to decode video in hardware. That seemed like a one-package fix, so I installed the driver and checked whether my browsers were using it, starting with brave://gpu.

At the top of the page, video decoding was Hardware accelerated. However, several hundred lines further down:

Video Acceleration Information
==============================
Decoding:
Encoding:

An empty Decoding: just means there was no hardware decoder available for Chromium to use; the first line only shows that it is not blocklisted. Firefox was no better. It had hardware decoding turned on in its settings, but a 4K video kept its decoder process busy on the CPU while the GPU’s decoder sat idle.

On Linux, browsers use VA-API to play back video on the GPU. There is no official VA-API implementation for NVIDIA cards, so people use nvidia-vaapi-driver to translate to NVDEC. That’s the driver I’d installed, with its two environment variables set in my Hyprland config:

sudo pacman -S libva-nvidia-driver
LIBVA_DRIVER_NAME=nvidia
NVD_BACKEND=direct

vainfo showed a number of H.264, HEVC and AV1 profiles, so clearly the appropriate driver support was available. The browsers just weren’t using it.

Chromium

Chromium disables VA-API under Linux by default, and doesn’t enable it for NVIDIA GPUs either. Brave reads extra options from ~/.config/brave-flags.conf, with one option per line. So I inserted --enable-features=AcceleratedVideoDecodeLinuxGL, completely exited from Brave (just closing all windows did not suffice) and checked brave://gpu again. Decoding: was still empty.

As it happens, the core switches are listed in the README supplied with the driver. The set of options which seemed to work was:

--enable-features=AcceleratedVideoDecodeLinuxGL,VaapiVideoDecoder,VaapiOnNvidiaGPUs,VaapiIgnoreDriverChecks
--ignore-gpu-blocklist
--use-gl=angle
--use-angle=gl

I’ve included all of these under one --enable-features to be safe, as it appears Chromium may ignore an option given more than once. After restarting again, the Decoding: section contained:

Decode h264 high              : 48x16 to 4096x4096 pixels
Decode vp9 profile0           : 128x128 to 8192x8192 pixels
Decode hevc main              : 144x144 to 8192x8192 pixels
Decode av1 profile main       : 128x128 to 8192x8192 pixels

There’s no guarantee that any of these profiles will be in use just because they are supported. I watched a YouTube clip, monitoring nvidia-smi, and the NVDEC usage was between 0 and 1%, which may be misleading. It was an AV1 video, only 854x480, so there’s very little decoding to be done and hardly any demand on NVDEC.

brave://media-internals settles it, as it tells us what decoder each player used:

kVideoDecoderName: VaapiVideoDecoder
kIsPlatformVideoDecoder: true

It would be Dav1dVideoDecoder or VpxVideoDecoder if using a software decoder. So, to see the GPU actually doing work, I played a 4K60 VP9 video:

$ nvidia-smi pmon -c 1 -s u
# gpu         pid   type     sm    mem    enc    dec    jpg    ofa    command
    0       5388   C+G      -      -      -     18      -      -    renderD128 --us

About 18% decoder utilization, with almost 0% CPU usage by Brave. According to stats for nerds, there were 20 dropped frames out of a total of 3285.

There was another difference when comparing the brave://gpu outputs with and without these flags. The GPU process had gone from Sandboxed: true to Sandboxed: false once the flags were in, meaning it would be easier to escalate a GPU-side exploit. The flags are also Chromium features that may be changed or removed at any time. So if decoding stops working after an update, an empty Decoding: section is the first thing to check.

Firefox

Firefox skips the command-line flags. According to the driver’s README, since Firefox 137 hardware decoding is turned on with an about:config pref:

media.hardware-video-decoding.force-enabled = true

My profile already had it set. During the 4K video from earlier, the decoder sat at 0%, and Firefox’s RDD process, which is where it decodes media, was using about 279% CPU. Its memory map showed nvidia_drv_video.so loaded next to libdav1d and libvpx, but no libcuda. The driver was loading and then never reaching the GPU, so Firefox fell back to decoding in software.

The driver’s README has a Firefox section too, and it lists one more requirement: MOZ_DISABLE_RDD_SANDBOX=1. Before changing anything for good, I tried it on a throwaway profile with the pref set in its user.js:

mkdir -p /tmp/ffprobe
echo 'user_pref("media.hardware-video-decoding.force-enabled", true);' > /tmp/ffprobe/user.js
MOZ_DISABLE_RDD_SANDBOX=1 firefox -no-remote -profile /tmp/ffprobe

This time the RDD process loaded libcuda and libnvcuvid, showed up in nvidia-smi with the decoder at 17%, and dropped to about 2% CPU. I added the variable to my Hyprland config next to the other two, logged back in, and my normal profile did the same.

It’s the same tradeoff as Brave. RDD is the process that parses untrusted video from websites, and that variable turns its sandbox off. Firefox also doesn’t support HEVC on Linux, which doesn’t matter for YouTube.