Manage cookies

We use cookies to improve our services. Read more about how we use cookies and how you can refuse them.

The necessary cookies help to make the website work properly.

Anonymous statistical cookies help to understand how visitors use the website.

  • Raspberry Pi
    4 min | 189872

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

    Raspberry Pi | 4 min | 189872


    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!

    You may be also interested in this tutorial: Raspberry Pi 4: booting from an SSD with enabled TRIM

    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 Performance Options > GPU Memory (on old Raspbian/Raspberry Pi OS: 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
    
    # on Raspberry Pi 3 the v3dbus command should be (provided by Alexis in the comments):
    cat /proc/device-tree/soc/v3d@7ec00000/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
    • Hardware-accelerated video decode (only available on the new versions of Raspberry Pi OS)

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

    Chromium flags - hardware acceleration
    Fig. 4a: Chromium flags - Setting flags to activate the Hardware Acceleration (old Raspbian/Raspberry Pi OS).
    Chromium flags - hardware acceleration
    Fig. 4b: Chromium flags - Setting flags to activate the Hardware Acceleration (new Raspberry Pi OS).
    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.

    Possible Issue: Raspberry Pi HD Camera - ENOSPC error

    After activating the GPU acceleration in Chromium, I got the following error while trying to take a photo with the HD camera and playing some Youtube video.

    # raspistill -o /tmp/capture.jpg
    mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
    mmal: camera component couldn't be enabled
    mmal: main: Failed to create camera component
    mmal: Failed to run camera app. Please check for firmware updates

    Increasing the CPU memory from 128 to 144 made the error go away:

    sudo raspi-config
    
    # old Raspbian / Raspberry Pi OS:
    # 7 Advanced Options > A3 Memory Split
    
    # new Raspberry Pi OS:
    # 4 Performance Options > P2 GPU Memory
    Chromium flags - hardware acceleration
    Fig. 8: Extending the CPU Memory using raspi-config
    I described the issue as possible, because I tried to reproduce it and did not get the error again. However, I wrote it here, in case someone needs to deal with it.

    Comments

    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.15.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.

    sanjay 11.02.2020

    HELLO, I HAVE PI4, THE CHROMIUM BROWERS USES MMALDECODER WHEN PLAYING YOUTUBE. BUT AMAZON PRIME STILL USES SOFTWARE DECODER: DECRYINGVIDEOCODER SOMETHING WRONG? thanks sanjay

    cmoney 11.14.2020

    Interestingly, amazon prime video worked fine before all of those gpu settings. Now I can't undo any of those and I'm getting the error message that I need to update the WDLI module but I can't ever update it:(

    emwtur 12.15.2020

    Worked, i think - but I lost HDMI sound :-(

    brentil 12.29.2020

    Since this was published some of the items have changed.

    In Chrome 86 you have to also enable the flag "Hardware-accelerated video decode"

    Also in raspi-config there is no longer a Memory Split menu under Advanced. It's now under Performance Options -> P2 GPU Memory.

    I noticed a new option in Chrome 86 under GPU for using Vulkan, I might experiment turning it on later to test.

    Rick 02.26.2021

    Using RaspOS Deb 10.8, there are 2 browser versions, Chromium and Chromium-Browser. The file names and dependencies are different. I had already installed Chromium v88 before I discovered your tutorials. Your scripts fail as the directory names are /chromium not /chromium-browser. Is it possible that the Chromium version already has DRM support?

    Mostafa 05.23.2021

    Thank you for your amazing notes.

    Are you able to stream h264 from your raspberry pi camera? I used v4l2-ctl -d /dev/video0 -v pixelformat=H264 -V to set the camera encoding to h264 and it returns back to MJPG as soon as I open a web application that uses the camera such as Jitsi Web Meet

    TJJaz 07.26.2021

    On the Raspberry Pi 4B I had problems with videos not playing and graphics on Chrome pages loading all "chopped up". I followed the steps on this page up to the "cat /proc/device-tree/v3dbus/v3d@7ec04000/status" line - got "okay" responses to each. When I opened Chromium, the window was all chopped up and unusable. I made things worse than before!

    Al Forster 09.04.2021

    Sept 3, 2021- After making your changes, in YouTubeTV I still get "Sorry, there was an error licensing this video". Chrome works fine running YouTubeTV on a Mac running Catalina, but Running Twister OS on a 8gb Raspberry Pi4b I get that error. Any suggestions?

    Lawrie 10.27.2021

    I followed the steps but I can't enable out of process rasterization or hardware acceleration as they're both in the un available tab in experiments. I'm using pi 4, raspbian 10, everything up to date and the commands to check the hardware acceleration return "okay"

    MIke 12.02.2021

    Hello everybody

    under Debian Buster, AARCH64, Pi 400, Chromium doesn't seem to have the "chrome://flags/#enable-accelerated-video-decode" flag anymore. The howto mentioned above doesn't work anaymore, I just get the "FFMPEGVIdeoDecoder" not the MojoVideoDecoder anymore.

    What am I doing wrong?

    KRis 12.12.2021

    Im running the "2021-10-30:Based on Debian version 11 (bullseye)" Raspberry Pi OS, and i experience the same as Mike, that the "chrome://flags/#enable-accelerated-video-decode" is not available. It's filed in chrome://flags as "Unavailable" and also states "Not available on your platform". I'm running Raspberry Pi 4 4GB.