Raspberry Pi 4 - gpu acceleration for chromium-browser

Hi there,

I’ve been trying to get chromium-browser to run with GPU acceleration on a Raspberry Pi 4 using this as the base repo: https://github.com/balena-io-playground/x11-window-manager

My start.sh looks like this:

#!/bin/bash

# Remove the X server lock file so ours starts cleanly
rm /tmp/.X0-lock &>/dev/null || true

# Set the display to use
export DISPLAY=:0

# Set the DBUS address for sending around system messages
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

# start desktop manager
echo "STARTING X"
sleep 2
startx &
sleep 20

# Hide the cursor
unclutter -display :0 -idle 0.1 &

# Start Flask
python3 -u app/main.py &

sleep 10

# Launch chromium browser in fullscreen on that page
SCREEN_SCALE="${SCREEN_SCALE:-default 1.0}"
chromium-browser --app=http://localhost:8080 --start-fullscreen --no-sandbox --user-data-dir --kiosk --force-device-scale-factor=$SCREEN_SCALE --no-user-gesture-required

# For debugging
echo "Chromium browser exited unexpectedly."
free -h
echo "End of pi.sh ..."

and my Dockerfile.raspberrypi4-64 looks like this:

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/raspberrypi3:buster

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.
RUN install_packages \
  g++ python3-pip python3-setuptools python3-dev build-essential \
  chromium-browser \
  rpi-chromium-mods \
  lsb-release xserver-xorg \
  xinit lxsession desktop-file-utils \
  raspberrypi-ui-mods rpd-icons \
  gtk2-engines-clearlookspix \
  matchbox-keyboard \
  unclutter \
  # Support for Accuview gTouch 21.5" touchscreen
  xserver-xorg-input-evdev \
  xinput

# disable lxpolkit popup warning
RUN mv /usr/bin/lxpolkit /usr/bin/lxpolkit.bak

# Set wallpaper
COPY /conf/desktop-items-0.conf /root/.config/pcmanfm/LXDE-pi/

# Autohide panel
COPY /conf/panel /root/.config/lxpanel/LXDE-pi/panels/

# Hide panel completely
COPY /conf/autostart /etc/xdg/lxsession/LXDE-pi/
COPY /conf/autostart /root/.config/lxsession/LXDE-pi/

# Disable screen from turning it off
RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
  && echo "" >> /etc/X11/xinit/xserverrc \
  && echo 'exec /usr/bin/X -s 0 dpms -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV 1

COPY ./requirements.txt /code/requirements.txt
RUN pip3 install -Ur /code/requirements.txt

COPY . /code/
WORKDIR /code/

# pi4.sh will run when container starts up on the device
CMD ["bash","scripts/pi4.sh"]

I’ve set RESIN_HOST_CONFIG_gpu_mem to 396

Any hints?

Cheers, Simon.

Hi @sighmon. What are the issues you re facing? Did you try out the base repo as is? Gradually building up changes on top of that repo, could help you identify the issue here.

@mikesimos I’m trying to play a 1080p video in an html5 video tag, but it doesn’t play smoothly and the CPU is pegged, so seems that the GPU isn’t being used for video decoding at all.

Video spec: 1080p, h264, 30fps.

Hi @sighmon I don’t think anyone has tried this yet, but I believe one needs to pass specific flags to chromium to use the gpu on some arm devices. What I would suggest trying is passing the flags listed in https://lb.raspberrypi.org/forums/viewtopic.php?t=199543 to see if that enables the gpu.