- Enable FireFox Hardware Video Acceleration on Ubuntu
- Switch the Windowing System to Wayland
- VA-API Support
- Configure Environment
- First, run vainfo to check if there is any error
- Second, decide to configure for an individual user or system-wide
- Last, add the following options
- For Intel HD
- For AMD
- For NVIDIA Nouveau
- For NVIDIA’s Propriety Driver
- Notes
- Additional Install
- Intel GPU Monitor
- Intel VA-API
- AMD & NVIDIA Nouveau VA-API
- Extra Codecs
- Firefox Configurations
- Search for ‘ffmpeg’
- Search for ‘vpx’
- Search for ‘webrender’
- Search for ‘hardware-video-decoding’
- Verify
- Monitor GPU
- Intel
- AMD
- NVIDIA
- Reference
- Share this:
- Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
- Verify VA-API:
- Enable VA-API in Firefox:
- Check if Hardware Video Acceleration working:
- Ji m
- 12 responses to Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
Enable FireFox Hardware Video Acceleration on Ubuntu
Firefox supports hardware video acceleration via VA-API and Wayland. Both Intel and AMD support VA-API. NVIDIA needs to use the open-source Nouveau or nvidia-vaapi-driver.
“Hardware video acceleration” and “Firefox” on ArchLinux are very useful and detail resource.
Most AMD cards earlier than Graphics Core Next (GCN) architecture fails to play YouTube videos with 1080p 60p with the help of UVD. The GPU decoder is just too slow.
Switch the Windowing System to Wayland
Wayland is a display server protocol similar to X11 or the X Window System.
In Ubuntu’s login screen, click the login name and pick up “Ubuntu on Wayland” in the lower right corner. If program icons disappear, launch any program with the Win key and they will appear quickly. It would go back to normal after a few minutes.
If the option is not available, edit /etc/gdm3/custom.conf to enable:
$sudo nano /etc/gdm3/custom.conf WaylandEnable=true
For Ubuntu 22.04LTS and after, the default is Wayland. There is no need to change.
VA-API Support
NVIDIA’s propriety driver doesn’t support VA-API. Need to install an additional nvidia-vaapi-driver which is designed to implement VA-API using NVDEC for Firefox. It’s not NVIDIA’s official solution and might have problems with other software.
I have used ‘export MOZ_X11_EGL=1’ and ‘export MOZ_ENABLE_WAYLAND=1’ in /etc/environment with NVIDIA’s propriety driver on X11. There is no hardware video acceleration.
Configure Environment
First, run vainfo to check if there is any error
$sudo apt install vainfo $sudo vainfo error: XDG_RUNTIME_DIR not set in the environment. libva info: VA-API version 1.7.0 libva info: User environment variable requested driver 'iHD' libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so libva info: Found init function __vaDriverInit_1_7 libva info: va_openDriver() returns 0 vainfo: VA-API version: 1.7 (libva 2.6.0) vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 20.1.1 () vainfo: Supported profile and entrypoints VAProfileMPEG2Simple : VAEntrypointVLD VAProfileMPEG2Main : VAEntrypointVLD VAProfileH264Main : VAEntrypointVLD VAProfileH264Main : VAEntrypointEncSliceLP VAProfileH264High : VAEntrypointVLD VAProfileH264High : VAEntrypointEncSliceLP VAProfileJPEGBaseline : VAEntrypointVLD VAProfileJPEGBaseline : VAEntrypointEncPicture VAProfileH264ConstrainedBaseline: VAEntrypointVLD VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP VAProfileVP8Version0_3 : VAEntrypointVLD VAProfileHEVCMain : VAEntrypointVLD VAProfileHEVCMain10 : VAEntrypointVLD VAProfileVP9Profile0 : VAEntrypointVLD VAProfileVP9Profile2 : VAEntrypointVLD
On the right column, “VAEntrypointVLD” means decoding support for this format while “VAEntrypointEncSlice” is encoding support.
Second, decide to configure for an individual user or system-wide
- For individual users: /.profile
- For System-wide: /etc/environment
Last, add the following options
For Intel HD
export LIBVA_DRIVER_NAME=iHD export MOZ_DISABLE_RDD_SANDBOX=1 export MOZ_ENABLE_WAYLAND=1
For AMD
export LIBVA_DRIVER_NAME=radeonsi export MOZ_DISABLE_RDD_SANDBOX=1 export MOZ_ENABLE_WAYLAND=1
For NVIDIA Nouveau
export LIBVA_DRIVER_NAME=nouveau export MOZ_DISABLE_RDD_SANDBOX=1 export MOZ_ENABLE_WAYLAND=1
For NVIDIA’s Propriety Driver
export LIBVA_DRIVER_NAME=nvidia export MOZ_DISABLE_RDD_SANDBOX=1 export MOZ_ENABLE_WAYLAND=1
Notes
- ‘LIBVA_DRIVER_NAME’ is not necessary if vainfo reports no errors
- ‘MOZ_DISABLE_RDD_SANDBOX = 1’ is a must-have because VA-API is blocked by RDD sandbox. This will disable it and won’t affect firefox VCN capability.
Logout and login again. Run about:support in Firefox URL. The “Window Protocole” would change from “xwayland” or “X11” to “wayland”.
Additional Install
Intel GPU Monitor
$sudo apt install intel-gpu-tools
Intel VA-API
Install only when vainfo reports errors.
$sudo apt install intel-media-va-driver
AMD & NVIDIA Nouveau VA-API
Install only when vainfo reports errors.
$sudo apt install mesa-va-drivers
Extra Codecs
To install libaribb24-0, libavcodec-extra, libavcodec-extra58, and libvo-amrwbenc0:
$sudo apt install libavcodec-extra
If “Install third party software for graphics and WiFi hardware and additional media formats” is ignored during Ubuntu installation, install manually:
$sudo apt install ubuntu-restricted-addons
ubuntu-restricted-extras installs both above, ttf-mscorefonts-installer and unrar. The latter two are not related to codecs.
$sudo apt install ubuntu-restricted-extras
Firefox Configurations
For Ubuntu 22.04LTS, the build-in Firefox has enabled it already. To disable, set “media.hardware-video-decoding.enabled” ➞ false
For earlier Ubuntu, run “about:config” in Firefox URL and configure:
Search for ‘ffmpeg’
Search for ‘vpx’
“media.ffvpx.enabled” ➞ false
“media.navigator.mediadatadecoder_vpx_enabled” ➞ true
“media.rdd-vpx.enabled” ➞ false
Search for ‘webrender’
Search for ‘hardware-video-decoding’
Verify
Relaunch Firefox to apply.
Run about:support in Firefox URL.
If the “Window Protocol” is “wayland” and the “Graphics” ➞ “Compositing” is “WebRender”, video decode hardware acceleration is enabled.
On Ubuntu 22.10, the “Window Protocol” is “xwayland” and YouTube videos are still hardware decode accelerated.
Monitor GPU
Intel
AMD
$sudo watch cat /sys/kernel/debug/dri/0/amdgpu_pm_info
$sudo watch cat /sys/kernel/debug/dri/0/radeon_pm_info
Check whether VCN or UVD enables when a video is played. It would refresh every 2 seconds.
NVIDIA
nvidia-smi ships with NVIDIA’s proprierity drivers. It provides memory usage, GPU utilization, and temperature.
If the GPU is decoding, the GPU usage should increase while the CPU decrease. I also use the build-in System Monitor to check.
More discussion is in askUbuntu. If you know any tools to monitor GPU video decode, please shared in comments.
Reference
- GitHub: elFarto / nvidia-vaapi-driver
- ArchLinux: Hardware video acceleration
- ArchLinux: Firefox
- Wiki: Wayland (display server protocol)
- Wiki: ubuntu-restricted-extras
- UbuntuHandbook: Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
- askUbuntu: Enabling hardware acceleration in Firefox
- reddit: Using Firefox on Wayland? Make sure you have MOZ_ENABLE_WAYLAND set to 1!
- askUbuntu: Setting PATH variable in /etc/environment vs .profile
- askUbuntu: Enabling hardware acceleration in Firefox
- LinuxConfig.org: How to enable/disable wayland on Ubuntu 22.04 Desktop
- freedesktop.org: X Clients under Wayland (XWayland)
- blog.szypowi.cz: Enable Mozilla Firefox and Thunderbird on wayland in Ubuntu 20.04
- ubuntu Discourse: Enabling accelerated video decoding in Firefox on Ubuntu 21.04
- reddit: Firefox video hardware acceleration with Nvidia proprietary drivers?
- GitHub: clbr / radeontop
- GitHub: clbr /radeontop: question: which metric shows H264 decoding? #96
- nVidia DEVELOPER: NVIDIA System Management Interface
- askUbuntu: How to measure GPU usage?
Share this:
Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
Hardware video acceleration is a computer technology to make the graphics card to encode and decode video, thus offloading the CPU to save power. And compared to CPU, GPU are normally more efficient at the job.
There are a few ways to achieve this on Ubuntu Linux, including:
- Video Acceleration API (VA-API) – an open source API developed by Intel.
- Video Decode and Presentation API for Unix (VDPAU) – open source API developed by NVIDIA.
- NVENC/NVDEC – NVIDIA’s proprietary API.
The VA-API supports Intel, AMD, and NVIDIA (via open-source Nouveau drivers) GPUs. And it is widely supported by software, such as MPV uses va-api hardware acceleration for video playback by default if available.
The VDPAU API supports both AMD and NVIDIA, but has no support in Firefox or Chromium. And while NVENC/NVDEC is used for NVIDIA GPU only, we usually use VA-API for hardware video acceleration.
Firefox pop-up video encoding/decoding via Intel GPU
Verify VA-API:
NOTE: VA-API does not work on NVIDIA via proprietary drivers as mentioned above. If you installed NVIDIA proprietary driver via ‘Additional Drivers’ utility, this will only work when you choose ‘Intel (Power Saving)’ mode in NVIDIA Prime settings.
The VA-API may work out-of-the-box in Ubuntu. You can firstly open terminal from start menu (click ‘Activities’ and search terminal).
Next install vainfo package via command:
And run it to check VA-API info:
It outputs the driver as well as supported profile. VAEntrypointVLD means decoding support for this format, VAEntrypointEncSlice means encoding support.
If the command outputs an error, you can try to install drivers via command:
- For NVIDIA nouveau and AMD, run command:
sudo apt install mesa-va-drivers
sudo apt install intel-media-va-driver
By setting the environment variable, you can choose which driver to use. For example, set “export LIBVA_DRIVER_NAME=i965” to use i965 driver. The value can also set to “nouveau” for NVIDIA, or “radeonsi” for AMDGPU.
Enable VA-API in Firefox:
Firefox added VA-API support since version 80, though it’s not enabled by default. You can enabled it manually by doing following steps one by one.
Firstly, open Firefox and go to about:config in url bar. Click on “Accept the Risk and Continue”. Then search for following keys, enable or disable them one by one:
- media.ffmpeg.vaapi.enabled set to true
- media.ffvpx.enabled set to false .
- media.rdd-vpx.enabled set to false .
- media.navigator.mediadatadecoder_vpx_enabled set to true .
- If you experience page crashes, try setting security.sandbox.content.level to 0 .
Secondly, set environment variable (for current user only). Open terminal and run command to edit profile file:
When file opens, add following lines to the end:
- (Optional) Specify va-api driver as mentioned above (replace iHD accordingly):
export LIBVA_DRIVER_NAME=iHD
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_ENABLE_WAYLAND=1
Finally, log out and back in. Open Firefox and play a video and see result!
Check if Hardware Video Acceleration working:
During video playback, you can use top command to see CPU usage before and after enable VA-API. For Intel GPU, there’s intel_gpu_top command that monitor it continuously.
Open terminal and run command to install the tool first:
sudo apt install intel-gpu-tools
Start playing video in Firefox and you’ll see the video bar is busy (above 0%) if VA-API starts working.
For AMD GPU, there’s another command line tool “radeontop” available to monitor GPU activity.
NOTE for YouTube videos, the video codec may sometimes not supported by your hardware. To workaround, try h264ify or enhanced-h264ify extension to make YouTube stream H.264 videos instead of VP8/VP9.
Ji m
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 remind me outdated tutorial! 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
12 responses to Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 / 18.04 & Higher
Hi,
I checked it in Debian testing and didn’t work in my case and I think I did all the steps correctly. Maybe the Firefox version from Ubuntu and Debian is different. In Fact I have the latest version available downloaded directly from the website. Thanks
VA-API is ready and enabled by default in Chromium in Debian 11, but not tried in Debian testing. For Firefox, try launching it from terminal via MOZ_ENABLE_WAYLAND=1 variable since Debian defaults to Wayland session:
MOZ_ENABLE_WAYLAND=1 firefox
Hi, I use X11. Anyway I tried what you mentioned and in my case doesn’t work in Firefox using Debian. The Firefox version for Ubuntu maybe it’s slightly different. For instance mpv in Ubuntu the hardware acceleration use to work by default. In Debian you need to modify the config file or the command to launch mpv in order to get hardware acceleration. Thanks.
Hey. Thanks for this amazing guide! It worked for me. I just have one question. Does reducing the sandbox level to zero affect my security in any way? This question in giving me many sleepless nights lol.
Lower level value indicates a less restrictive sandbox. Reset the key (it’s 4 in my case) if you care about it. And keep the value if you don’t experience page crashes (see bug)
I’m using Ubuntu 20.04.3 on X11, FF version 93.00 x64 and CPU is AMD 5300U with Renoir graphics. I did all the steps above but still I can’t get hardware decoding to work. I’m getting 85-90+ percent CPU usage on YouTube videos. I’ve also installed the h-264ify extension to no avail.
Same here with a bunch of Intel and NVidia laptops and PC, all running Mint, cannot make it to work even with the newest Firefox. I tried it for more than 1 year now, no success.