• Raspberry Pi
    3 min | 6677

    #Raspberry Pi 4: Hardware accelerated video decoding (GPU) in Chromium

    Raspberry Pi | 3 min | 6677

    Two months ago, I wrote a tutorial that explains how to get DRM support on Chromium on the Raspberry Pi. If you follow the steps of that tutorial:

    you can use the Chromium web browser to play videos from Netflix, Hulu, HBO, Disney+, Amazon Prime, Spotify, Pandora, and many others (see Fig. 1 & 2).

    Supported Browser
    Fig. 1: Playing videos on Amazon Prime
    using Chromium on the Raspberry Pi OS.
    Supported Browser
    Fig. 2: Playing music on Spotify
    using Chromium on the Raspberry Pi OS.

    AnthonyD wrote in the comment section:

    That is a great solution to the DRM problem on Raspberry Pi! How is the video playback quality in Chromium? Do you know if it uses hardware acceleration or just the CPU?

    Last week I had some time to run some tests and extended the tutorial to add support for hardware acceleration for the video decoding.

    To answer that question, the video playback quality is good, however, per default Chromium uses Software (CPU) to decode the video. This means, no hardware acceleration.

    Graphics Feature Status - Software Acceleration
    Fig. 3: Graphics Feature Status - Chromium on Raspberry Pi 4.

    But, we will change that on this tutorial!

    Hardware and Software

    You will need the following hardware and software for this tutorial:

    DIY: Video Decode using Hardware Acceleration

    You need to install a few libraries, but first, the basic step is to update the system typing the following on a Terminal:

    sudo apt-get update
    sudo apt-get upgrade

    Then, install the libraries typing:

    sudo apt-get install libgles2-mesa libgles2-mesa-dev xorg-dev

    To be able to activate the hardware acceleration, first we need to enable the 3D video driver (so-called Fake KMS), and then set the memory to e.g. 128 MB (this is usually a default value). To do that:

    1. Start the raspi-config configurator, typing in a Terminal:
      sudo raspi-config
    2. Go to Advanced Options > GL Driver
    3. Select the option GL (Fake KMS) OpenGL desktop driver with fake KMS and Click OK
    4. Go to Advanced Options > Memory Split
    5. Type 128 and click OK
    6. Select Finish and Reboot the system.

    Note: if you're new to this configurator, you can navigate the menu using the arrows and the tab key from your keyboard.

    Once your Raspberry reboots, you can check that the 3D drivers are loaded and working:

    cat /proc/device-tree/soc/firmwarekms@7e600000/status
    cat /proc/device-tree/v3dbus/v3d@7ec04000/status

    If both commands return okay, then the hardware acceleration is working and activated.

    Enable hardware acceleration in Chromium

    If open a Chromium and go to chrome://gpu, you will still get Fig. 1. To change that, we need to go to chrome://flags and search for

    • Override software rendering list
    • GPU rasterization
    • Out of process rasterization

    and change those settings to Enabled (see Fig. 4). After restarting the web browser, you can refresh chrome://gpu and you will get Fig. 5.

    Chromium flags - hardware acceleration
    Fig. 4: Chromium flags - Setting flags to activate the Hardware Acceleration.
    Graphics Feature Status - Hardware Acceleration activated
    Fig. 5: Graphics Feature Status - Video Decode: Hardware accelerated.

    You can check if a video is decoded using hardware or software checking the chrome://media-internals/ URL while playing it. Fig. 6 shows the software decoder (before the changes). Fig. 7 indicates that the MmalVideoDecoder decoder is being used (after the changes). This is the Broadcom’s library for H.264 hardware acceleration on the Raspberry Pi.

    Video Decoder: DecryptingVideoDecoder
    Fig. 6: Media internals - Software Decoder
    Video Decoder: MmalVideoDecoder
    Fig. 7: Media internals - Hardware Decoder

    Reduce screen tearing (Update 20.08.2020)

    You will still get the occasional "screen tearing". You can find more information about this on the forum topic.

    The solution is to disable the xcompmgr composition manager. To do that, you can move/remove the xcompmgr.desktop file typing:

    sudo mv /etc/xdg/autostart/xcompmgr.desktop /home/pi/backup.xcompmgr.desktop
    sudo reboot

    or you can follow these steps:

    1. Start the raspi-config configurator, typing in a Terminal
      sudo raspi-config
    2. Navigate to Advanced Options > Compositor > xcompmgr composition manager
    3. Choose No
    4. Reboot the Raspberry Pi
      sudo reboot

    That should resolve most issues! I still noticed a bit of screen tearing.


    Fabien 08.13.2020

    Thank you for your article! I have try it and it works fine for user pi, but for a standard user with less privileges, chromium uses ffmpegVideoDecoder insted of MmalVideoDecoder. PErhaps, you have a solution?

    Len 08.14.2020

    Thanks for the tip. I now have Chromium using the hardware acceleration, but video is still quite choppy. Oh well...

    andre van den brink 08.14.2020

    Hi Thanks for your explanation to get hardware decoding working. I have a rpi 3B+. Should this also work? I followed your instruction but I see in the device-tree that the v3dbus folder is not there. Is there an other procedure for the rpi 3B+ ?

    Regards Andre van den Brink

    David 09.16.2020

    Working like a charm in a Raspberry 4 and a Raspberry 3 B+. Why the heck isn't it enabled by default? Thank you.