Kay Thomas Development

Navigation

How to use hardware acceleration with Flatpak Firefox

December 9, 2020

SEPTEMBER 2022 EDIT: I updated this guide a little bit because a couple of things changed. Basically, you don't need the `MOZ_X11_EGL=1` environment variable anymore, and you also want to install v21.08 of org.freedesktop.Platform.ffmpeg-full now instead of 19.08. As Firefox updates the ffmpeg runtime version they use, you will need to update the Flatpak accordingly.

This is how I was able to get hardware acceleration working on Flatpak Firefox (version 83.0 at the time of writing this). Note that I am using an AMD GPU for this, though I believe it should work with other brands as well. This guide is for the Xorg display server.

  1. Follow the instructions on the Arch wiki here on how to verify if your GPU supports hardware acceleration and which codecs it supports
  2. Install the org.freedesktop.Platform.ffmpeg-full flatpak: flatpak install org.freedesktop.Platform.ffmpeg-full. Choose branch 21.08 when prompted
    • (Some people report they also had to install org.freedesktop.Platform.VAAPI.Intel. Maybe that's only for Intel integrated GPUs?)
  3. Set the following environment variables in order to enable hardware acceleration and logging so that you can verify it's working later: flatpak override --env="MOZ_LOG=PlatformDecoderModule:5" org.mozilla.firefox
  4. In Firefox, type about:config in the URL bar and set the following settings:
    gfx.webrender.all=true
    media.ffmpeg.vaapi.enabled=true
    media.ffvpx.enabled=false (maybe not required anymore?)
    media.av1.enabled=false (maybe not required anymore?)
  5. In Firefox, type about:support in the URL bar, go the "Graphics" table, and confirm that "Composting" is set to "WebRender."
  6. To allow hardware decoding on YouTube, the video codec used must be supported by the hardware. By default, YouTube streams VP8/VP9 encoded video, and since my GPU doesn't support decoding of that codec, I use the h264ify extension to force H.264 videos on YouTube. I recommend installing this extension if you are in the same position.
  7. Verify that hardware acceleration is working by running the Firefox Flatpak from the terminal with verbose logging: flatpak run --verbose org.mozilla.firefox. Then, open a YouTube video. Right as the video starts playing, look for logs indicating that it's working. As an example, I will show the relevant lines of output from the logs that I see, indicating that it's working:
    [Child 389: MediaPDecoder #2]: D/PlatformDecoderModule Initialising VA-API FFmpeg decoder
    [RDD 437: MediaPDecoder #1]: D/PlatformDecoderModule FFMPEG: Initialising VA-API FFmpeg decoder
    [RDD 437: MediaPDecoder #1]: D/PlatformDecoderModule FFMPEG:   codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
    libva info: VA-API version 1.12.0
    ...
    RDD 437: MediaPDecoder #1]: D/PlatformDecoderModule FFMPEG:   VA-API FFmpeg init successful
    ...
    [RDD 437: MediaPDecoder #1]: D/PlatformDecoderModule FFMPEG: VA-API Got one frame output with pts=1933333 dts=1933334 duration=33333 opaque=-9223372036854775808
I will try and update this post if this stops working and/or if steps need to be updated. Hope it helps!