Firefox now supports hardware video acceleration (YouTube etc)

Soldato
Joined
18 Aug 2007
Posts
9,704
Location
Liverpool
In case anyone didn't know, Firefox now finally supports (>v80) hardware video acceleration/decoding on the web, including YouTube etc. This is VAAPI only for now, and works on both Wayland and X11 - though I've found the latter far more useful. As it's X11 support, this works on basically all Linux distros as well as *BSD and it's been flawless for me. I have finally been able to ditch janky ungoogled-chromium installs (patched for VAAPI) and just use the built in Firefox packages with no messing. Win! Tested on Debian Buster and Bullseye, Arch, Fedora 32 and 33, and FreeBSD.

Steps to activate:

1) Firefox needs launching with MOZ_X11_EGL=1 and you can do this either with the launcher, or set it as an environmental variable in /etc/environment or .bashrc/.zshrc/whatever (export MOZ_X11_EGL=1).

2) Change the following preferences in about:config
Code:
gfx.webrender.all:true
media.ffmpeg.dmabuf-textures.enabled:true
media.ffmpeg.vaapi.enabled:true
media.ffvpx.enabled:false

3) Install h264ify or enhanced-h264ify as the acceleration is x264-only at the moment. The former addon works on all sites including embedded videos. The latter only works on YouTube but does allow disabling of volume normalisation and allows you to choose which codecs to allow/disable. Swings and roundabouts.

You will need to have the appropriate hardware drivers for your platform (eg i965 for Intel iGPU, amdgpu+mesa for AMD) as well as the libva and vaapi packages for your platform (libva, libva-intel-driver or similar depending on your hardware). You can test that you're set with vainfo - the package is either called vainfo or libva-utils depending on distro/platform. If vainfo gives a non-error output (i.e. a list of codecs it can decode and encode) you're set.

You can test that it's working by launching Firefox with MOZ_LOG="PlatformDecoderModule:5" - for example by running MOZ_LOG="PlatformDecoderModule:5" firefox in a terminal. While this does restrict you to x264 (and thus 1080p) on YouTube, it's great for low powered laptops etc running on battery (not so much on my Threadripper desktop system, but meh). YMMV but it's pretty easy to get working and the Arch Wiki has some distro-agnostic info if you get stuck.
 
Last edited:
Soldato
Joined
1 Nov 2007
Posts
5,600
Location
England
That sounds pretty cool. However, having said that I've not had any problems playing YouTube videos even when they are 4k videos. Unfortunately, I'm stuck on the ESR release of Firefox so won't get to update from 78 until version 88 comes out.
 
Soldato
Joined
1 Nov 2007
Posts
5,600
Location
England
Just to say in this thread although the video acceleration requires > 80 you can still set gfx.webrender.all to True in earlier versions and it greatly speeds up Firefox. Works perfectly in 78 ESR.
 
Associate
Joined
5 Feb 2012
Posts
46
Location
London
Firefox used to work fine for me until I got a 3080 and now it is laggy and choppy. Turning off video acceleration made no difference. However driver 455.28 seems to have made the problem less severe.

nvidia-smi reports my gpu is using something like 33W then when you scroll nothing happens for about half a second or a second and then it suddenly starts scrolling. Power usage jumps up to 99W momentarily then settles down to sat 66W while scrolling.

On Chrome power usage is 33W and when you start to scroll it might jump up to 36W or 37W, scrolling is super smooth and there is no lag.
 
Soldato
OP
Joined
18 Aug 2007
Posts
9,704
Location
Liverpool
Firefox used to work fine for me until I got a 3080 and now it is laggy and choppy. Turning off video acceleration made no difference. However driver 455.28 seems to have made the problem less severe.

nvidia-smi reports my gpu is using something like 33W then when you scroll nothing happens for about half a second or a second and then it suddenly starts scrolling. Power usage jumps up to 99W momentarily then settles down to sat 66W while scrolling.

