Firefox on Fedora finally gets VA-API on Wayland.

video1
I used of Toy Story 3 trailer as a test video and saw it a thousand times during the VA-API debugging. I should definitely watch the movie one day.

Yes, it’s finally here. One and half year after Tom Callaway, Engineering Manager @ Red Hat added the patch to Chromium we also get hardware accelerated video playback for Firefox. It’s shame it took too long but I’m still learning.

The VA-API support in Firefox is a bit specific as it works under Wayland only right now. There isn’t any technical reason for that, I just don’t have enough time to implement it for X11 so Bug 1619523 is waiting for brave hackers.

There are a lot of people who greatly contributed to the Firefox Wayland port. Jan Horak (Red Hat) did all the uneasy Wayland patches reviews I threw at him. Jonas Ådahl (Red Hat) helped me with Wayland backend since the first Wayland patch four years ago. Robert Mader faced various Mutter/Gtk compositor bugs, Kenny Levinsen implemented adaptive Wayland vsync handlers, Jan Andre Ikenmeyer has been tirelessly triaged new Wayland bugs and cleaning bugzilla. Sotaro Ikeda (Mozilla) reviewed almost all Wayland patches for graphics subsystem, Jean-Yves Avenard (Mozilla) reviewed VA-API video patches and Jeff Gilbert (Mozilla) faced to my OpenGL Wayland patches.

The contributor list is not exhaustive as I mentioned only the most active ones who comes to mind right now. There are a lot of people who contribute to Firefox/Wayland. You’re the best!

How to enable it in Fedora?

When you run Gnome Wayland session on Fedora you get Firefox with Wayland backend by default. Make sure you have the latest Firefox 77.0 for Fedora 32 / Fedora 31.

You also need working VA-API acceleration and ffmpeg (valib) packages. They are provided by RPM Fusion repository. Enable it and install ffmpeg, libva and libva-utils.

Intel graphics card

There are two drivers for Intel cards, libva-intel-driver (provides i965_drv_video.so) and libva-intel-hybrid-driver (iHD_drv_video.so). Firefox works with libva-intel-driver only, intel-media-driver is broken due to sandboxing issues (Bug 1619585). I strongly recommend to avoid it all cost and don’t disable media sandbox for it.

AMD graphics card

AMD open source drivers decode video with radeonsi_drv_video.so library which is provided by mesa-dri-drivers package and it comes with Fedora by default.

NVIDIA graphics cards

I have no idea how NVIDIA cards are supported because I don’t owny any. Please refer to Fedora VA-API page for details.

Test VA-API state

When you have the driver set it’s time to prove it. Run vainfo on terminal and check which media formats are decoded on the hardware.

vaapi1

There’s vainfo output from my laptop with integrated Intel UHD Graphics 630. Loads i965_drv_video.so driver and decodes H.264/VP8/VP9 video formats. I don’t expect much more from it – seems to be up.

Configure Firefox

It’s time to whip up the lazy fox 🙂 At about:config set gfx.webrender.enabled and widget.wayland-dmabuf-vaapi.enabled. Restart browser, go to about:support and make sure WebRender is enabled…

vaapi2

…and Window Protocol is Wayland/drm.

vaapi3

Right now you should be able to decode and play clips on your graphics cards only without any CPU interaction.

Get more info from Firefox log

VA-API video playback may not work from various reason. Incompatible video codec, large video size, missing system libraries and so on. All those errors can be diagnosed by Firefox media log. Run on terminal

MOZ_LOG="PlatformDecoderModule:5" MOZ_ENABLE_WAYLAND=1 firefox

and you should see something like

vaapi-log

VA-API FFmpeg init successful” claims the VA-API is up and running, VP9 is the video format and “Got one VAAPI frame output…” line confirms that frame decoding works.

VA-API and Youtube

Unfortunately Youtube tends to serve various video formats, from H.264 to AV1. Actual codec info is shown after right click on video under “Stats for nerds” option.

vaapi4
Surprisingly “avc1” means H.264 video. You can expect also AV1 and VP8/VP9 there.

Youtube video codec can be changed by enhanced-h264ify Firefox add-on, so disable all SW decoded formats there. And that’s it. If you’re running Fedora you should be settled for now.

video2
We’re done, bro!

VA-API with stock Mozilla binaries

Stock Mozilla Firefox 77.0 is missing some important stability/performance VA-API fixes which hit Firefox 78.0 and are backported to Fedora Firefox package. You should grab latest nightly binaries or Developer/Beta versions and run them under Wayland as

MOZ_ENABLE_WAYLAND=1 ./firefox

