Kevin Thomas Development

Navigation

How to use hardware acceleration with Flatpak Firefox

December 9, 2020

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 19.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_X11_EGL=1 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
    media.av1.enabled=false
    media.ffmpeg.dmabuf-textures.enabled=true
  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
    libva info: VA-API version 1.5.0
    libva info: va_getDriverName() returns 0
    libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so
    libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/intel-vaapi-driver/radeonsi_drv_video.so
    libva info: Trying to open /usr/lib/x86_64-linux-gnu/GL/lib/dri/radeonsi_drv_video.so
    libva info: Found init function __vaDriverInit_1_5
    libva info: va_openDriver() returns 0
    [AVHWDeviceContext @ 0x7f4efb9fad00] VAAPI driver: Mesa Gallium driver 20.1.2 for Radeon RX Vega (VEGA10,
    DRM 3.39.0, 5.9.12-xanmod1, LLVM 9.0.1).
    [Child 389: MediaPDecoder #2]: D/PlatformDecoderModule VA-API FFmpeg init successful
    [Child 389: MediaPDecoder #3]: D/PlatformDecoderModule Choosing FFmpeg pixel format for VA-API video decoding.
I will try and update this post if this stops working and/or if steps need to be updated. Hope it helps!