On Chrome power usage is 33W and when you start to scroll it might jump up to 36W or 37W, scrolling is super smooth and there is no lag.

Yeah, Nvidia and Linux... When you say you disabled 'video acceleration', did you disable webrender? Was it running in the first place? Are you running OGL? On X11 or Wayland? Lots to play with but the answer is still probably 'Nvidia on Linux'. Have you tried with nouveau?
 
Associate
Joined
5 Feb 2012
Posts
46
Location
London
Ok so I didn't touch webrender, I only changed the performance setting under Preferences (which includes a Use hardware acceleration when available).

So I've just changed gfx.webrender.all from false to true and re-enabled the performance settings and now it is scrolling smoothly and GPU power usages is only going up by a couple of watts instead of 60 or so, so it has made a huge difference.

It is interesting that it worked much more smoothly on the GTX 980 without touching any settings.
 
Soldato
OP
Joined
18 Aug 2007
Posts
9,704
Location
Liverpool
@Cithan I'm glad you got it sorted. WebRender is Mozilla's new rendering engine with more modern supports, hardware aware and much smoother and faster graphics. Now follow the OP and get hardware accelerated video working.

Edit: Actually I'm not sure video hardware acceleration will work with Nvidia due to VAAPI (vs VDPAU).
 
Associate
Joined
5 Feb 2012
Posts
46
Location
London
@Cithan I'm glad you got it sorted. WebRender is Mozilla's new rendering engine with more modern supports, hardware aware and much smoother and faster graphics. Now follow the OP and get hardware accelerated video working.

Edit: Actually I'm not sure video hardware acceleration will work with Nvidia due to VAAPI (vs VDPAU).

Thanks very much for your help @Rainmaker , I'm very happy to have the smooth scrolling working! I did have a go at the video settings in the OP, I couldn't get it to work but I'm not going to persist since enhanced-h264ify blocked the streams that allow You Tube so play in 4k, at least for this video it did: https://www.youtube.com/watch?v=LXb3EKWsInQ It wasn't until I unblocked the other codecs that 4k became available again. So I think I'll stick with CPU render...
 
Associate
Joined
5 Feb 2012
Posts
46
Location
London
@Rainmaker

Just in case you are interested, here is my console output for Firefox:

Code:
Can't find symbol 'eglGetNativeClientBufferANDROID'.
Can't find symbol 'eglQuerySurfacePointerANGLE'.
Can't find symbol 'eglCreateStreamProducerD3DTextureANGLE'.
Can't find symbol 'eglStreamPostD3DTextureANGLE'.
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
Can't find symbol 'eglGetNativeClientBufferANDROID'.
Can't find symbol 'eglQuerySurfacePointerANGLE'.
Can't find symbol 'eglCreateStreamProducerD3DTextureANGLE'.
Can't find symbol 'eglStreamPostD3DTextureANGLE'.
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[Child 472101, MediaDecoderStateMachine #1] WARNING: Decoder=7fb8780eec00 Decode error: NS_ERROR_DOM_MEDIA_FATAL_ERR (0x806e0005) - RefPtr<MediaSourceTrackDemuxer::SamplesPromise> mozilla::MediaSourceTrackDemuxer::DoGetSamples(int32_t): manager is detached.: file /build/firefox-Gh9MKO/firefox-82.0.2+build1/dom/media/MediaDecoderStateMachine.cpp, line 3471
[Child 472101, MediaDecoderStateMachine #1] WARNING: Decoder=7fb8780eec00 Decode error: NS_ERROR_DOM_MEDIA_FATAL_ERR (0x806e0005) - RefPtr<MediaSourceTrackDemuxer::SamplesPromise> mozilla::MediaSourceTrackDemuxer::DoGetSamples(int32_t): manager is detached.: file /build/firefox-Gh9MKO/firefox-82.0.2+build1/dom/media/MediaDecoderStateMachine.cpp, line 3471
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
libva info: VA-API version 1.7.0
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
 
Back
Top Bottom