Mozilla binaries perform VP8/VP9 decoding by bundled libvpx library which is missing VA-API decode path. If your hardware supports it and you want to use VA-API for VP8/VP9 decoding, you need to disable bundled libvpx and force external ffmpeg. Go to about:config and set media.ffvpx.enabled to false. Fedora sets that by default when VA-API is enabled.

 

42 thoughts on “Firefox on Fedora finally gets VA-API on Wayland.

  1. Amazing news, thanks so much for working on this! I’ve been following the issue tracker on bugzilla, nice job 🙂

    I was wondering if it would be possible to enable this in Fedora out of the box? Am I correct that the reason why we need FFmpeg from RPM Fusion is to allow software fallback if VA-API doesn’t work, and Fedora can’t ship avdec_h264?

    Please correct me if I’m wrong, but can’t ffmpeg be built to use openh264 instead of avdec_h264, which combined with Firefox’s automatic openh264 downloading of Cisco binaries would mean we could use that as the fallback software implementation? Is that something that’s in the works? Or is there anything else that’s blocking Firefox from using VA-API through Fedora’s ffmpeg?

    Like

    1. We did the va-api playback via. ffmpeg (libavcodec.so) and also Intel needs libva-intel-driver, both from rpmfusion. If openh264 supports va-api it will still needs libva-intel-driver from rpmfusion.

      Like

  2. Well the chromium side got a setback when bugs started to appear. The vaapi is currently disabled and now broken(dmabuf).

    Anyways, Huge thank to you and everyone else involved for this achievement. The only issue remaining on Firefox is related to sandbox violations and hope it will get fixed too.

    Also thanks for enabling dmabuf for us poor radeon GPU card users which do not support DRM modifiers.

    Like

  3. Hi Martin,

    that’s awesome to hear and I hope to test it later. There’s one thing that is not correct in the article though – the iHD driver is provided by the intel-media-driver package, I’m not sure though what the libva-intel-hybrid-driver package is for…

    Like

    1. > libva-intel-hybrid-driver package is for…
      This (fedora) package allows VP8/9 hw decode for libva-intel-driver VA-API backend, as shown with vainfo with/out the package installed. The intel-media-driver (iHD) doesn’t rely on it and would provides VP8/9 support by itself.
      It’s unfortunate that the intel-media-driver that targets newer intel hw doesn’t work. Is there any bug reported upstream.
      Thanks for this work!

      Like

  4. Great work!

    Just wanted to note that there is a curly quotation mark in MOZ_LOG=”PlatformDecoderModule:5″ MOZ_ENABLE_WAYLAND=1 firefox which appears to make the logger not work properly.

    Like

  5. Will video acceleration also work without WebRender, i.e. on hardware which is too old to get supported by WebRender?

    Like

  6. Thanks a lot, Martin, that’s a big achievement and a lot of good work! I also just figured that `widget.wayland-dmabuf-webgl.enabled` is enabled by default now, so faster WebGL is already shipped – as long as WR is enabled. So lets go and get that one ready* 🙂

    * and fix all the lingering bugs of course

    Like

  7. Seems that something is not working on my laptop:

    libva info: VA-API version 1.7.0
    libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
    libva info: va_openDriver() returns -1
    libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
    libva info: Found init function __vaDriverInit_1_6
    libva info: va_openDriver() returns 0

    This is everything what I see here with:

    libva-2.7.1-1.fc33.x86_64
    libva-intel-driver-2.4.0-3.fc33.x86_64
    firefox-77.0-2.fc33.x86_64
    ffmpeg-4.3-0.22.20200531git.fc33.x86_64

    Liked by 1 person

  8. gfx.webrender.enabled requires layers.acceleration.force-enabled. gfx.webrender.all implies both, so it’s better to recommend it instead.

    Like

  9. I did everything and I have only :

    $ MOZ_LOG=”PlatformDecoderModule:5″ MOZ_ENABLE_WAYLAND=1 firefox
    libva info: VA-API version 1.7.0
    libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
    libva info: va_openDriver() returns -1
    libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
    libva info: Found init function __vaDriverInit_1_6
    failed to open /usr/lib64/dri/hybrid_drv_video.so
    Not using hybrid_drv_video.so
    libva info: va_openDriver() returns 0

    Like

  10. This is Awesome! I’ve tested it on my intel laptop: youtube, 1080p, vp9 and with va the cpu usage is noticably better: https://imgur.com/a/4HeP2XK. That work is shifted to gpu, but my very not scientific eyeballing in powertop showed that the overall power usage is very slightly lower too.

    Like

  11. This is fricking awesome, I’ve been waiting for a an excuse to switch to swaywm anyway!

    Just two quick questions, if i may:

    1. Will the about:config tweaks be required going into the future or is this just a hack to make it available now and future firefox versions will have these enabled by default?

    2. Why is MOZ_ENABLE_WAYLAND=1 necessary? Shouldn’t firefox start with a wayland backend anyway when started within a wayland wm?

    Thanks!

    Like

  12. The libva-intel-hybrid-driver driver adds VP9 support on my hardware (Intel HD 520), but I get a lot of dropped frames with it installed. Without it I get a lot less dropped frames. Apparently my CPU is better at decoding VP9 than my GPU. Just putting it out here, maybe it helps some people with older hardware. Based on the results I’ve disabled av1 and VP9 in enhanced-h264ify.

    Like

  13. Thank you for all your work on firefox wayland. Using firefox-nightly with a AMD 290x GPU I had to disable VP9 using the enhancen-h264ify addon but now I have va-api working on youtube. CPU usage went down and hardly any extra GPU usage according to radeontop.

    Like

  14. This is all crap. You need broken Mutter/GTK3 for something that should work 10 years ago. You cannot use KDE and x11 at all. You have to hack Firefox to work with bunch of environmental crap, bunch of about:configs and Fedora is missing intel-libva drivers, which are in unsupported external repo (why intel drivers are missing from Fedora repo? Why are they not installed by default? Why installer doesn’t see that there’s an Intel CPU/GPU inside the laptop? 90% laptops have Intel CPU and still Fedora doesn’t install intel drivers nor detects them and you cannot install them from Fedora repo, and you have to add external unreliable ppa. WTF.

    Then you have to mess up with two confusing libva-intel and itel-media and I thing all the posts above have it the other way round, since the newer is not intel-media, but libva-intel wich in Fedora is missing dependancy gmm library (graphics memory management). Another thing is that gstremer vaapi and intel-libva has a nasty bug and regression for some time now, which I couldn’t disect- much higher CPU usage while playing avc1/x.264 files. From 2 to 5 times higher CPU usage on never drivers and newer CPUs (Brodwel is max 5% CPU on Debian and Skylyke upwars is like 12-20% CPU on the same video file with newer drivers in Fedora and Arch). Plus there’s more because for older Intel GPUs there was –vo=vaapi and its deprecated now in favour of –vo=gpu but regardless the higher CPU is still present. Plus there might be some “surface” bug with newer f’ed intel drivers/ffmpeg/gst-vaapi combo.

    This is all one crappy bullshit. The only solution is to drag and drop the url (or extracted mp4) onto smplayer with mpv as backend. And as of youtube and VP9 Intel is bullshit. You have to download acv1 via youtube-dl and ffmpeg will aoutmatically glue h.264 video and m4a into mp4 container so you can play it with vaapi support (albeit broken with more CPU usage on anything past Debian….).

    10 years have passed and we are still behind Windows. One gigantic bullshit.

    Like

    1. You may try the view-tube-addon and/or the open-in-vlc-addon. Especially opening YT-vids in VLC helps because of its vaapi-support a lot; on my 10 year old compaq I can run 720p30frames with no problems, CPU running at just 30% (X11, Lubuntu).

      (I did not yet test how vaapi-support in FF78 (X11) is coming along…)

      Like

  15. Similarly to this experience [1], video hardware decoding is working for me with the intel iHD driver [3] for h264/vp8 and vp9 youtube videos. av01 is software decoded, but firefox doesn’t crash on av01 videos. Disabling av01 for youtube via enhanced-h264ify works fine to enforce hardware decoding for most YT videos.

    Logging output for a vp9 YT video (via MOZ_LOG=”PlatformDecoderModule:5″ ):
    A few ‘Sandbox decoder rejects requested type’ lines,
    A few ‘Sandbox decoder supports requested type’

    Upon video init:
    [AVHWDeviceContext @ 0x7ff1a992fa80] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics – 20.1.1 ().
    [AVHWDeviceContext @ 0x7ff1a992fa80] Driver not found in known nonstandard list, using standard behaviour.
    [Child 26848: MediaPDecoder #9]: D/PlatformDecoderModule VA-API FFmpeg init successful
    [Child 26848: MediaPDecoder #10]: D/PlatformDecoderModule Choosing FFmpeg pixel format for VA-API video decoding.
    [Child 26848: MediaPDecoder #10]: D/PlatformDecoderModule Requesting pixel format VAAPI_VLD
    [vp9 @ 0x7ff1aa8c3000] Format vaapi_vld chosen by get_format().
    [vp9 @ 0x7ff1aa8c3000] Format vaapi_vld requires hwaccel initialisation.
    [vp9 @ 0x7ff1aa8c3000] Considering format 0x3231564e -> nv12.
    [vp9 @ 0x7ff1aa8c3000] Picked nv12 (0x3231564e) as best match for yuv420p.

    Upon video playback:
    “[Child 26848: MediaPDecoder #1]: D/PlatformDecoderModule Got one VAAPI frame output with pts=0 dts=0 duration=42000 opaque=-9223372036854775808
    [Child 26848: MediaPDecoder #1]: D/PlatformDecoderModule Created dmabuf UID = 1 HW surface 11
    [Child 26848: MediaPDecoder #1]: D/PlatformDecoderModule VAAPIFrameHolder is adding dmabuf surface UID = 1
    [Child 26848: MediaPDecoder #1]: D/PlatformDecoderModule VAAPIFrameHolder is releasing dmabuf surface UID = 1”.

    So – at least for me – intel-media-driver seems to be able to accelerate the decoding of the most common video codecs with the exception of av01. Though I doubt whether the older driver supports that. This archwiki entry [2] section to imply not.

    [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1619585#c40
    [2] https://wiki.archlinux.org/index.php/Hardware_video_acceleration#VA-API_drivers
    [3] vainfo ouput:
    vainfo: VA-API version: 1.8 (libva 2.7.1)
    vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics – 20.1.1 ()
    vainfo: Supported profile and entrypoints
    VAProfileNone : VAEntrypointVideoProc
    VAProfileNone : VAEntrypointStats
    VAProfileMPEG2Simple : VAEntrypointVLD
    VAProfileMPEG2Simple : VAEntrypointEncSlice
    VAProfileMPEG2Main : VAEntrypointVLD
    VAProfileMPEG2Main : VAEntrypointEncSlice
    VAProfileH264Main : VAEntrypointVLD
    VAProfileH264Main : VAEntrypointEncSlice
    VAProfileH264Main : VAEntrypointFEI
    VAProfileH264Main : VAEntrypointEncSliceLP
    VAProfileH264High : VAEntrypointVLD
    VAProfileH264High : VAEntrypointEncSlice
    VAProfileH264High : VAEntrypointFEI
    VAProfileH264High : VAEntrypointEncSliceLP
    VAProfileVC1Simple : VAEntrypointVLD
    VAProfileVC1Main : VAEntrypointVLD
    VAProfileVC1Advanced : VAEntrypointVLD
    VAProfileJPEGBaseline : VAEntrypointVLD
    VAProfileJPEGBaseline : VAEntrypointEncPicture
    VAProfileH264ConstrainedBaseline: VAEntrypointVLD
    VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
    VAProfileH264ConstrainedBaseline: VAEntrypointFEI
    VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
    VAProfileVP8Version0_3 : VAEntrypointVLD
    VAProfileVP8Version0_3 : VAEntrypointEncSlice
    VAProfileHEVCMain : VAEntrypointVLD
    VAProfileHEVCMain : VAEntrypointEncSlice
    VAProfileHEVCMain : VAEntrypointFEI
    VAProfileHEVCMain10 : VAEntrypointVLD
    VAProfileHEVCMain10 : VAEntrypointEncSlice
    VAProfileVP9Profile0 : VAEntrypointVLD
    VAProfileVP9Profile2 : VAEntrypointVLD

    Like

  16. Hi,
    Since firefox 79 vaapi acceleration is not working correctly in wayland or x11. Video starts working, but with vaapi acceleration but in the middle i get a green screen and video fall to 360p. I get this with firefox 79, 80 and 81. In firefox 78 it worked flawless. My graphic card is a intel iHd

    my firefox config gfx.webrender.enabled, widget.wayland-dmabuf-vaapi.enabled and media.ffvpx.enabled set to falso so I can play vp9 in youtube

    Like

  17. In what version can we hope that firefox solves the problem without needed to be patch in a particular distribution?

    Like

      1. Hi Martin, tanks for your great work. The green issue seems to be fixed in nightly but video error and falls to poor quality (360p) in youtube still persists

        Like

  18. I can’t get vp9/vp8 acceleration to work inside flatpak. h264 in flatpak works, and h264 and vp9/vp8 work on the binary downloaded from mozilla.org, it’s just vp9/vp8 inside of flatpak that’s broken. is this a known issue?

    i’m using firefox 81 on debian testing on an intel i7-8650U / UHD 620 (kaby lake)

    Like

      1. that looks like a different issue, since i got vaapi partially working (i think i had to install a newer flatpak ffmpeg build?) but that bug can’t find vaapi at all.

        Like

  19. You mentioned that intel-media-driver is broken due to sandboxing issues. I have a Lenovo x1 Carbon gen 8 laptop with an Intel 10th gen processor Ice Lake. Hardware acceleration is supported by the intel-media-driver. Is the driver still broken? I enabled hw acceleration and it seems to work.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website at WordPress.com
Get started
%d bloggers like this: