Enabling accelerated video decoding in Firefox on Ubuntu 21.04

I have followed this guide. Here are my about:config settings:
media.ffmpeg.vaapi.enabled : true
media.ffvpx.enabled : false
media.rdd-vpx.enabled : false
mediadatadecoder_vpx_enabled : false

$ sudo apt install ubuntu-restricted-extras
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ubuntu-restricted-extras is already the newest version (67).

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

about:support values –

Compositing: WebRender (Software)
Window Protocol: wayland

intel_gpu_top output while playing the video

      ENGINE      BUSY                                      MI_SEMA MI_WAIT
 Render/3D/0   16.50% |█████▊                             |      0%      0%
   Blitter/0    0.00% |                                   |      0%      0%
     Video/0    0.00% |                                   |      0%      0%

VideoEnhance/0 0.00% | | 0% 0%

^C

I don’t have a 4k video to test in VLC.

No improvement after setting media.rdd-process.enabled to false

      ENGINE      BUSY                                      MI_SEMA MI_WAIT
 Render/3D/0   14.35% |█████                              |      0%      0%
   Blitter/0    0.00% |                                   |      0%      0%
     Video/0    0.00% |                                   |      0%      0%

VideoEnhance/0 0.00% | | 0% 0%

^C

WebRender (Software)

That’s your problem. Software WebRender is still software rendering. Hardware rendering (WebRender) is a prerequisite in order to use VA-API in Firefox. Try setting gfx.webrender.all to true and restart Firefox.

The arch wiki explicitly mentions this, unfortunately this guide did not. I would edit the guide but the edit button no longer shows up, probably because the post is old?

1 Like

I set gfx.webrender.all to true and now it shows:
Compositing WebRender

But the choppy video and frame dropping issue still persists.

      ENGINE      BUSY                                      MI_SEMA MI_WAIT
 Render/3D/0   16.49% |█████▊                             |      0%      0%
   Blitter/0    0.00% |                                   |      0%      0%
     Video/0    0.00% |                                   |      0%      0%

VideoEnhance/0 0.00% | | 0% 0%

^C

Hm, then it’s probably something else then.

As one more sanity check can you verify VP9 or H264 is shown in YouTube when right clicking the video > stats for nerds.

If that is VP9 or H264 then I’m out of simple solutions. Everything you’ve set looks correct.

I’d recommend checking the output of things like vainfo and running Firefox with MOZ_LOG="PlatformDecoderModule:5" firefox. Anything mentioning VA-API is relevant.

It is vp09, i don’t see H264 here for that video. As you can see 1000s of frames are dropped as the video plays.

$ vainfo
libva info: VA-API version 1.10.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_10
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.10 (libva 2.10.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 21.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

Running with

$ MOZ_LOG="PlatformDecoderModule:5" firefox

but still the same issue.

Something interesting I found in the logs when running with MOZ_LOG

[Child 6908: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
[Child 6908: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform

But I did enable ffmpeg vaapi and about:support also confirms this:

media.ffmpeg.vaapi.enabled true

This variable doesn’t change how Firefox works, it just logs what it’s doing. Maybe there’s some clues there.

Aside from maybe a new Firefox profile being useful I don’t see anything obviously wrong here. It’s probably a Firefox bug somewhere.

Yes that is probably a problem. Can you try in a fresh Firefox profile and try the guide?

Sorry what do you mean fresh profile? Should i uninstall and reinstall firefox?

media.hardware-video-decoding.force-enabled is also true

Go to about:profiles and create a new Firefox profile. Then within that new profile (will be default settings for everything), follow this guide. The idea is to see what happens with default settings.

There is no need at all to reinstall Firefox, and you can remove the test profile later on easily.

For reference: https://support.mozilla.org/en-US/kb/profile-manager-create-remove-switch-firefox-profiles

Alright, created a profile and followed the guide but no luck.

Went to about:profiles > Create new profile > Entered name > Finish
Then for that new profile I clicked on Launch profile in new browser

ubuntu-restricted-extras is already installed as before.

Here are my changes to about:config
media.ffmpeg.vaapi.enabled : true (was false)
media.ffvpx.enabled : false (was true)
media.rdd-vpx.enabled: false (was true)
media.navigator.mediadatadecoder_vpx_enabled : true (was false)
gfx.webrender.all : true (was false)

about:support -

MOZ_LOG

$ MOZ_LOG="PlatformDecoderModule:5" firefox
[Child 13875: Main Thread]: D/PlatformDecoderModule PDMInitializer, Init PDMs in Content process
[Child 13875: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
[Child 13875: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
Gdk-Message: 18:36:01.668: Unable to load split_v from the cursor theme
[Child 13983: Main Thread]: D/PlatformDecoderModule PDMInitializer, Init PDMs in Content process
[Child 13983: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
[Child 13983: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
[Child 13983: Main Thread]: D/PlatformDecoderModule Agnostic decoder supports requested type

intel-gpu-top - 127/ 126 MHz; 77% RC6; 0.43 Watts; 158 irqs/s

  IMC reads:     2743 MiB/s
 IMC writes:     1089 MiB/s

      ENGINE      BUSY                                      MI_SEMA MI_WAIT
 Render/3D/0   18.10% |██████▎                            |      0%      0%
   Blitter/0    0.00% |                                   |      0%      0%
     Video/0    0.00% |                                   |      0%      0%

VideoEnhance/0 0.00% | | 0% 0%

1 Like

One last idea from browsing bugzilla, media.rdd-ffvpx.enabled to false (in addition to everything else). And/or maybe media.rdd-process.enabled to false again.

Nope.

$ MOZ_LOG="PlatformDecoderModule:5" firefox
[Child 3388: Main Thread]: D/PlatformDecoderModule PDMInitializer, Init PDMs in Content process
[Child 3388: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform
[Child 3388: Main Thread]: D/PlatformDecoderModule VA-API FFmpeg is disabled by platform

Filed 1735694

I should clarify that I can replicate the same issue on Firefox on Windows. I’ve only seen smooth hardware accelerated playback on Microsoft Edge. Haven’t tried Chrome on Windows yet on this system. On Ubuntu, nothing seems to work properly.

This always works for me:

  • Install VAAPI drivers.

  • Set the following flags:

media.ffmpeg.vaapi.enabled = true
media.rdd-process.enabled = false
media.av1.enabled = false

  • If you use Xorg

gfx.x11-egl.force-enabled = true

PD: VAAPI is broken on FF snap, .deb version works fine.

This is tracked by bug #1947115, and in the process of being fixed.

3 Likes

Thanks for your reply, I’ll keep an eye on it btw I’m already enjoying 21.10 on my main machine.

Sorry to slip a bit but on Intel Alder Lake , although vainfo shows AV1 support , I could not succeed to make Firefox decode it with GPU , did you try ?

Brilliant it worked for me first time! Previously I could not receive incoming videos in messenger, after the about: config changes it worked straight away. Thank you. I was going crazy trying to sort it.

@vchernin

https://www.phoronix.com/news/NVIDIA-VAAPI-Driver-0.0.8

Not sure if the above project is of any interest or use, i noticed it at phoronix yesterday.