BalenaOS 2.73.1+rev1 for RPI4: how to make bcm2835-codec working?

Hi,
my goal is to enable HEVC decoding on a RPI4 running Balena OS.
I previously was able to make a patched FFMPEG work on the same RPI4 board with an Ubuntu 20.04 server for RPI4 distribution, following the instructions here: https://github.com/jc-kynesim/rpi-ffmpeg/tree/dev/4.3.1%2Fdrm_prime_1.

With Balena OS
Now looking at dmesg (both with the prebuilt image and with the self made image) I notice the vc_sm_cma_vchi_init error and no /dev/videoX devices initialized:

[ 15.638816] rpivid-mem feb00000.hevc-decoder: rpivid-hevcmem initialised: Registers at 0xfeb00000 length 0x00010000
[ 15.686483] rpivid-mem feb10000.rpivid-local-intc: rpivid-intcmem initialised: Registers at 0xfeb10000 length 0x00001000
[ 15.738116] mc: Linux media interface: v0.10
[ 15.739213] rpivid-mem feb20000.h264-decoder: rpivid-h264mem initialised: Registers at 0xfeb20000 length 0x00010000
[ 15.781821] rpivid-mem feb30000.vp9-decoder: rpivid-vp9mem initialised: Registers at 0xfeb30000 length 0x00010000
[ 15.810891] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned.
[ 15.844259] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 15.864135] [vc_sm_connected_init]: start
[ 15.883729] vc_sm_cma_vchi_init: failed to open VCHI service (-1)
[ 15.883739] [vc_sm_connected_init]: failed to initialize shared memory service

On Ubuntu 20.04 server instead:

8.776970] rpivid-mem feb00000.hevc-decoder: rpivid-hevcmem initialised: Registers at 0xfeb00000 length 0x00010000

[ 8.777171] rpivid-mem feb10000.rpivid-local-intc: rpivid-intcmem initialised: Registers at 0xfeb10000 length 0x00001000
[ 8.777339] rpivid-mem feb20000.h264-decoder: rpivid-h264mem initialised: Registers at 0xfeb20000 length 0x00010000
[ 8.777501] rpivid-mem feb30000.vp9-decoder: rpivid-vp9mem initialised: Registers at 0xfeb30000 length 0x00010000
[ 8.824418] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned.
[ 8.825008] vc_sm_cma: module verification failed: signature and/or required key missing - tainting kernel
[ 8.826000] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 8.826009] [vc_sm_connected_init]: start
[ 8.829893] [vc_sm_connected_init]: installed successfully

[ 9.086728] bcm2835-codec bcm2835-codec: Device registered as /dev/video10
[ 9.086755] bcm2835-codec bcm2835-codec: Loaded V4L2 decode
[ 9.091218] bcm2835-codec bcm2835-codec: Device registered as /dev/video11
[ 9.091250] bcm2835-codec bcm2835-codec: Loaded V4L2 encode
[ 9.100934] bcm2835-codec bcm2835-codec: Device registered as /dev/video12
[ 9.100979] bcm2835-codec bcm2835-codec: Loaded V4L2 isp

I wonder what I need to flag on before the custom image build to enable the /dev/videoX devices.
If only I had that then I would modify the config.txt and enable the /dev/video19 which is used for HEVC decode.

Hi there, a few questions to better understand your problem. Are you exposing the device (/dev/videoX) to the container? If you are using a multicontainer setup or a docker-compose.yml file it won’t be exposed by default. Typically you can expose all devices by adding the privileged: true flag to your container. Have you tried with this? You can read a bit more on this here: Interact with hardware - Balena Documentation

Are the dmesg logs you shared from a container or from the hostOS?

Thank you for the reply Tomas.
The dmesg is from hostOS, the devices are not visible to the host.

Hey @fguerzoni, I’ve seen this error when the GPU mem is too low.
Note that in balenaOS the default GPU mem is 16M but to perform GPU actions you can increase that to 64M by setting the device config variable BALENA_HOST_CONFIG_gpu_mem.

I hope this helps!

2 Likes

I tried and it works!
Many many thanks

Fixed it for me as well.

@klutchell Would you expect any performance benefit from assigning even more RAM to the GPU for encoding applications?

Hi @rapha, increasing the GPU memory may be necessary for higher resolution videos (up to 320M for 4K videos) but adding more GPU memory than necessary will have no effect on encoding/decoding performance.

Hello all…

Something I am trying to realize from the Advanced boot settings configuration but it is not clear to me:

BALENA_HOST_CONFIG_gpu_mem

and other configs are just effective on Raspberry Pi?
What about intel NUC? does it takes effect?

Thanks in advance,

Nuno